diff --git a/src/main/java/epicsquid/roots/block/runes/BlockTrample.java b/src/main/java/epicsquid/roots/block/runes/BlockTrample.java index 5581cc165..a5d53453f 100644 --- a/src/main/java/epicsquid/roots/block/runes/BlockTrample.java +++ b/src/main/java/epicsquid/roots/block/runes/BlockTrample.java @@ -1,17 +1,11 @@ package epicsquid.roots.block.runes; -import epicsquid.mysticallib.block.BlockBase; -import epicsquid.mysticallib.block.CustomStateMapper; -import net.minecraft.block.BlockLiquid; +import epicsquid.mysticallib.block.BlockTEBase; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.state.BlockStateContainer; -import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; -import net.minecraft.client.renderer.block.statemap.StateMap; import net.minecraft.item.Item; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; +import net.minecraft.tileentity.TileEntity; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -19,40 +13,18 @@ import javax.annotation.Nonnull; @SuppressWarnings("deprecation") -public class BlockTrample extends BlockBase { +public class BlockTrample extends BlockTEBase { public static int SAFE_RANGE_X = 30; public static int SAFE_RANGE_Y = 5; public static int SAFE_RANGE_Z = 30; - public BlockTrample(@Nonnull Material mat, @Nonnull SoundType type, float hardness, @Nonnull String name) { - super(mat, type, hardness, name); - setDefaultState(this.getDefaultState().withProperty(BlockLiquid.LEVEL, 15)); - } - - @Override - protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, BlockLiquid.LEVEL); - } - - @Override - public IBlockState getStateFromMeta(int meta) { - return this.getDefaultState().withProperty(BlockLiquid.LEVEL, meta); - } - - @Override - public int getMetaFromState(IBlockState state) { - return state.getValue(BlockLiquid.LEVEL); - } - - @Override - public boolean isReplaceable(IBlockAccess worldIn, BlockPos pos) { - return false; + public BlockTrample(@Nonnull Material mat, @Nonnull SoundType type, float hardness, @Nonnull String name, @Nonnull Class teClass) { + super(mat, type, hardness, name, teClass); } @Override @SideOnly(Side.CLIENT) public void initModel() { - ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(BlockLiquid.LEVEL).build()); ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "handlers")); } } diff --git a/src/main/java/epicsquid/roots/init/ModBlocks.java b/src/main/java/epicsquid/roots/init/ModBlocks.java index 627cebe71..cd07b3138 100644 --- a/src/main/java/epicsquid/roots/init/ModBlocks.java +++ b/src/main/java/epicsquid/roots/init/ModBlocks.java @@ -98,7 +98,7 @@ public static void registerBlocks(@Nonnull RegisterContentEvent event) { event.addBlock(runestone_brick = new BlockBase(Material.ROCK, SoundType.METAL, 1.4f, "runestone_brick")).setCreativeTab(Roots.tab); event.addBlock(runestone_brick_alt = new BlockBase(Material.ROCK, SoundType.METAL, 1.4f, "runestone_brick_alt")).setCreativeTab(Roots.tab); event.addBlock(chiseled_runestone = new BlockBase(Material.ROCK, SoundType.METAL, 1.4f, "chiseled_runestone")).setCreativeTab(Roots.tab); - event.addBlock(trample_rune = new BlockTrample(Material.WATER, SoundType.METAL, 1.4f, "runestone_trample")).setCreativeTab(Roots.tab); + event.addBlock(trample_rune = new BlockTrample(Material.ROCK, SoundType.METAL, 1.4f, "runestone_trample", TileEntityTrample.class)).setCreativeTab(Roots.tab); runestoneBlocks = Arrays.asList(runestone, runestone_brick, runestone_brick_alt, chiseled_runestone); diff --git a/src/main/java/epicsquid/roots/tileentity/TileEntityTrample.java b/src/main/java/epicsquid/roots/tileentity/TileEntityTrample.java new file mode 100644 index 000000000..4ff1b3eb1 --- /dev/null +++ b/src/main/java/epicsquid/roots/tileentity/TileEntityTrample.java @@ -0,0 +1,53 @@ +package epicsquid.roots.tileentity; + +import epicsquid.mysticallib.tile.TileBase; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.FarmlandWaterManager; +import net.minecraftforge.common.ticket.AABBTicket; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class TileEntityTrample extends TileBase { + public static AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(-4, -1, -4, 4, 1, 4); + + private AABBTicket ticket = null; + + public TileEntityTrample() { + } + + @Override + public void breakBlock(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nullable EntityPlayer player) { + super.breakBlock(world, pos, state, player); + + onChunkUnload(); + } + + @Override + public void onLoad() { + super.onLoad(); + + if (world != null && !world.isRemote) { + if (ticket != null) { + ticket.validate(); + } else { + ticket = FarmlandWaterManager.addAABBTicket(world, BOUNDING_BOX.offset(getPos())); + } + } + } + + @Override + public void onChunkUnload() { + super.onChunkUnload(); + + if (world != null && !world.isRemote) { + if (ticket != null) { + ticket.invalidate(); + } + } + } +}