diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java new file mode 100644 index 00000000..2a2295b6 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAnimalContainer.java @@ -0,0 +1,35 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.api.render.IVisualizable; +import de.ellpeck.naturesaura.blocks.tiles.TileEntityAnimalContainer; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +public class BlockAnimalContainer extends BlockContainerImpl implements IVisualizable { + public BlockAnimalContainer() { + super("animal_container", TileEntityAnimalContainer::new, ModBlocks.prop(Material.WOOD).hardnessAndResistance(2)); + } + + @Override + @OnlyIn(Dist.CLIENT) + public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { + TileEntity tile = world.getTileEntity(pos); + if (tile instanceof TileEntityAnimalContainer) { + int radius = ((TileEntityAnimalContainer) tile).getRadius(); + if (radius > 0) + return new AxisAlignedBB(pos).grow(radius); + } + return null; + } + + @Override + @OnlyIn(Dist.CLIENT) + public int getVisualizationColor(World world, BlockPos pos) { + return 0x42ddf5; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index 7ad8de38..b0e00d28 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -59,6 +59,7 @@ public final class ModBlocks { public static Block DIMENSION_RAIL_END; public static Block BLAST_FURNACE_BOOSTER; public static Block NETHER_WART_MUSHROOM; + public static Block ANIMAL_CONTAINER; public static Block.Properties prop(Material material, MaterialColor color) { return Block.Properties.create(material, color); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java index 35ad6e2e..339dae3b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java @@ -1,8 +1,6 @@ package de.ellpeck.naturesaura.blocks.tiles; -import de.ellpeck.naturesaura.NaturesAura; import net.minecraft.tileentity.TileEntityType; -import net.minecraftforge.registries.ObjectHolder; @SuppressWarnings("FieldNamingConvention") public final class ModTileEntities { @@ -35,4 +33,5 @@ public final class ModTileEntities { public static TileEntityType TIME_CHANGER; public static TileEntityType WOOD_STAND; public static TileEntityType BLAST_FURNACE_BOOSTER; + public static TileEntityType ANIMAL_CONTAINER; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAnimalContainer.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAnimalContainer.java new file mode 100644 index 00000000..28568ff2 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAnimalContainer.java @@ -0,0 +1,45 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import net.minecraft.entity.passive.AnimalEntity; +import net.minecraft.tileentity.ITickableTileEntity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.Vec3d; + +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() { + if (this.world.isRemote || this.world.getGameTime() % 2 != 0) + return; + + int radius = this.getRadius(); + Set animalsInRange = new HashSet<>(this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius - 1))); + List animalsOutRange = this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius)); + for (AnimalEntity animal : animalsOutRange) { + if (animalsInRange.contains(animal)) + continue; + Vec3d pos = animal.getPositionVec(); + Vec3d distance = pos.subtract(this.pos.getX(), pos.getY(), this.pos.getZ()); + distance = distance.normalize().scale(-0.15F); + animal.setMotion(distance); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 02bd099c..f32de1c0 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -107,7 +107,8 @@ public final class ModRegistry { new BlockDimensionRail("nether", DimensionType.THE_NETHER, DimensionType.OVERWORLD), new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD), new BlockBlastFurnaceBooster(), - new BlockImpl("nether_wart_mushroom", ModBlocks.prop(Blocks.RED_MUSHROOM_BLOCK)) + new BlockImpl("nether_wart_mushroom", ModBlocks.prop(Blocks.RED_MUSHROOM_BLOCK)), + new BlockAnimalContainer() ); if (ModConfig.instance.rfConverter.get())