diff --git a/resources/assemblyline/textures/craneRail.png b/resources/assemblyline/textures/craneRail.png index d3b312f8..567cfebc 100644 Binary files a/resources/assemblyline/textures/craneRail.png and b/resources/assemblyline/textures/craneRail.png differ diff --git a/resources/assemblyline/textures/quarry_controller_map.png b/resources/assemblyline/textures/quarryControllerOff.png similarity index 100% rename from resources/assemblyline/textures/quarry_controller_map.png rename to resources/assemblyline/textures/quarryControllerOff.png diff --git a/resources/assemblyline/textures/quarryControllerValid.png b/resources/assemblyline/textures/quarryControllerValid.png new file mode 100644 index 00000000..1634f508 Binary files /dev/null and b/resources/assemblyline/textures/quarryControllerValid.png differ diff --git a/src/minecraft/assemblyline/common/machine/crane/ICraneConnectable.java b/src/minecraft/assemblyline/api/ICraneConnectable.java similarity index 76% rename from src/minecraft/assemblyline/common/machine/crane/ICraneConnectable.java rename to src/minecraft/assemblyline/api/ICraneConnectable.java index eb200bd6..403caf8e 100644 --- a/src/minecraft/assemblyline/common/machine/crane/ICraneConnectable.java +++ b/src/minecraft/assemblyline/api/ICraneConnectable.java @@ -1,4 +1,4 @@ -package assemblyline.common.machine.crane; +package assemblyline.api; import net.minecraftforge.common.ForgeDirection; diff --git a/src/minecraft/assemblyline/api/ICraneStructure.java b/src/minecraft/assemblyline/api/ICraneStructure.java new file mode 100644 index 00000000..facfb01e --- /dev/null +++ b/src/minecraft/assemblyline/api/ICraneStructure.java @@ -0,0 +1,6 @@ +package assemblyline.api; + +public interface ICraneStructure extends ICraneConnectable +{ + +} diff --git a/src/minecraft/assemblyline/client/render/RenderCraneController.java b/src/minecraft/assemblyline/client/render/RenderCraneController.java index 48c4c90b..afb0f9ff 100644 --- a/src/minecraft/assemblyline/client/render/RenderCraneController.java +++ b/src/minecraft/assemblyline/client/render/RenderCraneController.java @@ -1,52 +1,52 @@ package assemblyline.client.render; -import static org.lwjgl.opengl.GL11.GL_LIGHTING; -import static org.lwjgl.opengl.GL11.glEnable; -import static org.lwjgl.opengl.GL11.glPopMatrix; -import static org.lwjgl.opengl.GL11.glPushMatrix; -import static org.lwjgl.opengl.GL11.glRotatef; -import static org.lwjgl.opengl.GL11.glTranslated; +import static org.lwjgl.opengl.GL11.*; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; import assemblyline.client.model.ModelCraneController; import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.crane.TileEntityCraneController; public class RenderCraneController extends RenderImprintable { - public static final String TEXTURE = "quarry_controller_map.png"; + public static final String TEXTURE = "quarryControllerOff.png"; + public static final String TEXTURE_VALID = "quarryControllerValid.png"; public static final ModelCraneController MODEL = new ModelCraneController(); @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { - this.bindTextureByName(AssemblyLine.TEXTURE_PATH + TEXTURE); - ForgeDirection rot = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); - float angle = 0f; - switch (rot) + if (tileEntity != null && tileEntity instanceof TileEntityCraneController) { - case NORTH: + this.bindTextureByName(AssemblyLine.TEXTURE_PATH + (((TileEntityCraneController) tileEntity).isCraneValid() ? TEXTURE_VALID : TEXTURE)); + ForgeDirection rot = ForgeDirection.getOrientation(tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + float angle = 0f; + switch (rot) { - angle = 90f; - break; - } - case SOUTH: - { - angle = 270f; - break; - } - case EAST: - { - angle = 180f; - break; + case NORTH: + { + angle = 90f; + break; + } + case SOUTH: + { + angle = 270f; + break; + } + case EAST: + { + angle = 180f; + break; + } } + glPushMatrix(); + glTranslated(x + 0.5, y + 1.5, z + 0.5); + glRotatef(180f, 0f, 0f, 1f); + glRotatef(angle, 0f, 1f, 0f); + glEnable(GL_LIGHTING); + MODEL.render(0.0625f); + glPopMatrix(); } - glPushMatrix(); - glTranslated(x + 0.5, y + 1.5, z + 0.5); - glRotatef(180f, 0f, 0f, 1f); - glRotatef(angle, 0f, 1f, 0f); - glEnable(GL_LIGHTING); - MODEL.render(0.0625f); - glPopMatrix(); } } \ No newline at end of file diff --git a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java index 91a7e4b4..074bfd01 100644 --- a/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/BlockCraneController.java @@ -34,30 +34,26 @@ public class BlockCraneController extends BlockMachine @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entity) { - int rot = (int) Math.min((entity.rotationYaw - 45f) / 90f, 3); + int rot = (int) Math.min(((entity.rotationYaw + 315f) % 360f) / 90f, 3); switch (rot) { case 0: // WEST { - System.out.println("Facing west..."); world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal()); break; } case 1: // NORTH { - System.out.println("Facing north..."); world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal()); break; } case 2: // EAST { - System.out.println("Facing east..."); world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal()); break; } default: // SOUTH { - System.out.println("Facing south..."); world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal()); break; } diff --git a/src/minecraft/assemblyline/common/machine/crane/CraneHelper.java b/src/minecraft/assemblyline/common/machine/crane/CraneHelper.java index 9c8d72dc..cc5ba761 100644 --- a/src/minecraft/assemblyline/common/machine/crane/CraneHelper.java +++ b/src/minecraft/assemblyline/common/machine/crane/CraneHelper.java @@ -1,7 +1,10 @@ package assemblyline.common.machine.crane; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; +import assemblyline.api.ICraneConnectable; +import assemblyline.api.ICraneStructure; /** * Manager of crane movement, mapping, setup, but not AI @@ -15,6 +18,16 @@ public class CraneHelper * The maximum size that a crane can be */ public static final int MAX_SIZE = 64; + + public static boolean isCraneBlock(World world, int x, int y, int z) + { + return world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof ICraneConnectable; + } + + public static boolean isCraneStructureBlock(World world, int x, int y, int z) + { + return world.getBlockTileEntity(x, y, z) != null && world.getBlockTileEntity(x, y, z) instanceof ICraneStructure; + } public static boolean canFrameConnectTo(TileEntity tileEntity, int x, int y, int z, ForgeDirection side) { diff --git a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java index a1d67f8b..59b356f0 100644 --- a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java +++ b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneController.java @@ -1,14 +1,170 @@ package assemblyline.common.machine.crane; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; +import assemblyline.api.ICraneConnectable; import assemblyline.common.machine.TileEntityAssemblyNetwork; public class TileEntityCraneController extends TileEntityAssemblyNetwork implements ICraneConnectable { + int width, height, depth; + boolean isCraneValid; + long ticks; + + public TileEntityCraneController() + { + super(); + width = height = depth = 0; + isCraneValid = false; + ticks = 0; + } + @Override public void updateEntity() { - + ticks++; + if (ticks % 20 == 0) + { + validateCrane(); + } + } + + public boolean isCraneValid() + { + return isCraneValid; + } + + private void validateCrane() + { + isCraneValid = false; + width = height = depth = 0; + findCraneHeight(); + findCraneWidth(); + findCraneDepth(); + if (Math.abs(height) > 1 && Math.abs(width) > 1 && Math.abs(depth) > 1) + { + isCraneValid = isFrameValid(); + } + } + + private boolean isFrameValid() + { + for (int x = Math.min(0, width); x <= Math.max(0, width); x++) + { + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord)) + return false; + } + for (int x = Math.min(0, width); x <= Math.max(0, width); x++) + { + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord + depth)) + return false; + } + for (int z = Math.min(0, depth); z <= Math.max(0, depth); z++) + { + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + height, zCoord + z)) + return false; + } + for (int z = Math.min(0, depth); z <= Math.max(0, depth); z++) + { + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + width, yCoord + height, zCoord + z)) + return false; + } + for (int x = Math.min(width + 1, 1); x <= Math.max(-1, width - 1); x++) + { + for (int z = Math.min(depth + 1, 1); z <= Math.max(-1, depth - 1); z++) + { + if (!worldObj.isAirBlock(xCoord + x, yCoord + height, zCoord + z)) + return false; + } + } + return true; + } + + /** + * Find x size and store in this.width + */ + private void findCraneWidth() + { + if (height == 0) + { + width = 0; + return; + } + int x = 0; + ForgeDirection facing = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + while (true) + { + if (Math.abs(x) > CraneHelper.MAX_SIZE) + break; + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord + x, yCoord + height, zCoord)) + break; + if (facing == ForgeDirection.NORTH || facing == ForgeDirection.EAST) + { + x++; + } + else + { + x--; + } + } + width = x; //can be negative + if (width < 0) + width++; + if (width > 0) + width--; + } + + /** + * Find y size and store in this.height + */ + private void findCraneHeight() + { + int y = 1; + while (true) + { + if (yCoord + y >= 256) + break; + if (y > CraneHelper.MAX_SIZE) + break; + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + y, zCoord)) + break; + y++; + } + height = y - 1; + } + + /** + * Find x size and store in this.depth + */ + private void findCraneDepth() + { + if (height == 0) + { + width = 0; + return; + } + int z = 0; + ForgeDirection facing = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + while (true) + { + if (Math.abs(z) > CraneHelper.MAX_SIZE) + break; + if (!CraneHelper.isCraneStructureBlock(worldObj, xCoord, yCoord + height, zCoord + z)) + break; + if (facing == ForgeDirection.SOUTH || facing == ForgeDirection.EAST) + { + z++; + } + else + { + z--; + } + } + depth = z; //can be negative + if (depth < 0) + depth++; + if (depth > 0) + depth--; } @Override @@ -23,4 +179,24 @@ public class TileEntityCraneController extends TileEntityAssemblyNetwork impleme return true; return false; } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setInteger("width", width); + nbt.setInteger("height", height); + nbt.setInteger("depth", depth); + nbt.setBoolean("isValid", isCraneValid); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + width = nbt.getInteger("width"); + height = nbt.getInteger("height"); + depth = nbt.getInteger("depth"); + isCraneValid = nbt.getBoolean("isValid"); + } } diff --git a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java index 06e19a05..04ad537d 100644 --- a/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java +++ b/src/minecraft/assemblyline/common/machine/crane/TileEntityCraneRail.java @@ -1,9 +1,11 @@ package assemblyline.common.machine.crane; import net.minecraftforge.common.ForgeDirection; +import assemblyline.api.ICraneConnectable; +import assemblyline.api.ICraneStructure; import assemblyline.common.machine.TileEntityAssemblyNetwork; -public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneConnectable +public class TileEntityCraneRail extends TileEntityAssemblyNetwork implements ICraneStructure { @Override