- 8
- 0
я хотел сделать барьер который отталкивает ентити, но как бы я не старался ентити проджектайлы не хотят отталкиватся
почему этот код не работает на ентити проджектайлы, на обычных энтити работает
Java:
@Override
public void update() {
int radius = 7; // Радиус круга
Minecraft mc = Minecraft.getMinecraft();
double centerX = pos.getX() + 0.5;
double centerY = pos.getY() + 0.5;
double centerZ = pos.getZ() + 0.5;
AxisAlignedBB area = new AxisAlignedBB(
centerX - radius, centerY - radius, centerZ - radius,
centerX + radius, centerY + radius, centerZ + radius
);
List<Entity> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, area);
for (Entity entity : entities) {
if(entity instanceof EntityArrow ||
entity instanceof EntityEgg ||
entity instanceof EntityFireball ||
entity instanceof EntitySnowball ||
entity instanceof EntityPotion ){
double motionX = entity.posX - centerX;
double motionY = entity.posY - centerY;
double motionZ = entity.posZ - centerZ;
double distance = Math.sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ);
motionX /= distance;
motionY /= distance;
motionZ /= distance;
double knockbackStrength = 1.0;
entity.addVelocity(motionX * knockbackStrength, motionY * knockbackStrength, motionZ * knockbackStrength);
entity.velocityChanged = true;
}
Последнее редактирование: