From a05870a2ef54707aba614fa63132c57c500785f2 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Fri, 13 Dec 2013 17:13:46 -0500 Subject: [PATCH] A few fixes --- .../common/multipart/PartMechanicalPipe.java | 5 +- .../common/multipart/PartTransmitter.java | 19 +-- .../prefab/ConductorChunkInitiate.java | 64 ---------- .../prefab/block/BlockRotatable.java | 119 ++++++++++-------- 4 files changed, 78 insertions(+), 129 deletions(-) delete mode 100644 common/universalelectricity/prefab/ConductorChunkInitiate.java diff --git a/common/mekanism/common/multipart/PartMechanicalPipe.java b/common/mekanism/common/multipart/PartMechanicalPipe.java index e9e0f7353..590477bd0 100644 --- a/common/mekanism/common/multipart/PartMechanicalPipe.java +++ b/common/mekanism/common/multipart/PartMechanicalPipe.java @@ -41,9 +41,10 @@ public class PartMechanicalPipe extends PartTransmitter implements return "mekanism:mechanical_pipe"; } - public static void registerIcons(IconRegister register){ + public static void registerIcons(IconRegister register) + { pipeIcons = new PartTransmitterIcons(2); - pipeIcons.registerCenterIcons(register, new String[]{"MechanicalPipe", "MechanicalPipeActive"}); + pipeIcons.registerCenterIcons(register, new String[] {"MechanicalPipe", "MechanicalPipeActive"}); pipeIcons.registerSideIcon(register, "MechanicalPipeSide"); } diff --git a/common/mekanism/common/multipart/PartTransmitter.java b/common/mekanism/common/multipart/PartTransmitter.java index 4bf32c563..59bafcda1 100644 --- a/common/mekanism/common/multipart/PartTransmitter.java +++ b/common/mekanism/common/multipart/PartTransmitter.java @@ -105,7 +105,6 @@ public abstract class PartTransmitter> extends TM public abstract Icon getCenterIcon(); public abstract Icon getSideIcon(); - @Override public void bind(TileMultipart t) @@ -114,7 +113,7 @@ public abstract class PartTransmitter> extends TM { getTransmitterNetwork().transmitters.remove(tile()); super.bind(t); - getTransmitterNetwork().transmitters.add((ITransmitter) tile()); + getTransmitterNetwork().transmitters.add((ITransmitter)tile()); } else { super.bind(t); @@ -126,12 +125,12 @@ public abstract class PartTransmitter> extends TM { if(world().isRemote) { - if(delayTicks == 3) + if(delayTicks == 5) { - delayTicks++; + delayTicks = 6; /* don't refresh again */ refreshTransmitterNetwork(); } - else if(delayTicks < 3) + else if(delayTicks < 5) { delayTicks++; } @@ -146,7 +145,7 @@ public abstract class PartTransmitter> extends TM public static boolean connectionMapContainsSide(byte connections, ForgeDirection side) { - byte tester = (byte) (1 << side.ordinal()); + byte tester = (byte)(1 << side.ordinal()); return (connections & tester) > 0; } @@ -181,7 +180,7 @@ public abstract class PartTransmitter> extends TM if(world().isBlockIndirectlyGettingPowered(x(), y(), z())) { - return connections; + return connections; } for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) @@ -194,7 +193,6 @@ public abstract class PartTransmitter> extends TM { connections |= 1 << side.ordinal(); } - } } @@ -375,7 +373,8 @@ public abstract class PartTransmitter> extends TM if(connectionMapContainsSide(possibleTransmitters, side)) { TileEntity cable = Object3D.get(tile()).getFromSide(side).getTileEntity(world()); - if(TransmissionType.checkTransmissionType(cable, TransmissionType.ENERGY) && ((ITransmitter)cable).getTransmitterNetwork(false) != null) + + if(TransmissionType.checkTransmissionType(cable, getTransmissionType()) && ((ITransmitter)cable).getTransmitterNetwork(false) != null) { connectedNets.add(((ITransmitter)cable).getTransmitterNetwork()); } @@ -477,7 +476,9 @@ public abstract class PartTransmitter> extends TM public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) { if(item == null) + { return false; + } if(item.getItem() instanceof ItemConfigurator && player.isSneaking()) { isActive ^= true; diff --git a/common/universalelectricity/prefab/ConductorChunkInitiate.java b/common/universalelectricity/prefab/ConductorChunkInitiate.java deleted file mode 100644 index 05bfdb333..000000000 --- a/common/universalelectricity/prefab/ConductorChunkInitiate.java +++ /dev/null @@ -1,64 +0,0 @@ -package universalelectricity.prefab; - -import java.util.ArrayList; -import java.util.Collection; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.ForgeSubscribe; -import net.minecraftforge.event.world.ChunkEvent; -import universalelectricity.core.block.INetworkConnection; - -/** - * A helper class to register chunk loading for your wires if you need them to be refreshed upon - * chunk load. This prevents the need for your wire to be refreshed. - * - * @author Calclavia, Aidancbrady - * - */ -public class ConductorChunkInitiate -{ - private static boolean onChunkLoadRegistered = false; - - /** - * Registers and initiates Universal Electricity's network loader. - */ - public static void register() - { - if (!onChunkLoadRegistered) - { - try - { - MinecraftForge.EVENT_BUS.register(new ConductorChunkInitiate()); - onChunkLoadRegistered = true; - } - catch (Exception e) - { - e.printStackTrace(); - } - } - } - - @ForgeSubscribe - public void onChunkLoad(ChunkEvent.Load event) - { - if (event.getChunk() != null) - { - Collection collection = new ArrayList(); - collection.addAll(event.getChunk().chunkTileEntityMap.values()); - - for (Object obj : collection) - { - if (obj instanceof TileEntity) - { - TileEntity tileEntity = (TileEntity) obj; - - if (tileEntity instanceof INetworkConnection) - { - ((INetworkConnection) tileEntity).refresh(); - } - } - } - } - } -} diff --git a/common/universalelectricity/prefab/block/BlockRotatable.java b/common/universalelectricity/prefab/block/BlockRotatable.java index a7358ca92..2856926a1 100644 --- a/common/universalelectricity/prefab/block/BlockRotatable.java +++ b/common/universalelectricity/prefab/block/BlockRotatable.java @@ -8,70 +8,81 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -/** A block that can rotate based on placed position and wrenching. - * - * @author Calclavia */ +/** + * A block that can rotate based on placed position and wrenching. + * + * @author Calclavia + */ public abstract class BlockRotatable extends BlockTile implements IRotatableBlock { - public BlockRotatable(int id, Material material) - { - super(id, material); - } + protected byte rotationMask = 60; - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) - { - int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - int change = 3; + public BlockRotatable(int id, Material material) + { + super(id, material); + } - switch (angle) - { - case 0: - change = 2; - break; + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) + { + int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; + int change = 3; - case 1: - change = 5; - break; + switch (angle) + { + case 0: + change = 2; + break; - case 2: - change = 3; - break; + case 1: + change = 5; + break; - case 3: - change = 4; - break; - } + case 2: + change = 3; + break; - world.setBlockMetadataWithNotify(x, y, z, change, 3); - } + case 3: + change = 4; + break; + } - @Override - public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) - { - this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)); - return true; - } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + } - public static boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis, int mask) - { - int rotMeta = worldObj.getBlockMetadata(x, y, z); - int masked = rotMeta & ~mask; - ForgeDirection orientation = ForgeDirection.getOrientation(rotMeta & mask); - ForgeDirection rotated = orientation.getRotation(axis); - worldObj.setBlockMetadataWithNotify(x, y, z, rotated.ordinal() & mask | masked, 3); - return true; - } + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) + { + return this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)); + } - @Override - public ForgeDirection getDirection(World world, int x, int y, int z) - { - return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); - } + @Override + public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) + { + int currentRotMeta = worldObj.getBlockMetadata(x, y, z); + ForgeDirection orientation = ForgeDirection.getOrientation(currentRotMeta); + ForgeDirection rotated = orientation.getRotation(axis); + int rmeta = rotated.ordinal(); + int rmetaBit = 1 << rmeta; + System.out.println(rmetaBit + ": " + (rmetaBit & this.rotationMask)); + if ((rmetaBit & this.rotationMask) == rmetaBit) + { + worldObj.setBlockMetadataWithNotify(x, y, z, rmeta, 3); + return true; + } - @Override - public void setDirection(World world, int x, int y, int z, ForgeDirection direction) - { - world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3); - } + return false; + } + + @Override + public ForgeDirection getDirection(World world, int x, int y, int z) + { + return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); + } + + @Override + public void setDirection(World world, int x, int y, int z, ForgeDirection direction) + { + world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3); + } } \ No newline at end of file