diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-10-23 05:50:53 +0100 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2018-10-23 05:50:53 +0100 |
commit | 53408770c7a4dd6fa4c997d4601b7aba215bc9ab (patch) | |
tree | dc484060a98ae7664aa9c9065537c1a235b54aa6 /src/Java | |
parent | 3dcd9e39f138315c903650c69f9a1a9782226cc4 (diff) | |
download | GT5-Unofficial-53408770c7a4dd6fa4c997d4601b7aba215bc9ab.tar.gz GT5-Unofficial-53408770c7a4dd6fa4c997d4601b7aba215bc9ab.tar.bz2 GT5-Unofficial-53408770c7a4dd6fa4c997d4601b7aba215bc9ab.zip |
$ Finished Work on custom auto-doors, now they just require recipes.
Diffstat (limited to 'src/Java')
5 files changed, 657 insertions, 75 deletions
diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index 5bff9dd744..081ae3d347 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -116,7 +116,7 @@ public final class ModBlocks { blockPlayerDoorIron = new PlayerDoors(Material.iron, "door_iron", true); blockPlayerDoorCustom_Glass = new PlayerDoors(Material.glass, "door_glass", false); blockPlayerDoorCustom_Ice = new PlayerDoors(Material.ice, "door_ice", false); - blockPlayerDoorCustom_Cactus = new PlayerDoors(Material.cactus, "door_cactus", false); + blockPlayerDoorCustom_Cactus = new PlayerDoors(Material.cactus, "door_cactus", false, 0.6f, Block.soundTypeGrass, "Cactus"); } diff --git a/src/Java/gtPlusPlus/core/block/general/PlayerDoors.java b/src/Java/gtPlusPlus/core/block/general/PlayerDoors.java index ce28520862..a4c0c1a0a5 100644 --- a/src/Java/gtPlusPlus/core/block/general/PlayerDoors.java +++ b/src/Java/gtPlusPlus/core/block/general/PlayerDoors.java @@ -1,116 +1,467 @@ package gtPlusPlus.core.block.general; -import java.util.ArrayList; +import java.util.HashMap; import java.util.Random; import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.item.base.itemblock.ItemBlockDoor; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.tileentities.general.TileEntityPlayerDoorBase; import gtPlusPlus.core.util.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockDoor; +import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.IconFlipped; +import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -public class PlayerDoors extends BlockDoor { +public class PlayerDoors extends BlockDoor implements ITileEntityProvider { - private boolean mHasDrops = true; + @SideOnly(Side.CLIENT) + private IIcon[] aTextureUpper; + @SideOnly(Side.CLIENT) + private IIcon[] aTextureLower; + + private final static HashMap<Material, BlockDoor> mDoorMap = new HashMap<Material, BlockDoor>(); public PlayerDoors(Material aMaterial, String aTextureName, boolean vanillaType) { - this (aMaterial, aTextureName, vanillaType, 0f, null, null); + this(aMaterial, aTextureName, vanillaType, 0f, null, null); } - - public PlayerDoors(Material aMaterial, String aTextureName, boolean vanillaType, float aHardness, SoundType aStepSound, String aBlockExtensionName) { + + public PlayerDoors(Material aMaterial, String aTextureName, boolean vanillaType, float aHardness, + SoundType aStepSound, String aBlockExtensionName) { super(aMaterial); this.disableStats(); - this.setBlockName("playerDoor_"+aTextureName); + this.isBlockContainer = true; + if (mDoorMap.get(aMaterial) == null) { + mDoorMap.put(aMaterial, this); + } + float f = 0.5F; + float f1 = 1.0F; + this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f); + + this.setBlockName("playerDoor_" + aTextureName); if (aMaterial == Material.wood) { setHardness(3.0F); setStepSound(soundTypeWood); - setBlockName("playerDoor"+"Wood"); + setBlockName("playerDoor" + "Wood"); this.setHarvestLevel("axe", 1); - } - else if (aMaterial == Material.iron) { + } else if (aMaterial == Material.iron) { setHardness(5.0F); setStepSound(Block.soundTypeMetal); - setBlockName("playerDoor"+"Iron"); + setBlockName("playerDoor" + "Iron"); this.setHarvestLevel("pickaxe", 1); - - } - else if (aMaterial == Material.glass) { + + } else if (aMaterial == Material.glass) { setHardness(0.1F); setStepSound(Block.soundTypeGlass); - setBlockName("playerDoor"+"Glass"); + setBlockName("playerDoor" + "Glass"); this.setHarvestLevel("pickaxe", 1); - mHasDrops = false; - - } - else if (aMaterial == Material.ice) { + + } else if (aMaterial == Material.ice) { setHardness(0.5F); setStepSound(Block.soundTypeSnow); - setBlockName("playerDoor"+"Ice"); + setBlockName("playerDoor" + "Ice"); this.setHarvestLevel("pickaxe", 1); - mHasDrops = false; - - } - else { + } else { setHardness(aHardness); setStepSound(aStepSound); - setBlockName("playerDoor"+aBlockExtensionName); + setBlockName("playerDoor" + aBlockExtensionName); this.setHarvestLevel("axe", 1); - - } - this.setBlockTextureName(vanillaType ? aTextureName : CORE.MODID+":"+aTextureName); - GameRegistry.registerBlock(this, Utils.sanitizeString(this.getUnlocalizedName())); + + } + this.setBlockTextureName(vanillaType ? aTextureName : CORE.MODID + ":" + aTextureName); + GameRegistry.registerBlock(this, ItemBlockDoor.class, Utils.sanitizeString(this.getUnlocalizedName())); } - @Override - public TileEntity createTileEntity(World world, int metadata) { - return new TileEntityPlayerDoorBase(this, metadata); + /** + * Gets the block's texture. Args: side, meta + */ + @SideOnly(Side.CLIENT) + public IIcon getIcon(int p_149691_1_, int p_149691_2_) { + return this.aTextureLower[0]; } - @Override - public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) { - // TODO Auto-generated method stub - return super.getItemDropped(p_149650_1_, p_149650_2_, p_149650_3_); + @SideOnly(Side.CLIENT) + public IIcon getIcon(IBlockAccess aAccess, int p_149673_2_, int p_149673_3_, int p_149673_4_, int p_149673_5_) { + if (p_149673_5_ != 1 && p_149673_5_ != 0) { + int i1 = this.getState(aAccess, p_149673_2_, p_149673_3_, p_149673_4_); + int j1 = i1 & 3; + boolean flag = (i1 & 4) != 0; + boolean flag1 = false; + boolean flag2 = (i1 & 8) != 0; + + if (flag) { + if (j1 == 0 && p_149673_5_ == 2) { + flag1 = !flag1; + } else if (j1 == 1 && p_149673_5_ == 5) { + flag1 = !flag1; + } else if (j1 == 2 && p_149673_5_ == 3) { + flag1 = !flag1; + } else if (j1 == 3 && p_149673_5_ == 4) { + flag1 = !flag1; + } + } else { + if (j1 == 0 && p_149673_5_ == 5) { + flag1 = !flag1; + } else if (j1 == 1 && p_149673_5_ == 3) { + flag1 = !flag1; + } else if (j1 == 2 && p_149673_5_ == 4) { + flag1 = !flag1; + } else if (j1 == 3 && p_149673_5_ == 2) { + flag1 = !flag1; + } + + if ((i1 & 16) != 0) { + flag1 = !flag1; + } + } + + return flag2 ? this.aTextureUpper[flag1 ? 1 : 0] : this.aTextureLower[flag1 ? 1 : 0]; + } else { + return this.aTextureLower[0]; + } } - @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister p_149651_1_) { + this.aTextureUpper = new IIcon[2]; + this.aTextureLower = new IIcon[2]; + this.aTextureUpper[0] = p_149651_1_.registerIcon(this.getTextureName() + "_upper"); + this.aTextureLower[0] = p_149651_1_.registerIcon(this.getTextureName() + "_lower"); + this.aTextureUpper[1] = new IconFlipped(this.aTextureUpper[0], true, false); + this.aTextureLower[1] = new IconFlipped(this.aTextureLower[0], true, false); + } + + public boolean getBlocksMovement(IBlockAccess aAccess, int aX, int aY, int aZ) { + int l = this.getState(aAccess, aX, aY, aZ); + return (l & 4) != 0; + } + + /** + * If this block doesn't render as an ordinary block it will return False + * (examples: signs, buttons, stairs, etc) + */ + public boolean renderAsNormalBlock() { + return false; + } + + /** + * The type of render function that is called for this block + */ + public int getRenderType() { + return 7; + } + + /** + * Returns the bounding box of the wired rectangular prism to render. + */ + @SideOnly(Side.CLIENT) + public AxisAlignedBB getSelectedBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { + this.setBlockBoundsBasedOnState(aWorld, aX, aY, aZ); + return super.getSelectedBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + + /** + * Returns a bounding box from the pool of bounding boxes (this means this box + * can change after the pool has been cleared to be reused) + */ + public AxisAlignedBB getCollisionBoundingBoxFromPool(World aWorld, int aX, int aY, int aZ) { + this.setBlockBoundsBasedOnState(aWorld, aX, aY, aZ); + return super.getCollisionBoundingBoxFromPool(aWorld, aX, aY, aZ); + } + + /** + * Updates the blocks bounds based on its current state. Args: world, x, y, z + */ + public void setBlockBoundsBasedOnState(IBlockAccess aAccess, int aX, int aY, int aZ) { + this.setBounds(this.getState(aAccess, aX, aY, aZ)); + } + + public int func_150013_e(IBlockAccess p_150013_1_, int p_150013_2_, int p_150013_3_, int p_150013_4_) { + return this.getState(p_150013_1_, p_150013_2_, p_150013_3_, p_150013_4_) & 3; + } + + public boolean func_150015_f(IBlockAccess p_150015_1_, int p_150015_2_, int p_150015_3_, int p_150015_4_) { + return (this.getState(p_150015_1_, p_150015_2_, p_150015_3_, p_150015_4_) & 4) != 0; + } + + private void setBounds(int aState) { + float f = 0.1875F; + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); + int j = aState & 3; + boolean flag = (aState & 4) != 0; + boolean flag1 = (aState & 16) != 0; + + if (j == 0) { + if (flag) { + if (!flag1) { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); + } else { + this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); + } + } else { + this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); + } + } else if (j == 1) { + if (flag) { + if (!flag1) { + this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } else { + this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); + } + } else { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); + } + } else if (j == 2) { + if (flag) { + if (!flag1) { + this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); + } else { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f); + } + } else { + this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + } else if (j == 3) { + if (flag) { + if (!flag1) { + this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F); + } else { + this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + } else { + this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F); + } + } + } + + /** + * Called upon block activation (right click on the block.) + */ + public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int p_149727_6_, + float p_149727_7_, float p_149727_8_, float p_149727_9_) { + if (this.blockMaterial == Material.iron) { + return false; // Allow items to interact with the door + } else { + int i1 = this.getState(aWorld, aX, aY, aZ); + int j1 = i1 & 7; + j1 ^= 4; + + if ((i1 & 8) == 0) { + aWorld.setBlockMetadataWithNotify(aX, aY, aZ, j1, 2); + aWorld.markBlockRangeForRenderUpdate(aX, aY, aZ, aX, aY, aZ); + } else { + aWorld.setBlockMetadataWithNotify(aX, aY - 1, aZ, j1, 2); + aWorld.markBlockRangeForRenderUpdate(aX, aY - 1, aZ, aX, aY, aZ); + } + + aWorld.playAuxSFXAtEntity(aPlayer, 1003, aX, aY, aZ, 0); + return true; + } + } + + public void func_150014_a(World aWorld, int aX, int aY, int aZ, boolean aFlag) { + int l = this.getState(aWorld, aX, aY, aZ); + boolean flag1 = (l & 4) != 0; + + if (flag1 != aFlag) { + int i1 = l & 7; + i1 ^= 4; + + if ((l & 8) == 0) { + aWorld.setBlockMetadataWithNotify(aX, aY, aZ, i1, 2); + aWorld.markBlockRangeForRenderUpdate(aX, aY, aZ, aX, aY, aZ); + } else { + aWorld.setBlockMetadataWithNotify(aX, aY - 1, aZ, i1, 2); + aWorld.markBlockRangeForRenderUpdate(aX, aY - 1, aZ, aX, aY, aZ); + } + + aWorld.playAuxSFXAtEntity((EntityPlayer) null, 1003, aX, aY, aZ, 0); + } + } + + /** + * Lets the block know when one of its neighbor changes. Doesn't know which + * neighbor changed (coordinates passed are their own) Args: x, y, z, neighbor + * Block + */ + public void onNeighborBlockChange(World aWorld, int aX, int aY, int aZ, Block aNeighbour) { + int l = aWorld.getBlockMetadata(aX, aY, aZ); + + if ((l & 8) == 0) { + boolean flag = false; + + if (aWorld.getBlock(aX, aY + 1, aZ) != this) { + aWorld.setBlockToAir(aX, aY, aZ); + flag = true; + } + + if (!World.doesBlockHaveSolidTopSurface(aWorld, aX, aY - 1, aZ)) { + aWorld.setBlockToAir(aX, aY, aZ); + flag = true; + + if (aWorld.getBlock(aX, aY + 1, aZ) == this) { + aWorld.setBlockToAir(aX, aY + 1, aZ); + } + } + + if (flag) { + if (!aWorld.isRemote) { + this.dropBlockAsItem(aWorld, aX, aY, aZ, l, 0); + } + } else { + boolean flag1 = aWorld.isBlockIndirectlyGettingPowered(aX, aY, aZ) + || aWorld.isBlockIndirectlyGettingPowered(aX, aY + 1, aZ); + + if ((flag1 || aNeighbour.canProvidePower()) && aNeighbour != this) { + this.func_150014_a(aWorld, aX, aY, aZ, flag1); + } + } + } else { + if (aWorld.getBlock(aX, aY - 1, aZ) != this) { + aWorld.setBlockToAir(aX, aY, aZ); + } + + if (aNeighbour != this) { + this.onNeighborBlockChange(aWorld, aX, aY - 1, aZ, aNeighbour); + } + } + } + + public Item getItemDropped(int p_149650_1_, Random aRand, int p_149650_3_) { + if ((p_149650_1_ & 8) != 0) { + return null; + } else { + Block b = mDoorMap.get(this.blockMaterial); + if (b != null) { + return Item.getItemFromBlock(b); + } + } + return null; + } + + /** + * Ray traces through the blocks collision from start vector to end vector + * returning a ray trace hit. Args: world, x, y, z, startVec, endVec + */ + public MovingObjectPosition collisionRayTrace(World p_149731_1_, int p_149731_2_, int p_149731_3_, int p_149731_4_, + Vec3 p_149731_5_, Vec3 p_149731_6_) { + this.setBlockBoundsBasedOnState(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_); + return super.collisionRayTrace(p_149731_1_, p_149731_2_, p_149731_3_, p_149731_4_, p_149731_5_, p_149731_6_); + } + + /** + * Checks to see if its valid to put this block at the specified coordinates. + * Args: world, x, y, z + */ + public boolean canPlaceBlockAt(World aWorld, int aX, int aY, int aZ) { + boolean aHeight = (aY < aWorld.getHeight() - 1); + boolean aSolidTopSurface = World.doesBlockHaveSolidTopSurface(aWorld, aX, aY - 1, aZ); + + boolean aCanPlace = aWorld.getBlock(aX, aY, aZ).isReplaceable(aWorld, aX, aY, aZ); + boolean aCanPlace2 = aWorld.getBlock(aX, aY, aZ).isReplaceable(aWorld, aX, aY + 1, aZ); + + // Logger.INFO(""+aY+"/"+aWorld.getHeight()+" | Trying to place door. Good + // height? "+aHeight+" | Solid top surface? "+aSolidTopSurface+" | Can Place? + // "+aCanPlace+"|"+aCanPlace2); + + return aHeight && aSolidTopSurface && aCanPlace && aCanPlace2; + } + + /** + * Returns the mobility information of the block, 0 = free, 1 = can't push but + * can move over, 2 = total immobility and stop pistons + */ + public int getMobilityFlag() { + return 1; + } + + public int getState(IBlockAccess aAccess, int aX, int aY, int aZ) { + int l = aAccess.getBlockMetadata(aX, aY, aZ); + boolean flag = (l & 8) != 0; + int i1; + int j1; + + if (flag) { + i1 = aAccess.getBlockMetadata(aX, aY - 1, aZ); + j1 = l; + } else { + i1 = l; + j1 = aAccess.getBlockMetadata(aX, aY + 1, aZ); + } + + boolean flag1 = (j1 & 1) != 0; + return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0); + } + + /** + * Gets an item for the block being called on. Args: world, x, y, z + */ + @SideOnly(Side.CLIENT) public Item getItem(World p_149694_1_, int p_149694_2_, int p_149694_3_, int p_149694_4_) { - // TODO Auto-generated method stub - return super.getItem(p_149694_1_, p_149694_2_, p_149694_3_, p_149694_4_); + Block b = mDoorMap.get(this.blockMaterial); + if (b != null) { + return Item.getItemFromBlock(b); + } + // return this.blockMaterial == Material.iron ? Items.iron_door : + // Items.wooden_door; + return null; } - @Override + /** + * Called when the block is attempted to be harvested + */ public void onBlockHarvested(World p_149681_1_, int p_149681_2_, int p_149681_3_, int p_149681_4_, int p_149681_5_, EntityPlayer p_149681_6_) { - // TODO Auto-generated method stub - super.onBlockHarvested(p_149681_1_, p_149681_2_, p_149681_3_, p_149681_4_, p_149681_5_, p_149681_6_); + if (p_149681_6_.capabilities.isCreativeMode && (p_149681_5_ & 8) != 0 + && p_149681_1_.getBlock(p_149681_2_, p_149681_3_ - 1, p_149681_4_) == this) { + p_149681_1_.setBlockToAir(p_149681_2_, p_149681_3_ - 1, p_149681_4_); + } + } + + /** + * Called whenever the block is added into the world. Args: world, x, y, z + */ + @Override + public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_) { + super.onBlockAdded(p_149726_1_, p_149726_2_, p_149726_3_, p_149726_4_); } @Override public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) { - // TODO Auto-generated method stub super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_); + p_149749_1_.removeTileEntity(p_149749_2_, p_149749_3_, p_149749_4_); } @Override - protected void dropBlockAsItem(World p_149642_1_, int p_149642_2_, int p_149642_3_, int p_149642_4_, - ItemStack p_149642_5_) { - // TODO Auto-generated method stub - super.dropBlockAsItem(p_149642_1_, p_149642_2_, p_149642_3_, p_149642_4_, p_149642_5_); + public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_, + int p_149696_5_, int p_149696_6_) { + super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_); + TileEntity tileentity = p_149696_1_.getTileEntity(p_149696_2_, p_149696_3_, p_149696_4_); + return tileentity != null ? tileentity.receiveClientEvent(p_149696_5_, p_149696_6_) : false; } @Override - public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { - return mHasDrops ? super.getDrops(world, x, y, z, metadata, fortune) : new ArrayList<ItemStack>(); + public TileEntity createNewTileEntity(World world, int metadata) { + return new TileEntityPlayerDoorBase(this, metadata); } - - + @Override + public TileEntity createTileEntity(World world, int metadata) { + return new TileEntityPlayerDoorBase(this, metadata); + } } diff --git a/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockDoor.java b/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockDoor.java new file mode 100644 index 0000000000..a41a44c113 --- /dev/null +++ b/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockDoor.java @@ -0,0 +1,92 @@ +package gtPlusPlus.core.item.base.itemblock; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; + +public class ItemBlockDoor extends ItemBlock { + @SideOnly(Side.CLIENT) + private IIcon field_150938_b; + + public ItemBlockDoor(Block p_i45328_1_) { + super(p_i45328_1_); + } + + /** + * Callback for item usage. If the item does something special on right + * clicking, he will have one of those. Return True if something happen and + * false if it don't. This is for ITEMS, not BLOCKS + */ + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, + int par5, int par6, int par7, float par8, float par9, float par10) { + if (par7 != 1) { + return false; + } else { + ++par5; + Block block; + + block = field_150939_a; + + if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) + && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)) { + if (!block.canPlaceBlockAt(par3World, par4, par5, par6)) { + return false; + } else { + int i1 = MathHelper.floor_double( + (double) ((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + byte b0 = 0; + byte b1 = 0; + + if (i1 == 0) { + b1 = 1; + } + + if (i1 == 1) { + b0 = -1; + } + + if (i1 == 2) { + b1 = -1; + } + + if (i1 == 3) { + b0 = 1; + } + + int i2 = (par3World.getBlock(par4 - b0, par5, par6 - b1).isNormalCube() ? 1 : 0) + + (par3World.getBlock(par4 - b0, par5 + 1, par6 - b1).isNormalCube() ? 1 : 0); + int j1 = (par3World.getBlock(par4 + b0, par5, par6 + b1).isNormalCube() ? 1 : 0) + + (par3World.getBlock(par4 + b0, par5 + 1, par6 + b1).isNormalCube() ? 1 : 0); + boolean flag = par3World.getBlock(par4 - b0, par5, par6 - b1) == block + || par3World.getBlock(par4 - b0, par5 + 1, par6 - b1) == block; + boolean flag1 = par3World.getBlock(par4 + b0, par5, par6 + b1) == block + || par3World.getBlock(par4 + b0, par5 + 1, par6 + b1) == block; + boolean flag2 = false; + + if (flag && !flag1) { + flag2 = true; + } else if (j1 > i2) { + flag2 = true; + } + + par3World.setBlock(par4, par5, par6, block, i1, 2); + par3World.setBlock(par4, par5 + 1, par6, block, 8 | (flag2 ? 1 : 0), 2); + par3World.notifyBlocksOfNeighborChange(par4, par5, par6, block); + par3World.notifyBlocksOfNeighborChange(par4, par5 + 1, par6, block); + + --par1ItemStack.stackSize; + return true; + } + } else { + return false; + } + } + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java index e31cb48561..b9f5727ed7 100644 --- a/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java +++ b/src/Java/gtPlusPlus/core/tileentities/ModTileEntities.java @@ -24,6 +24,7 @@ public class ModTileEntities { GameRegistry.registerTileEntity(TileEntityXpConverter.class, "TileEntityXpConverter"); GameRegistry.registerTileEntity(TileEntityGenericSpawner.class, "TileEntityGenericSpawner"); GameRegistry.registerTileEntity(TileEntityCircuitProgrammer.class, "TileCircuitProgrammer"); + GameRegistry.registerTileEntity(TileEntityPlayerDoorBase.class, "TilePlayerDoorBase"); //Mod TEs diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java index 513435212d..7df4bd45f3 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityPlayerDoorBase.java @@ -1,7 +1,8 @@ package gtPlusPlus.core.tileentities.general; -import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.api.objects.minecraft.BlockPos; import net.minecraft.block.Block; +import net.minecraft.block.BlockDoor; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -9,16 +10,16 @@ import net.minecraft.world.World; public class TileEntityPlayerDoorBase extends TileEntity { - private boolean mIsOpen = false; + public boolean mIsOpen = false; private short mMeta = 0; private long mTickCounter = 0; private final Block mBlockType; - - public TileEntityPlayerDoorBase(Block aBlock, int meta){ - mMeta = (short) meta; + private BlockPos mNeighbourDoor; + + public TileEntityPlayerDoorBase(Block aBlock, int meta) { mBlockType = aBlock; } - + @Override public void readFromNBT(NBTTagCompound aNBT) { super.readFromNBT(aNBT); @@ -31,22 +32,150 @@ public class TileEntityPlayerDoorBase extends TileEntity { aNBT.setBoolean("mIsOpen", mIsOpen); } + public int getNeighbourState() { + + if (mNeighbourDoor != null) { + World aWorld = this.worldObj; + if (aWorld != null) { + TileEntity t = aWorld.getTileEntity(mNeighbourDoor.xPos, mNeighbourDoor.yPos, mNeighbourDoor.zPos); + // Custom Door + if (t != null) { + if (t instanceof TileEntityPlayerDoorBase) { + TileEntityPlayerDoorBase d = (TileEntityPlayerDoorBase) t; + if (d.mIsOpen) { + return 100; + } else { + return -100; + } + } else + return -100; + } + // Vanilla Door + else { + Block aBlock = mNeighbourDoor.getBlockAtPos(); + BlockDoor aDoor = (aBlock instanceof BlockDoor ? (BlockDoor) aBlock : null); + if (aDoor != null) { + int i1 = aDoor.func_150012_g(mNeighbourDoor.world, mNeighbourDoor.xPos, mNeighbourDoor.yPos, + mNeighbourDoor.zPos); + if ((i1 & 4) != 0) { + return 100; + } else { + return -100; + } + } + } + } + } + return 0; + } + @Override public void updateEntity() { - super.updateEntity(); - mTickCounter++; - if (mTickCounter % 10 == 0) { - if (checkForPlayers(this.getWorldObj())) { - if (this.mIsOpen) { - this.getWorldObj().setBlock(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), this.getClosedMeta(), 3); - this.mIsOpen = false; + + if (this.getWorldObj().isRemote) { + return; + } + + // Look For Neighbours + if (mTickCounter % 100 == 0 || mTickCounter == 0) { + World aWorld = this.getWorldObj(); + BlockPos aThisPos = new BlockPos(xCoord, yCoord, zCoord, aWorld); + BlockPos[] aNeighbors = new BlockPos[4]; + aNeighbors[0] = aThisPos.getXNeg(); + aNeighbors[1] = aThisPos.getXPos(); + aNeighbors[2] = aThisPos.getZNeg(); + aNeighbors[3] = aThisPos.getZPos(); + boolean aFoundDoor = false; + for (BlockPos b : aNeighbors) { + Block aBlock = aWorld.getBlock(b.xPos, b.yPos, b.zPos); + BlockDoor aDoor = (aBlock instanceof BlockDoor ? (BlockDoor) aBlock : null); + if (aDoor != null) { + mNeighbourDoor = b; + aFoundDoor = true; + if (mMeta == 0) { + TileEntity t = aWorld.getTileEntity(b.xPos, b.yPos, b.zPos); + if (t != null) { + if (t instanceof TileEntityPlayerDoorBase) { + TileEntityPlayerDoorBase d = (TileEntityPlayerDoorBase) t; + if (d.mMeta != 0) { + //Logger.INFO("Found Door with Mode set other than 0, assuming slave role."); + mMeta = -1; + } + else { + //Logger.INFO("Found door with no mode set, assuming we are master."); + mMeta = 1; + } + } + else { + //Logger.INFO("Custom door from another mod, assuming slave role."); + mMeta = -1; + } + } + else { + //Logger.INFO("No Tile Entity found, Door is probably vanilla, assuming slave role."); + mMeta = -1; + } + } + break; } - else { - this.getWorldObj().setBlock(this.xCoord, this.yCoord, this.zCoord, this.getBlockType(), this.getOpenMeta(), 3); - this.mIsOpen = true; + } + if (mMeta < 1 && !aFoundDoor) { + //Logger.INFO("Found No Valid Doors around, setting this one to master mode."); + mMeta = 1; + } + } + + if (mTickCounter % 4 == 0) { + int aDoorState = 0; + if (mNeighbourDoor != null) { + aDoorState = getNeighbourState(); + } + World aWorld = this.getWorldObj(); + Block aBlock = aWorld.getBlock(xCoord, yCoord, zCoord); + BlockDoor aDoor = (aBlock instanceof BlockDoor ? (BlockDoor) aBlock : null); + boolean aPlayers = checkForPlayers(this.getWorldObj()); + + if (aDoor != null) { + if (aDoorState != 0 && mMeta == -1) { + if (aDoorState == 100) { + if (!mIsOpen) { + //Logger.INFO("Opening Door (Slave)"); + aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, true); + mIsOpen = true; + } + } else if (aDoorState == -100) { + if (mIsOpen) { + //Logger.INFO("Closing Door (Slave)"); + aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, false); + mIsOpen = false; + } + } + } else { + if (aDoor != null && !hasRedstone()) { + if (aPlayers) { + if (!mIsOpen) { + //Logger.INFO("Opening Door (Mstr)"); + aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, true); + mIsOpen = true; + } else { + // Logger.INFO("Doing Nothing, Door is in correct state."); + } + } else { + if (mIsOpen) { + //Logger.INFO("Closing Door (Mstr)"); + aDoor.func_150014_a(aWorld, this.xCoord, this.yCoord, this.zCoord, false); + mIsOpen = false; + } else { + // Logger.INFO("Doing Nothing, Door is in correct state."); + } + } + } } } - } + + } + super.updateEntity(); + mTickCounter++; } @Override @@ -54,6 +183,15 @@ public class TileEntityPlayerDoorBase extends TileEntity { return this.mMeta; } + public boolean hasRedstone() { + World aWorld = this.worldObj; + if (aWorld != null && !aWorld.isRemote) { + return aWorld.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) + || aWorld.isBlockIndirectlyGettingPowered(xCoord, yCoord + 1, zCoord); + } + return false; + } + @Override public Block getBlockType() { return mBlockType; @@ -63,23 +201,23 @@ public class TileEntityPlayerDoorBase extends TileEntity { public boolean canUpdate() { return true; } - + private boolean checkForPlayers(World aWorld) { int x = 0, y = 0, z = 0; x = this.xCoord; y = this.yCoord; z = this.zCoord; - EntityPlayer aPlayer = aWorld.getClosestPlayer(x, y, z, 8D); + EntityPlayer aPlayer = aWorld.getClosestPlayer(x, y, z, 3.5D); if (aPlayer != null) { return true; - } + } return false; } - + private short getClosedMeta() { return 0; } - + private short getOpenMeta() { return 1; } |