mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-26 08:19:24 +01:00
animal container, part 1
This commit is contained in:
parent
e240aade3a
commit
75fb931c5f
5 changed files with 84 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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<TileEntityTimeChanger> TIME_CHANGER;
|
||||
public static TileEntityType<TileEntityWoodStand> WOOD_STAND;
|
||||
public static TileEntityType<TileEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER;
|
||||
public static TileEntityType<TileEntityAnimalContainer> ANIMAL_CONTAINER;
|
||||
}
|
||||
|
|
|
@ -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<AnimalEntity> animalsInRange = new HashSet<>(this.world.getEntitiesWithinAABB(AnimalEntity.class, new AxisAlignedBB(this.pos).grow(radius - 1)));
|
||||
List<AnimalEntity> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue