Skip to content

Commit

Permalink
Resolve #334: no more material water hacks for the trample stone!
Browse files Browse the repository at this point in the history
  • Loading branch information
noobanidus committed Dec 22, 2019
1 parent d8f64d5 commit 6b1d0f0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
38 changes: 5 additions & 33 deletions src/main/java/epicsquid/roots/block/runes/BlockTrample.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,30 @@
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;

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<? extends TileEntity> 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"));
}
}
2 changes: 1 addition & 1 deletion src/main/java/epicsquid/roots/init/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
53 changes: 53 additions & 0 deletions src/main/java/epicsquid/roots/tileentity/TileEntityTrample.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
}

0 comments on commit 6b1d0f0

Please sign in to comment.