Posted June 30, 201510 yr So I have created a custom iron door that is different in that it's indestructible. However, I also want it to only open from behind which essentially means the door will only open if it is receiving redstone power from behind the door (anything in front will be ignored). I believe I understand how this would be done (using the onNeighbourBlockChange() method), but I don't understand how to get the position of the door from within that method to find where the neighbour block is relative to the door. For all I know it could be in the first part of the code already and I'm just not seeing it. Either way, I need some help with this. Here is my custom door code: BlockChaosDoorUnbreakable.java package com.samuel.chaosblock; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockDoor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockChaosDoorUnbreakable extends BlockDoor { public static final String name = "unbreakable_chaos_door"; public BlockChaosDoorUnbreakable(String unlocalizedName, Material material, float hardness, float resistance) { super(material); this.setUnlocalizedName(unlocalizedName); this.setHardness(hardness); this.setResistance(resistance); } public BlockChaosDoorUnbreakable(String unlocalizedName, float hardness, float resistance) { this(unlocalizedName, Material.iron, hardness, resistance); } public BlockChaosDoorUnbreakable(String unlocalizedName) { this(unlocalizedName, -1.0f, 18000000.0f); } @Override @SideOnly(Side.CLIENT) public Item getItem(World worldIn, BlockPos pos) { return ChaosBlock.itemChaosDoorUnbreakable; } @Override public Item getItemDropped(IBlockState state, Random rand, int fortune) { return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : this.getItem(); } private Item getItem() { return ChaosBlock.itemChaosDoorUnbreakable; } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { return false; //Allow items to interact with the door } /** * Called when a neighboring block changes. */ @Override public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { int combinedMeta = combineMetadata(worldIn, pos); EnumFacing enumfacing = getFacing(combinedMeta); if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER) { BlockPos blockpos1 = pos.down(); IBlockState iblockstate1 = worldIn.getBlockState(blockpos1); if (iblockstate1.getBlock() != this) { worldIn.setBlockToAir(pos); } else if (neighborBlock != this) { this.onNeighborBlockChange(worldIn, blockpos1, iblockstate1, neighborBlock); } } else { boolean flag1 = false; BlockPos blockpos2 = pos.up(); IBlockState iblockstate2 = worldIn.getBlockState(blockpos2); if (iblockstate2.getBlock() != this) { worldIn.setBlockToAir(pos); flag1 = true; } if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down())) { worldIn.setBlockToAir(pos); flag1 = true; if (iblockstate2.getBlock() == this) { worldIn.setBlockToAir(blockpos2); } } if (flag1) { if (!worldIn.isRemote) { this.dropBlockAsItem(worldIn, pos, state, 0); } } else { boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos2); if ((flag || neighborBlock.canProvidePower()) && neighborBlock != this && flag != ((Boolean)iblockstate2.getValue(POWERED)).booleanValue()) { /*Where I want to set a boolean indicating whether the power source is behind the door or not and cancel the following code if the power source is not behind*/ worldIn.setBlockState(blockpos2, iblockstate2.withProperty(POWERED, Boolean.valueOf(flag)), 2); if (flag != ((Boolean)state.getValue(OPEN)).booleanValue()) { worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2); worldIn.markBlockRangeForRenderUpdate(pos, pos); worldIn.playAuxSFXAtEntity((EntityPlayer)null, flag ? 1003 : 1006, pos, 0); } } } } } public String getName() { return name; } }
July 1, 201510 yr First you need to know which way your door is facing - BlockDoor has a property for this that you can get by accessing your block's state. Once you know the door's facing, you can use BlockPos#offset(facing.getOpposite()) to get the block behind the door and check if that is the one giving it power. Keep in mind that the state storing the door's facing is in the block comprising the lower half of the door. http://i.imgur.com/NdrFdld.png[/img]
July 1, 201510 yr Author To do that, I believe I need the door's BlockPos. How do I get the door's BlockPos from within the onNeighbourBlockChange method?
July 1, 201510 yr To do that, I believe I need the door's BlockPos. How do I get the door's BlockPos from within the onNeighbourBlockChange method? The BlockPos given in the method parameter is the position of the current block, not the neighbor. I suggest you take a look at the BlockDoor code and see how they handle it. http://i.imgur.com/NdrFdld.png[/img]
July 1, 201510 yr Author Yeah... I just found that out before reading your post. If I knew that I could have figured this out easily. Maybe now I'll learn not to assume things like that.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.