Improved Door Code and Removed Hack
Improved some of our door code by giving some of our variables real names. Also found a hack in BaseDimDoor.isDropped() and a strange comment that said "I have no idea, but sometimes this is returned as the blockID instead of metadata." I finally figured out that due to some random mistake introduced in another function, idDropped() sometimes received a block ID instead of metadata, which is what that comment referred to. I fixed the cause and removed the hack.
This commit is contained in:
@@ -10,6 +10,7 @@ import net.minecraft.client.renderer.texture.IconRegister;
|
|||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
@@ -27,8 +28,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||||||
|
|
||||||
public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEntityProvider
|
public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEntityProvider
|
||||||
{
|
{
|
||||||
protected final DDProperties properties;
|
|
||||||
private Icon blockIconBottom;
|
private Icon blockIconBottom;
|
||||||
|
protected final DDProperties properties;
|
||||||
|
|
||||||
public BaseDimDoor(int blockID, Material material, DDProperties properties)
|
public BaseDimDoor(int blockID, Material material, DDProperties properties)
|
||||||
{
|
{
|
||||||
@@ -229,60 +230,38 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
|
|||||||
* their own) Args: x, y, z, neighbor blockID
|
* their own) Args: x, y, z, neighbor blockID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
|
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
|
||||||
{
|
{
|
||||||
int var6 = par1World.getBlockMetadata(par2, par3, par4);
|
int metadata = world.getBlockMetadata(x, y, z);
|
||||||
|
if (!isUpperDoorBlock(metadata))
|
||||||
if ((var6 & 8) == 0)
|
|
||||||
{
|
{
|
||||||
boolean var7 = false;
|
if (world.getBlockId(x, y - 1, z) != this.blockID)
|
||||||
|
|
||||||
if (par1World.getBlockId(par2, par3 + 1, par4) != this.blockID)
|
|
||||||
{
|
{
|
||||||
par1World.setBlock(par2, par3, par4, 0);
|
world.setBlock(x, y, z, 0);
|
||||||
var7 = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (neighborID > 0 && neighborID != this.blockID)
|
||||||
if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4))
|
|
||||||
{
|
|
||||||
par1World.setBlockWithNotify(par2, par3, par4, 0);
|
|
||||||
var7 = true;
|
|
||||||
|
|
||||||
if (par1World.getBlockId(par2, par3 + 1, par4) == this.blockID)
|
|
||||||
{
|
|
||||||
par1World.setBlockWithNotify(par2, par3 + 1, par4, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
**/
|
|
||||||
|
|
||||||
if (var7)
|
|
||||||
{
|
{
|
||||||
if (!par1World.isRemote)
|
this.onNeighborBlockChange(world, x, y - 1, z, neighborID);
|
||||||
{
|
|
||||||
this.dropBlockAsItem(par1World, par2, par3, par4, properties.DimensionalDoorID, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boolean var8 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) || par1World.isBlockIndirectlyGettingPowered(par2, par3 + 1, par4);
|
|
||||||
|
|
||||||
if ((var8 || par5 > 0 && Block.blocksList[par5].canProvidePower()) && par5 != this.blockID)
|
|
||||||
{
|
|
||||||
this.onPoweredBlockChange(par1World, par2, par3, par4, var8);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (par1World.getBlockId(par2, par3 - 1, par4) != this.blockID)
|
if (world.getBlockId(x, y + 1, z) != this.blockID)
|
||||||
{
|
{
|
||||||
par1World.setBlock(par2, par3, par4, 0);
|
world.setBlock(x, y, z, 0);
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
this.dropBlockAsItem(world, x, y, z, metadata, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (par5 > 0 && par5 != this.blockID)
|
|
||||||
{
|
{
|
||||||
this.onNeighborBlockChange(par1World, par2, par3 - 1, par4, par5);
|
boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z);
|
||||||
|
if ((powered || neighborID > 0 && Block.blocksList[neighborID].canProvidePower()) && neighborID != this.blockID)
|
||||||
|
{
|
||||||
|
this.onPoweredBlockChange(world, x, y, z, powered);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,15 +276,12 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
|
|||||||
return this.getDrops();
|
return this.getDrops();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public int idDropped(int par1, Random par2Random, int par3)
|
* Returns the ID of the items to drop on destruction.
|
||||||
|
*/
|
||||||
|
public int idDropped(int metadata, Random random, int fortune)
|
||||||
{
|
{
|
||||||
//I have no idea, but sometimes this is returned as the blockID instead of metadata.
|
return isUpperDoorBlock(metadata) ? 0 : this.getDrops();
|
||||||
if(par1>100)
|
|
||||||
{
|
|
||||||
return this.getDrops();
|
|
||||||
}
|
|
||||||
return (par1 & 8) != 0 ? 0 :getDrops();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -375,9 +351,11 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDrops()
|
public abstract int getDrops();
|
||||||
|
|
||||||
|
protected static boolean isUpperDoorBlock(int metadata)
|
||||||
{
|
{
|
||||||
return this.blockID;
|
return (metadata & 8) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isDoorOpen(int metadata)
|
protected static boolean isDoorOpen(int metadata)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class BlockDoorGold extends BlockDoor
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
|
public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
|
||||||
{
|
{
|
||||||
if (par1IBlockAccess.getBlockId(par2, par3-1, par4) == this.blockID)
|
if (par1IBlockAccess.getBlockId(par2, par3 - 1, par4) == this.blockID)
|
||||||
{
|
{
|
||||||
return this.blockIcon;
|
return this.blockIcon;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ public class BlockGoldDimDoor extends BaseDimDoor
|
|||||||
dimension.createLink(x, y, z, LinkTypes.POCKET,world.getBlockMetadata(x, y - 1, z));
|
dimension.createLink(x, y, z, LinkTypes.POCKET,world.getBlockMetadata(x, y - 1, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDrops()
|
public int getDrops()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package StevenDimDoors.mod_pocketDim.blocks;
|
package StevenDimDoors.mod_pocketDim.blocks;
|
||||||
|
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||||
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
|
import StevenDimDoors.mod_pocketDim.core.DDTeleporter;
|
||||||
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||||
@@ -7,14 +13,6 @@ import StevenDimDoors.mod_pocketDim.core.LinkTypes;
|
|||||||
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||||
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||||
|
|
||||||
import net.minecraft.block.material.Material;
|
|
||||||
import net.minecraft.client.particle.EntityFX;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public class TransientDoor extends BaseDimDoor
|
public class TransientDoor extends BaseDimDoor
|
||||||
{
|
{
|
||||||
public TransientDoor(int blockID, Material material, DDProperties properties)
|
public TransientDoor(int blockID, Material material, DDProperties properties)
|
||||||
|
|||||||
Reference in New Issue
Block a user