Fixed an issue with multi-block code

This commit is contained in:
Robert 2013-12-26 06:30:09 -05:00
parent f3d0abd2b1
commit 7df7a141e8
3 changed files with 34 additions and 48 deletions

View file

@ -27,20 +27,12 @@ import cpw.mods.fml.relauncher.SideOnly;
public class BlockMulti extends BlockContainer implements IExtraBlockInfo
{
public String textureName = null;
public String channel = "";
public BlockMulti()
{
super(DarkCore.CONFIGURATION.getBlock("MultiBlock", DarkCore.getNextID()).getInt(), UniversalElectricity.machine);
this.setHardness(0.8F);
this.setUnlocalizedName("multiBlock");
this.setChannel(DarkCore.CHANNEL);
}
public BlockMulti setChannel(String channel)
{
this.channel = channel;
return this;
}
@Override
@ -121,22 +113,25 @@ public class BlockMulti extends BlockContainer implements IExtraBlockInfo
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityMulti(this.channel);
return new TileEntityMulti();
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z)
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z);
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition;
if (mainBlockPosition != null)
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityMulti)
{
int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition;
if (mainBlockID > 0)
if (mainBlockPosition != null && !mainBlockPosition.equals(new Vector3(x, y, z)))
{
return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
int mainBlockID = mainBlockPosition.getBlockID(world);
if (mainBlockID > 0)
{
return Block.blocksList[mainBlockID].getPickBlock(target, world, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ());
}
}
}

View file

@ -163,6 +163,7 @@ public abstract class TileEntityEnergyMachine extends TileEntityMachine implemen
return 0;
}
/** Called to produce power using the output enumset for directions to output in */
protected void produce()
{
for (ForgeDirection direction : this.getOutputDirections())

View file

@ -7,6 +7,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.api.vector.Vector3;
import com.builtbroken.minecraft.DarkCore;
import com.builtbroken.minecraft.interfaces.IMultiBlock;
import com.builtbroken.minecraft.network.ISimplePacketReceiver;
import com.builtbroken.minecraft.network.PacketHandler;
@ -21,18 +22,12 @@ public class TileEntityMulti extends TileEntity implements ISimplePacketReceiver
{
// The the position of the main block
public Vector3 mainBlockPosition;
public String channel;
public TileEntityMulti()
{
}
public TileEntityMulti(String channel)
{
this.channel = channel;
}
public void setMainBlock(Vector3 mainBlock)
{
this.mainBlockPosition = mainBlock;
@ -43,18 +38,31 @@ public class TileEntityMulti extends TileEntity implements ISimplePacketReceiver
}
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
{
try
{
if (id.equalsIgnoreCase("MainBlock"))
{
this.mainBlockPosition = new Vector3(data.readInt(), data.readInt(), data.readInt());
return true;
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
if (this.mainBlockPosition != null)
{
if (this.channel == null || this.channel == "" && this.getBlockType() instanceof BlockMulti)
{
this.channel = ((BlockMulti) this.getBlockType()).channel;
}
return PacketHandler.instance().getTilePacket(this.channel, "MainBlock", this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
return PacketHandler.instance().getTilePacket(DarkCore.CHANNEL, "MainBlock", this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ());
}
return null;
@ -125,22 +133,4 @@ public class TileEntityMulti extends TileEntity implements ISimplePacketReceiver
return false;
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
{
try
{
if (id.equalsIgnoreCase("MainBlock"))
{
this.mainBlockPosition = new Vector3(data.readInt(), data.readInt(), data.readInt());
return true;
}
}
catch (Exception e)
{
e.printStackTrace();
return true;
}
return false;
}
}