Work on automatic orientation setting

This commit is contained in:
Aidan Brady 2013-08-03 13:18:12 -04:00
parent 01458b1d5b
commit 5262a37826
2 changed files with 49 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package resonantinduction.contractor;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -30,8 +31,21 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
@Override @Override
public void onBlockAdded(World world, int x, int y, int z) public void onBlockAdded(World world, int x, int y, int z)
{ {
TileEntityEMContractor tileEntity = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z); TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
tileEntity.updateBounds(); tileContractor.updateBounds();
if(!tileContractor.isLatched())
{
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = world.getBlockTileEntity(x+side.offsetX, y+side.offsetY, z+side.offsetZ);
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
}
}
}
} }
@Override @Override
@ -52,10 +66,20 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
@Override @Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID) public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
if(!tileContractor.isLatched())
{ {
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{ {
TileEntity tileEntity = world.getBlockTileEntity(x+side.offsetX, y+side.offsetY, z+side.offsetZ);
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
}
}
} }
} }

View file

@ -4,6 +4,7 @@ import java.util.List;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
@ -193,10 +194,24 @@ public class TileEntityEMContractor extends TileEntity
} }
} }
public boolean isLatched()
{
ForgeDirection side = facing.getOpposite();
TileEntity tile = worldObj.getBlockTileEntity(xCoord+facing.offsetX, yCoord+facing.offsetY, zCoord+facing.offsetZ);
if(tile instanceof IInventory)
{
return true;
}
return false;
}
public void incrementFacing() public void incrementFacing()
{ {
int newOrdinal = facing.ordinal() < 5 ? facing.ordinal()+1 : 0; int newOrdinal = facing.ordinal() < 5 ? facing.ordinal()+1 : 0;
facing = ForgeDirection.getOrientation(newOrdinal); setFacing(ForgeDirection.getOrientation(newOrdinal));
updateBounds(); updateBounds();
} }
@ -206,6 +221,11 @@ public class TileEntityEMContractor extends TileEntity
return facing; return facing;
} }
public void setFacing(ForgeDirection side)
{
facing = side;
}
@Override @Override
public void readFromNBT(NBTTagCompound nbtTags) public void readFromNBT(NBTTagCompound nbtTags)
{ {