More efficient redstone control

This commit is contained in:
Aidan C. Brady committed 2013-12-25 00:03:04 -05:00
1 parent 0ee53780b6
commit 583ef4fc19
8 files changed
+103 -15

No files matched your search

@@ -34,4 +34,10 @@ public interface IRedstoneControl
* @param type - RedstoneControl type to set
*/
public void setControlType(RedstoneControl type);
/**
* If the block is getting powered or not by redstone (indirectly).
* @return if the block is getting powered indirectly
*/
public boolean isPowered();
}
+10 -4
View File
@@ -82,11 +82,16 @@ public class BlockBasic extends Block
{
if(!world.isRemote)
{
if(id == blockID && world.getBlockTileEntity(x, y, z) instanceof TileEntityDynamicTank)
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(id == blockID && tileEntity instanceof TileEntityDynamicTank)
{
TileEntityDynamicTank dynamicTank = (TileEntityDynamicTank)world.getBlockTileEntity(x, y, z);
dynamicTank.update();
((TileEntityDynamicTank)tileEntity).update();
}
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onNeighborChange(x, y, z, id);
}
}
}
@@ -582,6 +587,7 @@ public class BlockBasic extends Block
}
tileEntity.setFacing((short)change);
tileEntity.redstone = world.isBlockIndirectlyGettingPowered(x, y, z);
if(tileEntity instanceof IBoundingBlock)
{
@@ -16,6 +16,7 @@ import mekanism.common.Mekanism;
import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.item.ItemBlockEnergyCube;
import mekanism.common.tileentity.TileEntityBasicBlock;
import mekanism.common.tileentity.TileEntityDynamicTank;
import mekanism.common.tileentity.TileEntityElectricBlock;
import mekanism.common.tileentity.TileEntityEnergyCube;
import net.minecraft.block.BlockContainer;
@@ -62,6 +63,20 @@ public class BlockEnergyCube extends BlockContainer
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister register) {}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
if(!world.isRemote)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onNeighborChange(x, y, z, id);
}
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
{
@@ -89,6 +104,7 @@ public class BlockEnergyCube extends BlockContainer
}
tileEntity.setFacing((short)change);
tileEntity.redstone = world.isBlockIndirectlyGettingPowered(x, y, z);
}
@Override
@@ -59,7 +59,22 @@ public class BlockGasTank extends BlockContainer
}
tileEntity.setFacing((short)change);
tileEntity.redstone = world.isBlockIndirectlyGettingPowered(x, y, z);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
if(!world.isRemote)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onNeighborChange(x, y, z, id);
}
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int facing, float playerX, float playerY, float playerZ)
+12 -4
View File
@@ -215,6 +215,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
}
tileEntity.setFacing((short)change);
tileEntity.redstone = world.isBlockIndirectlyGettingPowered(x, y, z);
if(tileEntity instanceof IBoundingBlock)
{
@@ -787,11 +788,18 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
{
if(!world.isRemote)
{
if(world.getBlockTileEntity(x, y, z) instanceof TileEntityLogisticalSorter)
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity instanceof TileEntityBasicBlock)
{
TileEntityLogisticalSorter tileEntity = (TileEntityLogisticalSorter)world.getBlockTileEntity(x, y, z);
((TileEntityBasicBlock)tileEntity).onNeighborChange(x, y, z, id);
}
if(tileEntity instanceof TileEntityLogisticalSorter)
{
TileEntityLogisticalSorter sorter = (TileEntityLogisticalSorter)tileEntity;
if(!tileEntity.hasInventory())
if(!sorter.hasInventory())
{
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
@@ -799,7 +807,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
if(tile instanceof IInventory)
{
tileEntity.setFacing((short)dir.getOpposite().ordinal());
sorter.setFacing((short)dir.getOpposite().ordinal());
return;
}
}
@@ -35,6 +35,8 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
/** A timer used to send packets to clients. */
public int ticker;
public boolean redstone = false;
public boolean doAutoSync = true;
public List<ITileComponent> components = new ArrayList<ITileComponent>();
@@ -67,6 +69,7 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
public void handlePacketData(ByteArrayDataInput dataStream)
{
facing = dataStream.readInt();
redstone = dataStream.readBoolean();
if(clientFacing != facing)
{
@@ -85,6 +88,7 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
public ArrayList getNetworkedData(ArrayList data)
{
data.add(facing);
data.add(redstone);
for(ITileComponent component : components)
{
@@ -115,10 +119,8 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
{
super.readFromNBT(nbtTags);
if(nbtTags.hasKey("facing"))
{
facing = nbtTags.getInteger("facing");
}
facing = nbtTags.getInteger("facing");
redstone = nbtTags.getBoolean("redstone");
for(ITileComponent component : components)
{
@@ -132,6 +134,7 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
super.writeToNBT(nbtTags);
nbtTags.setInteger("facing", facing);
nbtTags.setBoolean("redstone", redstone);
for(ITileComponent component : components)
{
@@ -161,7 +164,7 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
if(facing != clientFacing)
{
PacketHandler.sendPacket(Transmission.ALL_CLIENTS, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())));
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())), worldObj.provider.dimensionId);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, worldObj.getBlockId(xCoord, yCoord, zCoord));
clientFacing = facing;
}
@@ -194,4 +197,23 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench
{
return getBlockType().getPickBlock(null, worldObj, xCoord, yCoord, zCoord);
}
public boolean isPowered()
{
return redstone;
}
public void onNeighborChange(int x, int y, int z, int id)
{
if(!worldObj.isRemote)
{
boolean power = worldObj.isBlockIndirectlyGettingPowered(x, y, z);
if(redstone != power)
{
redstone = power;
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketTileEntity().setParams(Coord4D.get(this), getNetworkedData(new ArrayList())), worldObj.provider.dimensionId);
}
}
}
}
@@ -1071,11 +1071,11 @@ public final class MekanismUtils
}
else if(control.getControlType() == RedstoneControl.HIGH)
{
return world.isBlockIndirectlyGettingPowered(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
return control.isPowered();
}
else if(control.getControlType() == RedstoneControl.LOW)
{
return !world.isBlockIndirectlyGettingPowered(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
return !control.isPowered();
}
return false;
@@ -69,6 +69,20 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
@Override
public void registerIcons(IconRegister register) {}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
if(!world.isRemote)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity instanceof TileEntityBasicBlock)
{
((TileEntityBasicBlock)tileEntity).onNeighborChange(x, y, z, id);
}
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
{
@@ -130,6 +144,7 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
}
tileEntity.setFacing((short)change);
tileEntity.redstone = world.isBlockIndirectlyGettingPowered(x, y, z);
if(tileEntity instanceof IBoundingBlock)
{