diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java index 46921941..a75f0433 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimDoorBase.java @@ -163,9 +163,10 @@ public abstract class BlockDimDoorBase extends BlockDoor implements IDimDoor, IT world.setBlockToAir(pos2); } else { ((DDTileEntityBase) world.getTileEntity(pos)).writeToNBT(origRiftTag); + } super.breakBlock(world, pos, state); - ModBlocks.blockRift.tryPlacingRift(world, pos2); //@todo, this seems to not happen? + world.setBlockState(pos2, ModBlocks.blockRift.getDefaultState()); DDTileEntityBase newRift = (DDTileEntityBase) world.getTileEntity(pos2); newRift.readFromNBT(origRiftTag); } diff --git a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimWall.java b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimWall.java index fade95fc..a9f06060 100644 --- a/src/main/java/com/zixiken/dimdoors/blocks/BlockDimWall.java +++ b/src/main/java/com/zixiken/dimdoors/blocks/BlockDimWall.java @@ -8,6 +8,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; @@ -19,6 +20,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.IStringSerializable; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.world.Explosion; @@ -33,7 +35,7 @@ import javax.annotation.Nullable; public class BlockDimWall extends Block { public static final String ID = "blockDimWall"; - public static final PropertyInteger TYPE = PropertyInteger.create("type", 0, 2); + public static final PropertyEnum<BlockDimWall.EnumType> TYPE = PropertyEnum.<BlockDimWall.EnumType>create("type", BlockDimWall.EnumType.class); private static final float SUPER_HIGH_HARDNESS = 10000000000000F; private static final float SUPER_EXPLOSION_RESISTANCE = 18000000F; @@ -45,30 +47,22 @@ public class BlockDimWall extends Block { setHardness(0.1F); setUnlocalizedName(ID); setRegistryName(ID); - setDefaultState(blockState.getBaseState().withProperty(TYPE, 0)); + setDefaultState(blockState.getBaseState().withProperty(TYPE, EnumType.FABRIC)); setSoundType(SoundType.STONE); } @Override public IBlockState getStateFromMeta(int meta) { if (meta >= 0 && meta <= 2) { - return getDefaultState().withProperty(TYPE, meta); + return getDefaultState().withProperty(TYPE, EnumType.values()[meta]); } else { return getDefaultState(); } } - @Override - public boolean isReplaceable(IBlockAccess world, BlockPos pos) { - if (world.getBlockState(pos).getValue(TYPE) == 1) { - return false; - } - return true; - } - @Override public int getMetaFromState(IBlockState state) { - return state.getValue(TYPE); + return state.getValue(TYPE).ordinal(); } @Override @@ -78,7 +72,7 @@ public class BlockDimWall extends Block { @Override public float getBlockHardness(IBlockState state, World world, BlockPos pos) { - if (state.getValue(TYPE) != 1) { + if (!state.getValue(TYPE).equals(EnumType.ANCIENT)) { return this.blockHardness; } else { return SUPER_HIGH_HARDNESS; @@ -87,7 +81,7 @@ public class BlockDimWall extends Block { @Override public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { - if (world.getBlockState(pos).getValue(TYPE) != 1) { + if (!world.getBlockState(pos).getValue(TYPE).equals(EnumType.ANCIENT)) { return super.getExplosionResistance(world, pos, exploder, explosion); } else { return SUPER_EXPLOSION_RESISTANCE; @@ -96,7 +90,7 @@ public class BlockDimWall extends Block { @Override public int damageDropped(IBlockState state) { - int metadata = state.getValue(TYPE); + int metadata = state.getValue(TYPE).ordinal(); //Return 0 to avoid dropping Ancient Fabric even if the player somehow manages to break it return metadata == 1 ? 0 : metadata; } @@ -123,4 +117,53 @@ public class BlockDimWall extends Block { public int quantityDropped(Random par1Random) { return 0; } -} + + /** + * replaces the block clicked with the held block, instead of placing the + * block on top of it. Shift click to disable. + */ + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { + //Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric + if (heldItem != null && !state.getValue(TYPE).equals(EnumType.ANCIENT)) { + Block block = Block.getBlockFromItem(heldItem.getItem()); + if (!state.isNormalCube() || block.hasTileEntity(block.getDefaultState()) + || block == this //this also keeps it from being replaced by Ancient Fabric + || player.isSneaking()) { + return false; + } + if (!world.isRemote) { //@todo on a server, returning false or true determines where the block gets placed? + if (!player.capabilities.isCreativeMode) { + heldItem.stackSize--; + } + world.setBlockState(pos, block.getStateForPlacement(world, pos, side, hitX, hitY, hitZ, 0, player, heldItem)); //choosing getStateForPlacement over getDefaultState, because it will cause directional blocks, like logs to rotate correctly + heldItem.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ); + } + return true; + } + return false; + } + + public static enum EnumType implements IStringSerializable { + FABRIC("fabric"), + ANCIENT("ancient"), + ALTERED("altered"); + + private final String name; + + private EnumType(String name) + { + this.name = name; + } + + public String toString() + { + return this.name; + } + + public String getName() + { + return this.name; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java b/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java index 3ad9566f..8a08811e 100644 --- a/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java +++ b/src/main/java/com/zixiken/dimdoors/client/DDProxyClient.java @@ -2,6 +2,7 @@ package com.zixiken.dimdoors.client; import com.zixiken.dimdoors.DDProxyCommon; import com.zixiken.dimdoors.tileentities.TileEntityDimDoor; +import com.zixiken.dimdoors.tileentities.TileEntityRift; import com.zixiken.dimdoors.tileentities.TileEntityTransTrapdoor; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; @@ -10,6 +11,7 @@ import net.minecraft.world.World; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +@SuppressWarnings({"MethodCallSideOnly", "NewExpressionSideOnly"}) public class DDProxyClient extends DDProxyCommon { @Override @@ -21,6 +23,7 @@ public class DDProxyClient extends DDProxyCommon { public void registerRenderers() { ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDimDoor.class, new RenderDimDoor()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTransTrapdoor.class, new RenderTransTrapdoor()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRift.class, new RenderRift()); } @Override diff --git a/src/main/java/com/zixiken/dimdoors/client/RenderDimDoor.java b/src/main/java/com/zixiken/dimdoors/client/RenderDimDoor.java index 90ae9bc1..9525c0b2 100644 --- a/src/main/java/com/zixiken/dimdoors/client/RenderDimDoor.java +++ b/src/main/java/com/zixiken/dimdoors/client/RenderDimDoor.java @@ -24,7 +24,6 @@ import net.minecraft.util.ResourceLocation; import static org.lwjgl.opengl.GL11.*; -@SideOnly(Side.CLIENT) public class RenderDimDoor extends TileEntitySpecialRenderer<TileEntityDimDoor> { private FloatBuffer buffer = GLAllocation.createDirectFloatBuffer(16); diff --git a/src/main/java/com/zixiken/dimdoors/client/RenderRift.java b/src/main/java/com/zixiken/dimdoors/client/RenderRift.java new file mode 100644 index 00000000..575c1bf1 --- /dev/null +++ b/src/main/java/com/zixiken/dimdoors/client/RenderRift.java @@ -0,0 +1,18 @@ +package com.zixiken.dimdoors.client; + +import com.zixiken.dimdoors.tileentities.TileEntityRift; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; + +public class RenderRift extends TileEntitySpecialRenderer<TileEntityRift> { + + public void renderTileEntityAt(TileEntityRift te, double x, double y, double z, float partialTicks, int destroyStage) { + ITextComponent itextcomponent = new TextComponentString("Derp"); + + this.setLightmapDisabled(true); + this.drawNameplate(te, itextcomponent.getFormattedText(), x, y, z, 12); + this.setLightmapDisabled(false); + } +} diff --git a/src/main/resources/assets/dimdoors/blockstates/blockDimWall.json b/src/main/resources/assets/dimdoors/blockstates/blockDimWall.json index d445fa63..df490653 100644 --- a/src/main/resources/assets/dimdoors/blockstates/blockDimWall.json +++ b/src/main/resources/assets/dimdoors/blockstates/blockDimWall.json @@ -1,7 +1,7 @@ { "variants": { - "type=0": { "model": "dimdoors:blockDimWall" }, - "type=1": { "model": "dimdoors:blockDimWallAncient" }, - "type=2": { "model": "dimdoors:blockDimWallAltered" } + "type=fabric": { "model": "dimdoors:blockDimWall" }, + "type=ancient": { "model": "dimdoors:blockDimWallAncient" }, + "type=altered": { "model": "dimdoors:blockDimWallAltered" } } } \ No newline at end of file