2020-02-02 18:00:52 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks.tiles;
|
|
|
|
|
2020-02-02 19:43:40 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2020-02-02 18:00:52 +01:00
|
|
|
import net.minecraft.entity.passive.AnimalEntity;
|
|
|
|
import net.minecraft.tileentity.ITickableTileEntity;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2020-09-22 03:17:02 +02:00
|
|
|
import net.minecraft.util.math.vector.Vector3d;
|
2020-02-02 18:00:52 +01:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class TileEntityAnimalContainer extends TileEntityImpl implements ITickableTileEntity {
|
|
|
|
|
|
|
|
public TileEntityAnimalContainer() {
|
|
|
|
super(ModTileEntities.ANIMAL_CONTAINER);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRadius() {
|
|
|
|
return this.redstonePower / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRedstonePowerChange(int newPower) {
|
|
|
|
super.onRedstonePowerChange(newPower);
|
|
|
|
this.sendToClients();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tick() {
|
2021-03-21 17:41:14 +01:00
|
|
|
if (this.world.isRemote)
|
2020-02-02 18:00:52 +01:00
|
|
|
return;
|
|
|
|
int radius = this.getRadius();
|
|
|
|
Set<AnimalEntity> animalsInRange = new HashSet<>(this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius - 1)));
|
2021-03-21 17:41:14 +01:00
|
|
|
List<AnimalEntity> animalsOutRange = this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius + 1));
|
2020-02-02 18:00:52 +01:00
|
|
|
for (AnimalEntity animal : animalsOutRange) {
|
|
|
|
if (animalsInRange.contains(animal))
|
|
|
|
continue;
|
2020-09-22 03:17:02 +02:00
|
|
|
Vector3d pos = animal.getPositionVec();
|
|
|
|
Vector3d distance = pos.subtract(this.pos.getX(), pos.getY(), this.pos.getZ());
|
2020-02-02 18:00:52 +01:00
|
|
|
distance = distance.normalize().scale(-0.15F);
|
|
|
|
animal.setMotion(distance);
|
2020-02-02 19:43:40 +01:00
|
|
|
|
|
|
|
if (this.world.rand.nextBoolean()) {
|
2020-09-22 03:17:02 +02:00
|
|
|
Vector3d eye = animal.getEyePosition(1).add(animal.getLookVec());
|
2020-02-02 19:43:40 +01:00
|
|
|
PacketHandler.sendToAllAround(this.world, this.pos, 32,
|
|
|
|
new PacketParticles((float) eye.getX(), (float) eye.getY(), (float) eye.getZ(), PacketParticles.Type.ANIMAL_CONTAINER));
|
|
|
|
}
|
2020-02-02 18:00:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|