diff --git a/.gitignore b/.gitignore index 8d16946..78c71b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .idea build run +bin +off \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7c2d31b..df51226 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,9 @@ buildscript { apply plugin: 'forge' +sourceCompatibility = '1.8' +targetCompatibility = '1.8' + version = "1.0" group= "modgroup" archivesBaseName = "modid" @@ -26,8 +29,12 @@ minecraft { runDir = "run" } -dependencies { +repositories { + maven { url = "https://maven.tilera.xyz" } +} +dependencies { + compile "universalelectricity:basiccomponents:1.0.2-dirty:deobf" } processResources diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/assemblyline/api/IArmbot.java b/src/main/java/assemblyline/api/IArmbot.java new file mode 100644 index 0000000..48412d1 --- /dev/null +++ b/src/main/java/assemblyline/api/IArmbot.java @@ -0,0 +1,22 @@ +package assemblyline.api; + +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; + +public interface IArmbot { + public void grabEntity(Entity var1); + + public void grabItem(ItemStack var1); + + public void dropEntity(Entity var1); + + public void dropItem(ItemStack var1); + + public void dropAll(); + + public List getGrabbedEntities(); + + public List getGrabbedItems(); +} + diff --git a/src/main/java/assemblyline/api/IArmbotUseable.java b/src/main/java/assemblyline/api/IArmbotUseable.java new file mode 100644 index 0000000..2b7e47c --- /dev/null +++ b/src/main/java/assemblyline/api/IArmbotUseable.java @@ -0,0 +1,8 @@ +package assemblyline.api; + +import assemblyline.api.IArmbot; + +public interface IArmbotUseable { + public boolean onUse(IArmbot var1, String[] var2); +} + diff --git a/src/main/java/assemblyline/api/IBelt.java b/src/main/java/assemblyline/api/IBelt.java new file mode 100644 index 0000000..211fd26 --- /dev/null +++ b/src/main/java/assemblyline/api/IBelt.java @@ -0,0 +1,11 @@ +package assemblyline.api; + +import java.util.List; +import net.minecraft.entity.Entity; + +public interface IBelt { + public List getAffectedEntities(); + + public void IgnoreEntity(Entity var1); +} + diff --git a/src/main/java/assemblyline/api/IBotArm.java b/src/main/java/assemblyline/api/IBotArm.java new file mode 100644 index 0000000..13b9550 --- /dev/null +++ b/src/main/java/assemblyline/api/IBotArm.java @@ -0,0 +1,5 @@ +package assemblyline.api; + +public interface IBotArm { +} + diff --git a/src/main/java/assemblyline/api/ICraneConnectable.java b/src/main/java/assemblyline/api/ICraneConnectable.java new file mode 100644 index 0000000..6463484 --- /dev/null +++ b/src/main/java/assemblyline/api/ICraneConnectable.java @@ -0,0 +1,8 @@ +package assemblyline.api; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface ICraneConnectable { + public boolean canFrameConnectTo(ForgeDirection var1); +} + diff --git a/src/main/java/assemblyline/api/ICraneStructure.java b/src/main/java/assemblyline/api/ICraneStructure.java new file mode 100644 index 0000000..3740496 --- /dev/null +++ b/src/main/java/assemblyline/api/ICraneStructure.java @@ -0,0 +1,8 @@ +package assemblyline.api; + +import assemblyline.api.ICraneConnectable; + +public interface ICraneStructure +extends ICraneConnectable { +} + diff --git a/src/main/java/assemblyline/api/IFilterable.java b/src/main/java/assemblyline/api/IFilterable.java new file mode 100644 index 0000000..3ec29fa --- /dev/null +++ b/src/main/java/assemblyline/api/IFilterable.java @@ -0,0 +1,10 @@ +package assemblyline.api; + +import net.minecraft.item.ItemStack; + +public interface IFilterable { + public void setFilter(ItemStack var1); + + public ItemStack getFilter(); +} + diff --git a/src/main/java/assemblyline/api/IManipulator.java b/src/main/java/assemblyline/api/IManipulator.java new file mode 100644 index 0000000..4419ab3 --- /dev/null +++ b/src/main/java/assemblyline/api/IManipulator.java @@ -0,0 +1,8 @@ +package assemblyline.api; + +public interface IManipulator { + public void eject(); + + public void inject(); +} + diff --git a/src/main/java/assemblyline/client/ClientProxy.java b/src/main/java/assemblyline/client/ClientProxy.java new file mode 100644 index 0000000..7434f9b --- /dev/null +++ b/src/main/java/assemblyline/client/ClientProxy.java @@ -0,0 +1,77 @@ +package assemblyline.client; + +import assemblyline.client.gui.GuiEncoder; +import assemblyline.client.gui.GuiImprinter; +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.client.render.RenderArmbot; +import assemblyline.client.render.RenderConveyorBelt; +import assemblyline.client.render.RenderCraneController; +import assemblyline.client.render.RenderCraneFrame; +import assemblyline.client.render.RenderCrate; +import assemblyline.client.render.RenderDetector; +import assemblyline.client.render.RenderManipulator; +import assemblyline.client.render.RenderRejector; +import assemblyline.common.CommonProxy; +import assemblyline.common.block.TileEntityCrate; +import assemblyline.common.machine.TileEntityManipulator; +import assemblyline.common.machine.TileEntityRejector; +import assemblyline.common.machine.armbot.TileEntityArmbot; +import assemblyline.common.machine.belt.TileEntityConveyorBelt; +import assemblyline.common.machine.crane.TileEntityCraneController; +import assemblyline.common.machine.crane.TileEntityCraneRail; +import assemblyline.common.machine.detector.TileEntityDetector; +import assemblyline.common.machine.encoder.TileEntityEncoder; +import assemblyline.common.machine.imprinter.TileEntityImprinter; +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; + +public class ClientProxy +extends CommonProxy { + @Override + public void preInit() { + RenderingRegistry.registerBlockHandler(new BlockRenderingHandler()); + } + + @Override + public void init() { + super.init(); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityConveyorBelt.class, (TileEntitySpecialRenderer)new RenderConveyorBelt()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRejector.class, (TileEntitySpecialRenderer)new RenderRejector()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityManipulator.class, (TileEntitySpecialRenderer)new RenderManipulator()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrate.class, (TileEntitySpecialRenderer)new RenderCrate()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityArmbot.class, (TileEntitySpecialRenderer)new RenderArmbot()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDetector.class, (TileEntitySpecialRenderer)new RenderDetector()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCraneController.class, (TileEntitySpecialRenderer)new RenderCraneController()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCraneRail.class, (TileEntitySpecialRenderer)new RenderCraneFrame()); + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null) { + switch (ID) { + case 1: { + return new GuiImprinter(player.inventory, (TileEntityImprinter)tileEntity); + } + case 2: { + if (tileEntity == null || !(tileEntity instanceof TileEntityEncoder)) break; + return new GuiEncoder(player.inventory, (TileEntityEncoder)tileEntity); + } + } + } + return null; + } + + @Override + public boolean isCtrKeyDown() { + return GuiScreen.isCtrlKeyDown(); + } +} + diff --git a/src/main/java/assemblyline/client/gui/GuiAutoCrafting.java b/src/main/java/assemblyline/client/gui/GuiAutoCrafting.java new file mode 100644 index 0000000..bd2ad49 --- /dev/null +++ b/src/main/java/assemblyline/client/gui/GuiAutoCrafting.java @@ -0,0 +1,34 @@ +package assemblyline.client.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerWorkbench; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; + +@SideOnly(value=Side.CLIENT) +public class GuiAutoCrafting +extends GuiContainer { + public GuiAutoCrafting(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5) { + super((Container)new ContainerWorkbench(par1InventoryPlayer, par2World, par3, par4, par5)); + } + + protected void drawGuiContainerForegroundLayer() { + this.fontRendererObj.drawString(StatCollector.translateToLocal((String)"AutoCrafter"), 28, 6, 0x404040); + this.fontRendererObj.drawString(StatCollector.translateToLocal((String)"container.inventory"), 8, this.ySize - 96 + 2, 0x404040); + } + + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.getTexture(new ResourceLocation("assemblyline", "textures/gui/gui_crafting.png")); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + int var5 = (this.width - this.xSize) / 2; + int var6 = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize); + } +} + diff --git a/src/main/java/assemblyline/client/gui/GuiButtonImage.java b/src/main/java/assemblyline/client/gui/GuiButtonImage.java new file mode 100644 index 0000000..22f7bd8 --- /dev/null +++ b/src/main/java/assemblyline/client/gui/GuiButtonImage.java @@ -0,0 +1,37 @@ +package assemblyline.client.gui; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +@SideOnly(value=Side.CLIENT) +@Deprecated +public class GuiButtonImage +extends GuiButton { + private int type = 0; + + public GuiButtonImage(int par1, int par2, int par3, int type) { + super(par1, par2, par3, 12, 12, ""); + this.type = type; + } + + @Override + public void drawButton(Minecraft par1Minecraft, int width, int hight) { + if (this.visible) { + par1Minecraft.getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/gui@.png")); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + boolean var4 = width >= this.xPosition && hight >= this.yPosition && width < this.xPosition + this.width && hight < this.yPosition + this.height; + int var5 = 106; + int var6 = 0; + if (var4) { + var5 += this.height; + } + this.drawTexturedModalRect(this.xPosition, this.yPosition, var6, var5, this.width, this.height); + } + } +} + diff --git a/src/main/java/assemblyline/client/gui/GuiCommandList.java b/src/main/java/assemblyline/client/gui/GuiCommandList.java new file mode 100644 index 0000000..428fadf --- /dev/null +++ b/src/main/java/assemblyline/client/gui/GuiCommandList.java @@ -0,0 +1,93 @@ +package assemblyline.client.gui; + +import cpw.mods.fml.client.GuiScrollingList; +import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import org.lwjgl.opengl.GL11; + +public class GuiCommandList +extends GuiScrollingList { + private ArrayList commands = new ArrayList(); + private int selIndex = -1; + private Minecraft mc; + + public GuiCommandList(Minecraft client, int width, int height, int top, int bottom, int left, int entryHeight) { + super(client, width, height, top, bottom, left, entryHeight); + this.mc = client; + } + + public void setCommands(ArrayList commands) { + this.commands = (ArrayList)commands.clone(); + } + + protected int getSize() { + return this.commands.size(); + } + + protected void elementClicked(int index, boolean doubleClick) { + this.selIndex = index; + } + + protected boolean isSelected(int index) { + return this.selIndex == index; + } + + protected void drawBackground() { + GuiCommandList.drawOutlineRect(this.left, this.left + this.listWidth, this.top, this.top + this.listHeight, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f); + } + + public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB) { + Tessellator tesselator = Tessellator.instance; + GL11.glEnable((int)3042); + GL11.glDisable((int)3553); + GL11.glBlendFunc((int)770, (int)771); + GL11.glColor4f((float)rR, (float)rG, (float)rB, (float)1.0f); + if (rR > 0.0f && rG > 0.0f && rB > 0.0f) { + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.draw(); + } + GL11.glColor4f((float)lR, (float)lG, (float)lB, (float)1.0f); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x1 + 1.0, (double)y2, 0.0); + tesselator.addVertex((double)x1 + 1.0, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x2 - 1.0, (double)y1, 0.0); + tesselator.addVertex((double)x2 - 1.0, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y1 + 1.0, 0.0); + tesselator.addVertex((double)x2, (double)y1 + 1.0, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y2 - 1.0, 0.0); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2 - 1.0, 0.0); + tesselator.draw(); + GL11.glEnable((int)3553); + GL11.glDisable((int)3042); + } + + protected void drawSlot(int slotID, int width, int slotY, int slotHeight, Tessellator tessellator) { + if (slotID < this.commands.size()) { + String command = (String)this.commands.get(slotID); + if (this.isSelected(slotID)) { + GuiCommandList.drawOutlineRect(this.left, this.left + width, this.top + slotY, this.top + slotY + slotHeight, -1.0f, -1.0f, -1.0f, 0.5f, 0.5f, 0.5f); + } + this.mc.fontRenderer.drawString(command, this.left + 4, slotY + 4, 0xAAAAAA, false); + } + } +} + diff --git a/src/main/java/assemblyline/client/gui/GuiEncoder.java b/src/main/java/assemblyline/client/gui/GuiEncoder.java new file mode 100644 index 0000000..10b86cb --- /dev/null +++ b/src/main/java/assemblyline/client/gui/GuiEncoder.java @@ -0,0 +1,305 @@ +package assemblyline.client.gui; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.encoder.ContainerEncoder; +import assemblyline.common.machine.encoder.IInventoryWatcher; +import assemblyline.common.machine.encoder.ItemDisk; +import assemblyline.common.machine.encoder.TileEntityEncoder; +import assemblyline.common.network.MessageEncoder; + +import java.util.ArrayList; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.GL11; + +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.TranslationHelper; + +public class GuiEncoder +extends GuiContainer +implements IInventoryWatcher { + private static final int MAX_COMMANDS = 6; + private int containerWidth; + private int containerHeight; + private TileEntityEncoder tileEntity; + private ArrayList commands; + private int minCommand; + private int selCommand; + private GuiButton addButton; + private GuiButton delButton; + private GuiButton pUpButton; + private GuiButton pDnButton; + private GuiTextField commandField; + + public GuiEncoder(InventoryPlayer playerInventory, TileEntityEncoder tileEntity) { + super((Container)new ContainerEncoder(playerInventory, tileEntity)); + this.ySize = 237; + this.tileEntity = tileEntity; + tileEntity.setWatcher(this); + } + + public void initGui() { + super.initGui(); + this.allowUserInput = true; + Keyboard.enableRepeatEvents((boolean)true); + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.addButton = new GuiButton(0, this.containerWidth + (this.xSize - 25), this.containerHeight + 128 + 0, 18, 20, "+"); + this.delButton = new GuiButton(1, this.containerWidth + (this.xSize - 43), this.containerHeight + 128 + 0, 18, 20, "-"); + this.pUpButton = new GuiButton(2, this.containerWidth + (this.xSize - 25), this.containerHeight + 46 + 0, 18, 20, ""); + this.pDnButton = new GuiButton(3, this.containerWidth + (this.xSize - 25), this.containerHeight + 106 + 0, 18, 20, ""); + this.commandField = new GuiTextField(this.fontRendererObj, 8, 129, this.xSize - 52, 18); + this.buttonList.add(this.addButton); + this.buttonList.add(this.delButton); + this.buttonList.add(this.pUpButton); + this.buttonList.add(this.pDnButton); + this.commands = new ArrayList(); + this.minCommand = 0; + this.selCommand = -1; + } + + @Override + protected void actionPerformed(GuiButton button) { + switch (button.id) { + case 0: { + ItemStack disk; + if (this.commandField.getText().equals("")) break; + if (this.tileEntity != null && (disk = this.tileEntity.getStackInSlot(0)) != null) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setBoolean("create", true); + nbt.setString("newCommand", this.commandField.getText()); + AssemblyLine.NETWORK.sendToServer(new MessageEncoder(new Vector3(this.tileEntity), nbt)); + } + this.minCommand = this.commands.size() - 6 + 1; + if (this.minCommand < 0) { + this.minCommand = 0; + } + this.selCommand = -1; + this.commandField.setText(""); + break; + } + case 1: { + if (this.tileEntity == null) break; + ItemStack disk = this.tileEntity.getStackInSlot(0); + if (disk != null && this.selCommand >= 0 && this.selCommand < this.commands.size()) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setBoolean("create", false); + nbt.setInteger("commandToRemove", this.selCommand); + AssemblyLine.NETWORK.sendToServer(new MessageEncoder(new Vector3(this.tileEntity), nbt)); + } + this.selCommand = -1; + break; + } + case 2: { + if (this.minCommand <= 0) break; + --this.minCommand; + break; + } + case 3: { + if (this.minCommand + 6 >= this.commands.size()) break; + ++this.minCommand; + } + } + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + GL11.glDisable((int)2896); + this.fontRendererObj.drawString(TranslationHelper.getLocal("tile.encoder.name"), 68, 8, 0x404040); + this.fontRendererObj.drawString("Disk:", 56, 28, 0x404040); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(this.pUpButton.xPosition - this.containerWidth + 6), (float)(this.pUpButton.yPosition - this.containerHeight + 7), (float)0.0f); + this.fontRendererObj.drawString("^", 1, 1, 0x444444); + this.fontRendererObj.drawString("^", 0, 0, 0xFFFFFF); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(this.pDnButton.xPosition - this.containerWidth + 6), (float)(this.pDnButton.yPosition - this.containerHeight + 7), (float)0.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glTranslatef((float)-5.0f, (float)-4.0f, (float)0.0f); + this.fontRendererObj.drawString("^", -1, -1, 0x444444); + this.fontRendererObj.drawString("^", 0, 0, 0xFFFFFF); + GL11.glPopMatrix(); + if (this.commands != null) { + this.drawCommands(); + } + this.commandField.drawTextBox(); + } + + private void drawCommands() { + for (int i = this.minCommand; i < this.minCommand + 6; ++i) { + if (i < 0 || i >= this.commands.size()) continue; + int relativeCommand = i - this.minCommand; + String command = ((String)this.commands.get(i)).toUpperCase(); + this.drawCommand(command, 8, 47 + relativeCommand * (this.fontRendererObj.FONT_HEIGHT + 4), this.selCommand == i); + } + } + + private void drawCommand(String command, int x, int y, boolean selected) { + if (selected) { + GuiEncoder.drawOutlineRect(x, y, x + 142, y + this.fontRendererObj.FONT_HEIGHT + 4, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); + } + this.fontRendererObj.drawString(command, x + 3, y + this.fontRendererObj.FONT_HEIGHT / 2 - 1, 0xFFFFFF, false); + } + + @Override + protected void mouseClicked(int x, int y, int button) { + super.mouseClicked(x, y, button); + this.commandField.mouseClicked(x - this.containerWidth, y - this.containerHeight, button); + if (button == 0) { + if (x >= this.containerWidth + 8) { + if (y >= this.containerHeight + 47 + 0) { + if (x <= this.containerWidth + (this.xSize - 25)) { + if (y <= this.containerHeight + 46 + 80 + 0) { + this.listClicked(x - (this.containerWidth + 8), y - (this.containerHeight + 47 + 0)); + } else { + this.selCommand = -1; + } + } else { + this.selCommand = -1; + } + } else { + this.selCommand = -1; + } + } else { + this.selCommand = -1; + } + } + } + + private void listClicked(int relativeX, int relativeY) { + int itemClicked = relativeY / 13; + this.selCommand = itemClicked + this.minCommand; + } + + @Override + protected void keyTyped(char character, int keycode) { + if (character != 'e' && character != 'E') { + super.keyTyped(character, keycode); + } + this.commandField.textboxKeyTyped(character, keycode); + if (keycode == 1) { + this.mc.thePlayer.closeScreen(); + } else if (keycode == 28) { + if (this.commandField.isFocused()) { + this.actionPerformed(this.addButton); + } + } else if (keycode == 211) { + this.actionPerformed(this.delButton); + } else if (keycode == 201) { + this.actionPerformed(this.pUpButton); + } else if (keycode == 209) { + this.actionPerformed(this.pDnButton); + } else if (keycode == 200) { + --this.selCommand; + if (this.selCommand < -1) { + this.selCommand = this.commands.size() - 1; + } + if (this.selCommand < this.minCommand && this.selCommand >= 0) { + this.minCommand = this.selCommand; + } + if (this.selCommand >= this.minCommand + 6 && this.selCommand < this.commands.size()) { + this.minCommand = this.selCommand - 6 + 1; + } + } else if (keycode == 208) { + ++this.selCommand; + if (this.selCommand >= this.commands.size()) { + this.selCommand = -1; + } + if (this.selCommand >= this.minCommand + 6 && this.selCommand < this.commands.size()) { + this.minCommand = this.selCommand - 6 + 1; + } + if (this.selCommand < this.minCommand && this.selCommand >= 0) { + this.minCommand = this.selCommand; + } + } + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.bindTexture(new ResourceLocation("assemblyline", "textures/gui/gui_encoder.png")); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + this.drawTexturedModalRect(this.containerWidth, this.containerHeight + 0, 0, 0, this.xSize, this.ySize); + GuiEncoder.drawOutlineRect(this.containerWidth + 7, this.containerHeight + 46 + 0, this.containerWidth + (this.xSize - 25), this.containerHeight + 46 + 80 + 0, 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f); + } + + public static void drawOutlineRect(int x1, int y1, int x2, int y2, float rR, float rG, float rB, float lR, float lG, float lB) { + Tessellator tesselator = Tessellator.instance; + GL11.glEnable((int)3042); + GL11.glDisable((int)3553); + GL11.glBlendFunc((int)770, (int)771); + GL11.glColor4f((float)rR, (float)rG, (float)rB, (float)1.0f); + if (rR >= 0.0f && rG >= 0.0f && rB >= 0.0f) { + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.draw(); + } + GL11.glColor4f((float)lR, (float)lG, (float)lB, (float)1.0f); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x1 + 1.0, (double)y2, 0.0); + tesselator.addVertex((double)x1 + 1.0, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x2 - 1.0, (double)y1, 0.0); + tesselator.addVertex((double)x2 - 1.0, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y1, 0.0); + tesselator.addVertex((double)x1, (double)y1 + 1.0, 0.0); + tesselator.addVertex((double)x2, (double)y1 + 1.0, 0.0); + tesselator.addVertex((double)x2, (double)y1, 0.0); + tesselator.draw(); + tesselator.startDrawingQuads(); + tesselator.addVertex((double)x1, (double)y2 - 1.0, 0.0); + tesselator.addVertex((double)x1, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2, 0.0); + tesselator.addVertex((double)x2, (double)y2 - 1.0, 0.0); + tesselator.draw(); + GL11.glEnable((int)3553); + GL11.glDisable((int)3042); + } + + private void updateCommands() { + if (this.commands != null) { + ItemStack disk; + this.commands.clear(); + if (this.tileEntity != null && (disk = this.tileEntity.getStackInSlot(0)) != null) { + this.commands = ItemDisk.getCommands(disk); + } + if (this.minCommand + 6 >= this.commands.size()) { + this.minCommand = this.commands.size() - 6; + } + if (this.minCommand < 0) { + this.minCommand = 0; + } + } + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + Keyboard.enableRepeatEvents((boolean)false); + } + + @Override + public void inventoryChanged() { + this.updateCommands(); + } +} + diff --git a/src/main/java/assemblyline/client/gui/GuiImprinter.java b/src/main/java/assemblyline/client/gui/GuiImprinter.java new file mode 100644 index 0000000..007af89 --- /dev/null +++ b/src/main/java/assemblyline/client/gui/GuiImprinter.java @@ -0,0 +1,41 @@ +package assemblyline.client.gui; + +import assemblyline.common.machine.imprinter.ContainerImprinter; +import assemblyline.common.machine.imprinter.TileEntityImprinter; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import universalelectricity.prefab.TranslationHelper; + +public class GuiImprinter +extends GuiContainer { + private int containerWidth; + private int containerHeight; + private TileEntityImprinter tileEntity; + + public GuiImprinter(InventoryPlayer par1InventoryPlayer, TileEntityImprinter tileEntity) { + super((Container)new ContainerImprinter(par1InventoryPlayer, tileEntity)); + this.tileEntity = tileEntity; + this.ySize = 201; + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + this.fontRendererObj.drawString("Use Inventories:", 70, 58, 0x404040); + this.fontRendererObj.drawString("" + this.tileEntity.searchInventories, 105, 67, 0x404040); + this.fontRendererObj.drawString(TranslationHelper.getLocal("tile.imprinter.name"), 68, 6, 0x404040); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { + this.mc.renderEngine.bindTexture(new ResourceLocation("assemblyline", "textures/gui/gui_imprinter.png")); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + this.containerWidth = (this.width - this.xSize) / 2; + this.containerHeight = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(this.containerWidth, this.containerHeight, 0, 0, this.xSize, this.ySize); + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelAngledBelt.java b/src/main/java/assemblyline/client/model/ModelAngledBelt.java new file mode 100644 index 0000000..b613c45 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelAngledBelt.java @@ -0,0 +1,68 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelAngledBelt +extends ModelBase { + ModelRenderer MRoller1; + ModelRenderer bBELT; + ModelRenderer MRoller2; + ModelRenderer tBELT; + ModelRenderer MRoller3; + + public ModelAngledBelt() { + this.textureWidth = 128; + this.textureHeight = 128; + this.MRoller1 = new ModelRenderer((ModelBase)this, 0, 26); + this.MRoller1.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.MRoller1.setRotationPoint(0.0f, 14.0f, 0.0f); + this.MRoller1.setTextureSize(128, 128); + this.MRoller1.mirror = true; + this.setRotation(this.MRoller1, 0.7853982f, 0.0f, 0.0f); + this.bBELT = new ModelRenderer((ModelBase)this, 0, 0); + this.bBELT.addBox(0.0f, 0.0f, 0.0f, 14, 1, 23); + this.bBELT.setRotationPoint(-7.0f, 23.5f, -8.0f); + this.bBELT.setTextureSize(128, 128); + this.bBELT.mirror = true; + this.setRotation(this.bBELT, 0.7853982f, 0.0f, 0.0f); + this.MRoller2 = new ModelRenderer((ModelBase)this, 0, 26); + this.MRoller2.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.MRoller2.setRotationPoint(0.0f, 9.0f, 5.0f); + this.MRoller2.setTextureSize(128, 128); + this.MRoller2.mirror = true; + this.setRotation(this.MRoller2, 0.7853982f, 0.0f, 0.0f); + this.tBELT = new ModelRenderer((ModelBase)this, 0, 0); + this.tBELT.addBox(0.0f, 0.0f, 0.0f, 14, 1, 23); + this.tBELT.setRotationPoint(-7.0f, 19.0f, -8.0f); + this.tBELT.setTextureSize(128, 128); + this.tBELT.mirror = true; + this.setRotation(this.tBELT, 0.7853982f, 0.0f, 0.0f); + this.MRoller3 = new ModelRenderer((ModelBase)this, 0, 26); + this.MRoller3.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.MRoller3.setRotationPoint(0.0f, 19.0f, -5.0f); + this.MRoller3.setTextureSize(128, 128); + this.MRoller3.mirror = true; + this.setRotation(this.MRoller3, 0.7853982f, 0.0f, 0.0f); + } + + public void render(float f5, boolean slantAdjust) { + if (slantAdjust) { + this.bBELT.setRotationPoint(-7.0f, 21.5f, -7.0f); + } else { + this.bBELT.setRotationPoint(-7.0f, 23.5f, -8.0f); + } + this.MRoller1.render(f5); + this.bBELT.render(f5); + this.MRoller2.render(f5); + this.tBELT.render(f5); + this.MRoller3.render(f5); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelArmbot.java b/src/main/java/assemblyline/client/model/ModelArmbot.java new file mode 100644 index 0000000..b56cdbc --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelArmbot.java @@ -0,0 +1,154 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; +import org.lwjgl.opengl.GL11; + +public class ModelArmbot +extends ModelBase { + ModelRenderer baseTop; + ModelRenderer base; + ModelRenderer armMountRight; + ModelRenderer armMountLeft; + ModelRenderer armLower; + ModelRenderer armLower2; + ModelRenderer armLower3; + ModelRenderer armUpper; + ModelRenderer baseRotation; + ModelRenderer clampBody; + ModelRenderer clampBody2; + ModelRenderer clampClawLower; + ModelRenderer clampClawLower2; + ModelRenderer clampClawLower3; + + public ModelArmbot() { + this.textureWidth = 128; + this.textureHeight = 128; + this.baseTop = new ModelRenderer((ModelBase)this, 0, 94); + this.baseTop.addBox(-6.0f, 0.0f, -6.0f, 12, 3, 12); + this.baseTop.setRotationPoint(0.0f, 18.0f, 0.0f); + this.baseTop.setTextureSize(64, 32); + this.baseTop.mirror = true; + this.setRotation(this.baseTop, 0.0f, 0.0f, 0.0f); + this.base = new ModelRenderer((ModelBase)this, 0, 109); + this.base.addBox(-8.0f, 0.0f, -8.0f, 16, 3, 16); + this.base.setRotationPoint(0.0f, 21.0f, 0.0f); + this.base.setTextureSize(64, 32); + this.base.mirror = true; + this.setRotation(this.base, 0.0f, 0.0f, 0.0f); + this.armMountRight = new ModelRenderer((ModelBase)this, 24, 85); + this.armMountRight.addBox(-3.8f, -5.0f, -2.0f, 4, 5, 4); + this.armMountRight.setRotationPoint(0.0f, 17.0f, 0.0f); + this.armMountRight.setTextureSize(128, 128); + this.armMountRight.mirror = true; + this.setRotation(this.armMountRight, 0.0f, 0.0f, 0.0f); + this.armMountLeft = new ModelRenderer((ModelBase)this, 0, 85); + this.armMountLeft.addBox(2.0f, -5.0f, -2.0f, 2, 5, 4); + this.armMountLeft.setRotationPoint(0.0f, 17.0f, 0.0f); + this.armMountLeft.setTextureSize(64, 32); + this.armMountLeft.mirror = true; + this.setRotation(this.armMountLeft, 0.0f, 0.0f, 0.0f); + this.armLower = new ModelRenderer((ModelBase)this, 116, 0); + this.armLower.addBox(0.3f, -15.0f, -1.5f, 2, 16, 4); + this.armLower.setRotationPoint(0.0f, 14.0f, 0.0f); + this.armLower.setTextureSize(64, 32); + this.armLower.mirror = true; + this.setRotation(this.armLower, 0.5235988f, 0.0f, 0.0f); + this.armLower2 = new ModelRenderer((ModelBase)this, 104, 0); + this.armLower2.addBox(-2.3f, -15.0f, -1.5f, 2, 16, 4); + this.armLower2.setRotationPoint(0.0f, 14.0f, 0.0f); + this.armLower2.setTextureSize(64, 32); + this.armLower2.mirror = true; + this.setRotation(this.armLower2, 0.5235988f, 0.0f, 0.0f); + this.armLower3 = new ModelRenderer((ModelBase)this, 92, 0); + this.armLower3.addBox(-1.0f, -14.0f, -2.0f, 2, 14, 4); + this.armLower3.setRotationPoint(0.0f, 14.0f, 0.0f); + this.armLower3.setTextureSize(64, 32); + this.armLower3.mirror = true; + this.setRotation(this.armLower3, 0.5235988f, 0.0f, 0.0f); + this.armUpper = new ModelRenderer((ModelBase)this, 0, 70); + this.armUpper.addBox(-1.0f, -10.0f, -1.5f, 2, 12, 3); + this.armUpper.setRotationPoint(0.0f, 2.0f, -7.0f); + this.armUpper.setTextureSize(64, 32); + this.armUpper.mirror = true; + this.setRotation(this.armUpper, 2.513274f, 0.0f, 0.0f); + this.baseRotation = new ModelRenderer((ModelBase)this, 0, 60); + this.baseRotation.addBox(-4.5f, 0.0f, -4.5f, 9, 1, 9); + this.baseRotation.setRotationPoint(0.0f, 17.0f, 0.0f); + this.baseRotation.setTextureSize(64, 32); + this.baseRotation.mirror = true; + this.setRotation(this.baseRotation, 0.0f, 0.0f, 0.0f); + this.clampBody = new ModelRenderer((ModelBase)this, 0, 7); + this.clampBody.addBox(-1.5f, -12.0f, -2.5f, 3, 2, 5); + this.clampBody.setRotationPoint(0.0f, 2.0f, -7.0f); + this.clampBody.setTextureSize(64, 32); + this.clampBody.mirror = true; + this.setRotation(this.clampBody, 2.513274f, 0.0f, 0.0f); + this.clampBody2 = new ModelRenderer((ModelBase)this, 0, 56); + this.clampBody2.addBox(-1.0f, -14.0f, -1.0f, 2, 2, 2); + this.clampBody2.setRotationPoint(0.0f, 2.0f, -7.0f); + this.clampBody2.setTextureSize(64, 32); + this.clampBody2.mirror = true; + this.setRotation(this.clampBody2, 2.513274f, 0.0f, 0.0f); + this.clampClawLower = new ModelRenderer((ModelBase)this, 0, 25); + this.clampClawLower.addBox(-1.0f, -4.0f, -1.0f, 2, 5, 1); + this.clampClawLower.setRotationPoint(0.0f, 13.0f, -15.0f); + this.clampClawLower.setTextureSize(64, 32); + this.clampClawLower.mirror = true; + this.setRotation(this.clampClawLower, 2.9147f, 0.0f, 0.0f); + this.clampClawLower2 = new ModelRenderer((ModelBase)this, 0, 31); + this.clampClawLower2.addBox(-1.2f, -3.5f, 0.0f, 1, 6, 1); + this.clampClawLower2.setRotationPoint(0.0f, 14.0f, -16.0f); + this.clampClawLower2.setTextureSize(64, 32); + this.clampClawLower2.mirror = true; + this.setRotation(this.clampClawLower2, 2.897247f, 0.0f, 0.0f); + this.clampClawLower3 = new ModelRenderer((ModelBase)this, 0, 0); + this.clampClawLower3.addBox(0.2f, -3.5f, 0.0f, 1, 6, 1); + this.clampClawLower3.setRotationPoint(0.0f, 14.0f, -16.0f); + this.clampClawLower3.setTextureSize(64, 32); + this.clampClawLower3.mirror = true; + this.setRotation(this.clampClawLower3, 2.897247f, 0.0f, 0.0f); + } + + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + super.render(entity, f, f1, f2, f3, f4, f5); + this.setRotationAngles(f, f1, f2, f3, f4, f5, entity); + this.render(f5, entity.rotationYaw, entity.rotationPitch); + } + + public void render(float f5, float rotationYaw, float rotationPitch) { + this.baseTop.render(f5); + this.base.render(f5); + GL11.glPushMatrix(); + GL11.glRotatef((float)rotationYaw, (float)0.0f, (float)1.0f, (float)0.0f); + this.armMountRight.render(f5); + this.armMountLeft.render(f5); + this.baseRotation.render(f5); + GL11.glPopMatrix(); + GL11.glPushMatrix(); + GL11.glRotatef((float)rotationYaw, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glTranslatef((float)0.0f, (float)0.9f, (float)0.0f); + GL11.glRotatef((float)(-rotationPitch), (float)1.0f, (float)0.0f, (float)0.0f); + GL11.glTranslatef((float)0.0f, (float)-0.9f, (float)0.0f); + this.armLower.render(f5); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.0f, (float)0.1f, (float)-0.35f); + GL11.glRotatef((float)(-rotationPitch), (float)1.0f, (float)0.0f, (float)0.0f); + GL11.glTranslatef((float)0.0f, (float)-0.05f, (float)0.35f); + this.armUpper.render(f5); + this.clampBody.render(f5); + this.clampBody2.render(f5); + this.clampClawLower.render(f5); + this.clampClawLower2.render(f5); + GL11.glPopMatrix(); + GL11.glPopMatrix(); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelConveyorBelt.java b/src/main/java/assemblyline/client/model/ModelConveyorBelt.java new file mode 100644 index 0000000..70bc65d --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelConveyorBelt.java @@ -0,0 +1,217 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelConveyorBelt +extends ModelBase { + ModelRenderer bBELTLong; + ModelRenderer FBELT; + ModelRenderer BacBELT; + ModelRenderer BBelt; + ModelRenderer FRL; + ModelRenderer MRL; + ModelRenderer FLL; + ModelRenderer BLL; + ModelRenderer MRoller; + ModelRenderer BRoller; + ModelRenderer tBELT; + ModelRenderer FRoller; + ModelRenderer BRL; + ModelRenderer BML; + ModelRenderer tBELTLong; + ModelRenderer tBELT15; + ModelRenderer bBELT15; + ModelRenderer c4; + ModelRenderer c3; + ModelRenderer c2; + ModelRenderer c1; + + public ModelConveyorBelt() { + this.textureWidth = 128; + this.textureHeight = 128; + this.bBELTLong = new ModelRenderer((ModelBase)this, 0, 66); + this.bBELTLong.addBox(0.0f, 0.0f, 0.0f, 14, 1, 16); + this.bBELTLong.setRotationPoint(-7.0f, 22.0f, -8.0f); + this.bBELTLong.setTextureSize(128, 128); + this.bBELTLong.mirror = true; + this.setRotation(this.bBELTLong, 0.0f, 0.0f, 0.0f); + this.FBELT = new ModelRenderer((ModelBase)this, 0, 16); + this.FBELT.addBox(0.0f, 0.0f, 0.0f, 14, 2, 1); + this.FBELT.setRotationPoint(-7.0f, 20.0f, -8.0f); + this.FBELT.setTextureSize(128, 128); + this.FBELT.mirror = true; + this.setRotation(this.FBELT, 0.0f, 0.0f, 0.0f); + this.BacBELT = new ModelRenderer((ModelBase)this, 0, 16); + this.BacBELT.addBox(0.0f, 0.0f, 0.0f, 14, 2, 1); + this.BacBELT.setRotationPoint(-7.0f, 20.0f, 7.0f); + this.BacBELT.setTextureSize(128, 128); + this.BacBELT.mirror = true; + this.setRotation(this.BacBELT, 0.0f, 0.0f, 0.0f); + this.BBelt = new ModelRenderer((ModelBase)this, 0, 31); + this.BBelt.addBox(0.0f, 0.0f, 0.0f, 14, 1, 14); + this.BBelt.setRotationPoint(-7.0f, 22.0f, -7.0f); + this.BBelt.setTextureSize(128, 128); + this.BBelt.mirror = true; + this.setRotation(this.BBelt, 0.0f, 0.0f, 0.0f); + this.FRL = new ModelRenderer((ModelBase)this, 0, 20); + this.FRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.FRL.setRotationPoint(-8.0f, 21.0f, -6.0f); + this.FRL.setTextureSize(128, 128); + this.FRL.mirror = true; + this.setRotation(this.FRL, 0.0f, 0.0f, 0.0f); + this.MRL = new ModelRenderer((ModelBase)this, 0, 20); + this.MRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.MRL.setRotationPoint(-8.0f, 21.0f, -1.0f); + this.MRL.setTextureSize(128, 128); + this.MRL.mirror = true; + this.setRotation(this.MRL, 0.0f, 0.0f, 0.0f); + this.FLL = new ModelRenderer((ModelBase)this, 0, 20); + this.FLL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.FLL.setRotationPoint(7.0f, 21.0f, -6.0f); + this.FLL.setTextureSize(128, 128); + this.FLL.mirror = true; + this.setRotation(this.FLL, 0.0f, 0.0f, 0.0f); + this.BLL = new ModelRenderer((ModelBase)this, 0, 20); + this.BLL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BLL.setRotationPoint(7.0f, 21.0f, 4.0f); + this.BLL.setTextureSize(128, 128); + this.BLL.mirror = true; + this.setRotation(this.BLL, 0.0f, 0.0f, 0.0f); + this.MRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.MRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.MRoller.setRotationPoint(0.0f, 21.0f, 0.0f); + this.MRoller.setTextureSize(128, 128); + this.MRoller.mirror = true; + this.setRotation(this.MRoller, 0.0f, 0.0f, 0.0f); + this.BRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.BRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.BRoller.setRotationPoint(0.0f, 21.0f, 5.0f); + this.BRoller.setTextureSize(128, 128); + this.BRoller.mirror = true; + this.setRotation(this.BRoller, 0.0f, 0.0f, 0.0f); + this.tBELT = new ModelRenderer((ModelBase)this, 0, 0); + this.tBELT.addBox(0.0f, 0.0f, 0.0f, 14, 1, 14); + this.tBELT.setRotationPoint(-7.0f, 19.0f, -7.0f); + this.tBELT.setTextureSize(128, 128); + this.tBELT.mirror = true; + this.setRotation(this.tBELT, 0.0f, 0.0f, 0.0f); + this.FRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.FRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.FRoller.setRotationPoint(0.0f, 21.0f, -5.0f); + this.FRoller.setTextureSize(128, 128); + this.FRoller.mirror = true; + this.setRotation(this.FRoller, 0.0f, 0.0f, 0.0f); + this.BRL = new ModelRenderer((ModelBase)this, 0, 20); + this.BRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BRL.setRotationPoint(-8.0f, 21.0f, 4.0f); + this.BRL.setTextureSize(128, 128); + this.BRL.mirror = true; + this.setRotation(this.BRL, 0.0f, 0.0f, 0.0f); + this.BML = new ModelRenderer((ModelBase)this, 0, 20); + this.BML.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BML.setRotationPoint(7.0f, 21.0f, -1.0f); + this.BML.setTextureSize(128, 128); + this.BML.mirror = true; + this.setRotation(this.BML, 0.0f, 0.0f, 0.0f); + this.tBELTLong = new ModelRenderer((ModelBase)this, 0, 48); + this.tBELTLong.addBox(0.0f, 0.0f, 0.0f, 14, 1, 16); + this.tBELTLong.setRotationPoint(-7.0f, 19.0f, -8.0f); + this.tBELTLong.setTextureSize(128, 128); + this.tBELTLong.mirror = true; + this.setRotation(this.tBELTLong, 0.0f, 0.0f, 0.0f); + this.tBELT15 = new ModelRenderer((ModelBase)this, 0, 84); + this.tBELT15.addBox(0.0f, 0.0f, 0.0f, 14, 1, 15); + this.tBELT15.setRotationPoint(-7.0f, 19.0f, -8.0f); + this.tBELT15.setTextureSize(128, 128); + this.tBELT15.mirror = true; + this.setRotation(this.tBELT15, 0.0f, 0.0f, 0.0f); + this.bBELT15 = new ModelRenderer((ModelBase)this, 0, 84); + this.bBELT15.addBox(0.0f, 0.0f, 0.0f, 14, 1, 15); + this.bBELT15.setRotationPoint(-7.0f, 22.0f, -8.0f); + this.bBELT15.setTextureSize(128, 128); + this.bBELT15.mirror = true; + this.setRotation(this.bBELT15, 0.0f, 0.0f, 0.0f); + this.c4 = new ModelRenderer((ModelBase)this, 60, 20); + this.c4.addBox(0.0f, 0.0f, 0.0f, 1, 16, 1); + this.c4.setRotationPoint(7.0f, 8.0f, 7.0f); + this.c4.setTextureSize(128, 128); + this.c4.mirror = true; + this.setRotation(this.c4, 0.0f, 0.0f, 0.0f); + this.c3 = new ModelRenderer((ModelBase)this, 60, 20); + this.c3.addBox(0.0f, 0.0f, 0.0f, 1, 16, 1); + this.c3.setRotationPoint(7.0f, 8.0f, -8.0f); + this.c3.setTextureSize(128, 128); + this.c3.mirror = true; + this.setRotation(this.c3, 0.0f, 0.0f, 0.0f); + this.c2 = new ModelRenderer((ModelBase)this, 60, 20); + this.c2.addBox(0.0f, 0.0f, 0.0f, 1, 16, 1); + this.c2.setRotationPoint(-8.0f, 8.0f, 7.0f); + this.c2.setTextureSize(128, 128); + this.c2.mirror = true; + this.setRotation(this.c2, 0.0f, 0.0f, 0.0f); + this.c1 = new ModelRenderer((ModelBase)this, 60, 20); + this.c1.addBox(0.0f, 0.0f, 0.0f, 1, 16, 1); + this.c1.setRotationPoint(-8.0f, 8.0f, -8.0f); + this.c1.setTextureSize(128, 128); + this.c1.mirror = true; + this.setRotation(this.c1, 0.0f, 0.0f, 0.0f); + } + + public void render(float f5, float radians, boolean front, boolean back, boolean above, boolean legs) { + boolean rightCap; + boolean mid = front && back; + boolean leftCap = !front && back; + boolean bl = rightCap = front && !back; + if (back || front) { + if (leftCap) { + this.FBELT.render(f5); + this.tBELT15.setRotationPoint(-7.0f, 19.0f, -7.0f); + this.bBELT15.setRotationPoint(-7.0f, 22.0f, -7.0f); + this.tBELT15.render(f5); + this.bBELT15.render(f5); + } else if (rightCap) { + this.BacBELT.render(f5); + this.tBELT15.setRotationPoint(-7.0f, 19.0f, -8.0f); + this.bBELT15.setRotationPoint(-7.0f, 22.0f, -8.0f); + this.tBELT15.render(f5); + this.bBELT15.render(f5); + } else { + this.bBELTLong.render(f5); + this.tBELTLong.render(f5); + } + } else { + this.FBELT.render(f5); + this.BacBELT.render(f5); + this.BBelt.render(f5); + this.tBELT.render(f5); + } + if (above) { + this.c1.render(f5); + this.c2.render(f5); + this.c3.render(f5); + this.c4.render(f5); + } + this.MRoller.rotateAngleX = radians; + this.BRoller.rotateAngleX = radians; + this.FRoller.rotateAngleX = radians; + this.MRoller.render(f5); + this.BRoller.render(f5); + this.FRoller.render(f5); + if (legs) { + this.BRL.render(f5); + this.BML.render(f5); + this.FLL.render(f5); + this.BLL.render(f5); + this.FRL.render(f5); + this.MRL.render(f5); + } + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelCraneArmMount.java b/src/main/java/assemblyline/client/model/ModelCraneArmMount.java new file mode 100644 index 0000000..f7dded1 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelCraneArmMount.java @@ -0,0 +1,87 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelCraneArmMount +extends ModelBase { + private ModelRenderer RailGuard1; + private ModelRenderer ArmMount; + private ModelRenderer RailGuard2; + private ModelRenderer Base; + private ModelRenderer WheelMount1; + private ModelRenderer Wheel2; + private ModelRenderer WheelMount2; + private ModelRenderer Wheel1; + + public ModelCraneArmMount() { + this.textureWidth = 64; + this.textureHeight = 64; + this.RailGuard1 = new ModelRenderer((ModelBase)this, 0, 20); + this.RailGuard1.addBox(0.0f, 0.0f, 0.0f, 16, 8, 2); + this.RailGuard1.setRotationPoint(-8.0f, 12.0f, 4.0f); + this.RailGuard1.setTextureSize(64, 32); + this.RailGuard1.mirror = true; + this.setRotation(this.RailGuard1, 0.0f, 0.0f, 0.0f); + this.ArmMount = new ModelRenderer((ModelBase)this, 36, 26); + this.ArmMount.addBox(0.0f, 0.0f, 0.0f, 8, 4, 2); + this.ArmMount.setRotationPoint(-4.0f, 4.0f, -8.0f); + this.ArmMount.setTextureSize(64, 32); + this.ArmMount.mirror = true; + this.setRotation(this.ArmMount, 0.0f, 0.0f, 0.0f); + this.RailGuard2 = new ModelRenderer((ModelBase)this, 0, 20); + this.RailGuard2.addBox(0.0f, 0.0f, 0.0f, 16, 8, 2); + this.RailGuard2.setRotationPoint(-8.0f, 12.0f, -6.0f); + this.RailGuard2.setTextureSize(64, 32); + this.RailGuard2.mirror = true; + this.setRotation(this.RailGuard2, 0.0f, 0.0f, 0.0f); + this.Base = new ModelRenderer((ModelBase)this, 0, 0); + this.Base.addBox(0.0f, 0.0f, 0.0f, 16, 4, 16); + this.Base.setRotationPoint(-8.0f, 8.0f, -8.0f); + this.Base.setTextureSize(64, 32); + this.Base.mirror = true; + this.setRotation(this.Base, 0.0f, 0.0f, 0.0f); + this.WheelMount1 = new ModelRenderer((ModelBase)this, 0, 30); + this.WheelMount1.addBox(0.0f, 0.0f, 0.0f, 14, 4, 4); + this.WheelMount1.setRotationPoint(-7.0f, 4.0f, 2.0f); + this.WheelMount1.setTextureSize(64, 32); + this.WheelMount1.mirror = true; + this.setRotation(this.WheelMount1, 0.0f, 0.0f, 0.0f); + this.Wheel2 = new ModelRenderer((ModelBase)this, 36, 20); + this.Wheel2.addBox(0.0f, 0.0f, 0.0f, 5, 4, 2); + this.Wheel2.setRotationPoint(1.0f, 6.0f, -1.0f); + this.Wheel2.setTextureSize(64, 32); + this.Wheel2.mirror = true; + this.setRotation(this.Wheel2, 0.0f, 0.0f, 0.0f); + this.WheelMount2 = new ModelRenderer((ModelBase)this, 0, 30); + this.WheelMount2.addBox(0.0f, 0.0f, 0.0f, 14, 4, 4); + this.WheelMount2.setRotationPoint(-7.0f, 4.0f, -6.0f); + this.WheelMount2.setTextureSize(64, 32); + this.WheelMount2.mirror = true; + this.setRotation(this.WheelMount2, 0.0f, 0.0f, 0.0f); + this.Wheel1 = new ModelRenderer((ModelBase)this, 36, 20); + this.Wheel1.addBox(0.0f, 0.0f, 0.0f, 5, 4, 2); + this.Wheel1.setRotationPoint(-6.0f, 6.0f, -1.0f); + this.Wheel1.setTextureSize(64, 32); + this.Wheel1.mirror = true; + this.setRotation(this.Wheel1, 0.0f, 0.0f, 0.0f); + } + + public void render(float scale) { + this.RailGuard1.render(scale); + this.ArmMount.render(scale); + this.RailGuard2.render(scale); + this.Base.render(scale); + this.WheelMount1.render(scale); + this.Wheel2.render(scale); + this.WheelMount2.render(scale); + this.Wheel1.render(scale); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelCraneController.java b/src/main/java/assemblyline/client/model/ModelCraneController.java new file mode 100644 index 0000000..f1c384f --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelCraneController.java @@ -0,0 +1,117 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelCraneController +extends ModelBase { + ModelRenderer Base2; + ModelRenderer Base; + ModelRenderer ConnectorFront; + ModelRenderer Decoration1; + ModelRenderer Decoration2; + ModelRenderer Decoration3; + ModelRenderer Decoration4; + ModelRenderer ConnectorTop; + ModelRenderer ConnectorRight; + + public ModelCraneController() { + this.textureWidth = 128; + this.textureHeight = 64; + this.Base2 = new ModelRenderer((ModelBase)this, 0, 24); + this.Base2.addBox(0.0f, 0.0f, 0.0f, 12, 4, 12); + this.Base2.setRotationPoint(-6.0f, 12.0f, -6.0f); + this.Base2.setTextureSize(128, 64); + this.Base2.mirror = true; + this.setRotation(this.Base2, 0.0f, 0.0f, 0.0f); + this.Base = new ModelRenderer((ModelBase)this, 0, 0); + this.Base.addBox(0.0f, 0.0f, 0.0f, 16, 8, 16); + this.Base.setRotationPoint(-8.0f, 16.0f, -8.0f); + this.Base.setTextureSize(128, 64); + this.Base.mirror = true; + this.setRotation(this.Base, 0.0f, 0.0f, 0.0f); + this.ConnectorFront = new ModelRenderer((ModelBase)this, 64, 0); + this.ConnectorFront.addBox(0.0f, 0.0f, 0.0f, 8, 8, 8); + this.ConnectorFront.setRotationPoint(-4.0f, 12.0f, 0.0f); + this.ConnectorFront.setTextureSize(128, 64); + this.ConnectorFront.mirror = true; + this.setRotation(this.ConnectorFront, 0.0f, 1.570796f, 0.0f); + this.Decoration1 = new ModelRenderer((ModelBase)this, 54, 24); + this.Decoration1.addBox(0.0f, 0.0f, 0.0f, 2, 1, 1); + this.Decoration1.setRotationPoint(2.0f, 15.0f, 6.0f); + this.Decoration1.setTextureSize(128, 64); + this.Decoration1.mirror = true; + this.setRotation(this.Decoration1, 0.0f, 0.0f, 0.0f); + this.Decoration2 = new ModelRenderer((ModelBase)this, 54, 24); + this.Decoration2.addBox(0.0f, 0.0f, 0.0f, 2, 1, 1); + this.Decoration2.setRotationPoint(-4.0f, 15.0f, 6.0f); + this.Decoration2.setTextureSize(128, 64); + this.Decoration2.mirror = true; + this.setRotation(this.Decoration2, 0.0f, 0.0f, 0.0f); + this.Decoration3 = new ModelRenderer((ModelBase)this, 48, 24); + this.Decoration3.addBox(0.0f, 0.0f, 0.0f, 1, 1, 2); + this.Decoration3.setRotationPoint(-7.0f, 15.0f, 2.0f); + this.Decoration3.setTextureSize(128, 64); + this.Decoration3.mirror = true; + this.setRotation(this.Decoration3, 0.0f, 0.0f, 0.0f); + this.Decoration4 = new ModelRenderer((ModelBase)this, 48, 24); + this.Decoration4.addBox(0.0f, 0.0f, 0.0f, 1, 1, 2); + this.Decoration4.setRotationPoint(-7.0f, 15.0f, -4.0f); + this.Decoration4.setTextureSize(128, 64); + this.Decoration4.mirror = true; + this.setRotation(this.Decoration4, 0.0f, 0.0f, 0.0f); + this.ConnectorTop = new ModelRenderer((ModelBase)this, 64, 0); + this.ConnectorTop.addBox(0.0f, 0.0f, 0.0f, 8, 8, 8); + this.ConnectorTop.setRotationPoint(-4.0f, 16.0f, -4.0f); + this.ConnectorTop.setTextureSize(128, 64); + this.ConnectorTop.mirror = true; + this.setRotation(this.ConnectorTop, 0.0f, 0.0f, -1.570796f); + this.ConnectorRight = new ModelRenderer((ModelBase)this, 64, 0); + this.ConnectorRight.addBox(0.0f, 0.0f, 0.0f, 8, 8, 8); + this.ConnectorRight.setRotationPoint(0.0f, 12.0f, -4.0f); + this.ConnectorRight.setTextureSize(128, 64); + this.ConnectorRight.mirror = true; + this.setRotation(this.ConnectorRight, 0.0f, 0.0f, 0.0f); + } + + public void render(float scale, boolean connectEast, boolean connectNorth) { + this.Base2.setRotationPoint(-6.0f, 12.0f, -6.0f); + this.setRotation(this.Base2, 0.0f, 0.0f, 0.0f); + this.Base.setRotationPoint(-8.0f, 16.0f, -8.0f); + this.setRotation(this.Base, 0.0f, 0.0f, 0.0f); + this.Decoration1.setRotationPoint(2.0f, 15.0f, 6.0f); + this.setRotation(this.Decoration1, 0.0f, 0.0f, 0.0f); + this.Decoration2.setRotationPoint(-4.0f, 15.0f, 6.0f); + this.setRotation(this.Decoration2, 0.0f, 0.0f, 0.0f); + this.Decoration3.setRotationPoint(-7.0f, 15.0f, 2.0f); + this.setRotation(this.Decoration3, 0.0f, 0.0f, 0.0f); + this.Decoration4.setRotationPoint(-7.0f, 15.0f, -4.0f); + this.setRotation(this.Decoration4, 0.0f, 0.0f, 0.0f); + this.ConnectorTop.setRotationPoint(-4.0f, 16.0f, -4.0f); + this.setRotation(this.ConnectorTop, 0.0f, 0.0f, -1.570796f); + this.ConnectorFront.setRotationPoint(-4.0f, 11.99f, -0.01f); + this.setRotation(this.ConnectorFront, 0.0f, 1.570796f, 0.0f); + this.ConnectorRight.setRotationPoint(0.01f, 11.99f, -4.0f); + this.setRotation(this.ConnectorRight, 0.0f, 0.0f, 0.0f); + this.Base2.render(scale); + this.Base.render(scale); + this.ConnectorTop.render(scale); + if (connectEast) { + this.ConnectorFront.render(scale); + this.Decoration1.render(scale); + this.Decoration2.render(scale); + } + if (connectNorth) { + this.ConnectorRight.render(scale); + this.Decoration3.render(scale); + this.Decoration4.render(scale); + } + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelCraneRail.java b/src/main/java/assemblyline/client/model/ModelCraneRail.java new file mode 100644 index 0000000..c61d029 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelCraneRail.java @@ -0,0 +1,454 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelCraneRail +extends ModelBase { + ModelRenderer SegmentUBLeft; + ModelRenderer SegmentUFLeft; + ModelRenderer SegmentBFLeft; + ModelRenderer SegmentBBLeft; + ModelRenderer SegmentBLBack; + ModelRenderer SegmentLUBack; + ModelRenderer SegmentRUBack; + ModelRenderer SegmentBRBack; + ModelRenderer SegmentBLFront; + ModelRenderer SegmentLUFront; + ModelRenderer SegmentRUFront; + ModelRenderer SegmentBRFront; + ModelRenderer SegmentLBUp; + ModelRenderer SegmentRBUp; + ModelRenderer SegmentLFUp; + ModelRenderer SegmentRFUp; + ModelRenderer SegmentUBRight; + ModelRenderer SegmentBFRight; + ModelRenderer SegmentUFRight; + ModelRenderer SegmentBBRight; + ModelRenderer SegmentLFDown; + ModelRenderer SegmentLBDown; + ModelRenderer SegmentRBDown; + ModelRenderer SegmentRFDown; + ModelRenderer SegmentBFMid; + ModelRenderer SegmentUBMid; + ModelRenderer SegmentBBMid; + ModelRenderer SegmentUFMid; + ModelRenderer SegmentLBMid; + ModelRenderer SegmentLFMid; + ModelRenderer SegmentRBMid; + ModelRenderer SegmentRFMid; + ModelRenderer SegmentRUMid; + ModelRenderer SegmentBRMid; + ModelRenderer SegmentBLMid; + ModelRenderer SegmentLUMid; + ModelRenderer SegmentMidDiag1; + ModelRenderer SegmentMidDiag2; + ModelRenderer SegmentMidDiag3; + ModelRenderer SegmentMidDiag4; + ModelRenderer SegmentMidDiag5; + ModelRenderer SegmentMidDiag6; + ModelRenderer SegmentMidDiag7; + ModelRenderer SegmentMidDiag8; + ModelRenderer FootBottom; + ModelRenderer FootTop; + + public ModelCraneRail() { + this.textureWidth = 64; + this.textureHeight = 32; + this.SegmentBLBack = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentBLBack.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentBLBack.setRotationPoint(3.0f, 19.0f, 4.0f); + this.SegmentBLBack.setTextureSize(64, 32); + this.SegmentBLBack.mirror = true; + this.setRotation(this.SegmentBLBack, 0.0f, 0.0f, 0.0f); + this.SegmentLUBack = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentLUBack.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentLUBack.setRotationPoint(3.0f, 12.0f, 4.0f); + this.SegmentLUBack.setTextureSize(64, 32); + this.SegmentLUBack.mirror = true; + this.setRotation(this.SegmentLUBack, 0.0f, 0.0f, 0.0f); + this.SegmentRUBack = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentRUBack.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentRUBack.setRotationPoint(-4.0f, 12.0f, 4.0f); + this.SegmentRUBack.setTextureSize(64, 32); + this.SegmentRUBack.mirror = true; + this.setRotation(this.SegmentRUBack, 0.0f, 0.0f, 0.0f); + this.SegmentBRBack = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentBRBack.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentBRBack.setRotationPoint(-4.0f, 19.0f, 4.0f); + this.SegmentBRBack.setTextureSize(64, 32); + this.SegmentBRBack.mirror = true; + this.setRotation(this.SegmentBRBack, 0.0f, 0.0f, 0.0f); + this.SegmentBLFront = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentBLFront.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentBLFront.setRotationPoint(3.0f, 19.0f, -8.0f); + this.SegmentBLFront.setTextureSize(64, 32); + this.SegmentBLFront.mirror = true; + this.setRotation(this.SegmentBLFront, 0.0f, 0.0f, 0.0f); + this.SegmentLUFront = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentLUFront.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentLUFront.setRotationPoint(3.0f, 12.0f, -8.0f); + this.SegmentLUFront.setTextureSize(64, 32); + this.SegmentLUFront.mirror = true; + this.setRotation(this.SegmentLUFront, 0.0f, 0.0f, 0.0f); + this.SegmentRUFront = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentRUFront.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentRUFront.setRotationPoint(-4.0f, 12.0f, -8.0f); + this.SegmentRUFront.setTextureSize(64, 32); + this.SegmentRUFront.mirror = true; + this.setRotation(this.SegmentRUFront, 0.0f, 0.0f, 0.0f); + this.SegmentBRFront = new ModelRenderer((ModelBase)this, 10, 13); + this.SegmentBRFront.addBox(0.0f, 0.0f, 0.0f, 1, 1, 4); + this.SegmentBRFront.setRotationPoint(-4.0f, 19.0f, -8.0f); + this.SegmentBRFront.setTextureSize(64, 32); + this.SegmentBRFront.mirror = true; + this.setRotation(this.SegmentBRFront, 0.0f, 0.0f, 0.0f); + this.SegmentLBUp = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentLBUp.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentLBUp.setRotationPoint(3.0f, 8.0f, 3.0f); + this.SegmentLBUp.setTextureSize(64, 32); + this.SegmentLBUp.mirror = true; + this.setRotation(this.SegmentLBUp, 0.0f, 0.0f, 0.0f); + this.SegmentRBUp = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentRBUp.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentRBUp.setRotationPoint(-4.0f, 8.0f, 3.0f); + this.SegmentRBUp.setTextureSize(64, 32); + this.SegmentRBUp.mirror = true; + this.setRotation(this.SegmentRBUp, 0.0f, 0.0f, 0.0f); + this.SegmentLFUp = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentLFUp.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentLFUp.setRotationPoint(3.0f, 8.0f, -4.0f); + this.SegmentLFUp.setTextureSize(64, 32); + this.SegmentLFUp.mirror = true; + this.setRotation(this.SegmentLFUp, 0.0f, 0.0f, 0.0f); + this.SegmentRFUp = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentRFUp.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentRFUp.setRotationPoint(-4.0f, 8.0f, -4.0f); + this.SegmentRFUp.setTextureSize(64, 32); + this.SegmentRFUp.mirror = true; + this.setRotation(this.SegmentRFUp, 0.0f, 0.0f, 0.0f); + this.SegmentUBRight = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentUBRight.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentUBRight.setRotationPoint(-8.0f, 12.0f, 3.0f); + this.SegmentUBRight.setTextureSize(64, 32); + this.SegmentUBRight.mirror = true; + this.setRotation(this.SegmentUBRight, 0.0f, 0.0f, 0.0f); + this.SegmentBFRight = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentBFRight.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentBFRight.setRotationPoint(-8.0f, 19.0f, -4.0f); + this.SegmentBFRight.setTextureSize(64, 32); + this.SegmentBFRight.mirror = true; + this.setRotation(this.SegmentBFRight, 0.0f, 0.0f, 0.0f); + this.SegmentUFRight = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentUFRight.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentUFRight.setRotationPoint(-8.0f, 12.0f, -4.0f); + this.SegmentUFRight.setTextureSize(64, 32); + this.SegmentUFRight.mirror = true; + this.setRotation(this.SegmentUFRight, 0.0f, 0.0f, 0.0f); + this.SegmentBBRight = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentBBRight.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentBBRight.setRotationPoint(-8.0f, 19.0f, 3.0f); + this.SegmentBBRight.setTextureSize(64, 32); + this.SegmentBBRight.mirror = true; + this.setRotation(this.SegmentBBRight, 0.0f, 0.0f, 0.0f); + this.SegmentLFDown = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentLFDown.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentLFDown.setRotationPoint(3.0f, 20.0f, -4.0f); + this.SegmentLFDown.setTextureSize(64, 32); + this.SegmentLFDown.mirror = true; + this.setRotation(this.SegmentLFDown, 0.0f, 0.0f, 0.0f); + this.SegmentLBDown = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentLBDown.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentLBDown.setRotationPoint(3.0f, 20.0f, 3.0f); + this.SegmentLBDown.setTextureSize(64, 32); + this.SegmentLBDown.mirror = true; + this.setRotation(this.SegmentLBDown, 0.0f, 0.0f, 0.0f); + this.SegmentRBDown = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentRBDown.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentRBDown.setRotationPoint(-4.0f, 20.0f, 3.0f); + this.SegmentRBDown.setTextureSize(64, 32); + this.SegmentRBDown.mirror = true; + this.setRotation(this.SegmentRBDown, 0.0f, 0.0f, 0.0f); + this.FootTop = new ModelRenderer((ModelBase)this, 24, 0); + this.FootTop.addBox(0.0f, 0.0f, 0.0f, 10, 2, 10); + this.FootTop.setRotationPoint(-5.0f, 20.0f, -5.0f); + this.FootTop.setTextureSize(64, 32); + this.FootTop.mirror = true; + this.setRotation(this.FootTop, 0.0f, 0.0f, 0.0f); + this.SegmentRFDown = new ModelRenderer((ModelBase)this, 20, 13); + this.SegmentRFDown.addBox(0.0f, 0.0f, 0.0f, 1, 4, 1); + this.SegmentRFDown.setRotationPoint(-4.0f, 20.0f, -4.0f); + this.SegmentRFDown.setTextureSize(64, 32); + this.SegmentRFDown.mirror = true; + this.setRotation(this.SegmentRFDown, 0.0f, 0.0f, 0.0f); + this.FootBottom = new ModelRenderer((ModelBase)this, 0, 18); + this.FootBottom.addBox(0.0f, 0.0f, 0.0f, 12, 2, 12); + this.FootBottom.setRotationPoint(-6.0f, 22.0f, -6.0f); + this.FootBottom.setTextureSize(64, 32); + this.FootBottom.mirror = true; + this.setRotation(this.FootBottom, 0.0f, 0.0f, 0.0f); + this.SegmentBFMid = new ModelRenderer((ModelBase)this, 30, 12); + this.SegmentBFMid.addBox(0.0f, 0.0f, 0.0f, 8, 1, 1); + this.SegmentBFMid.setRotationPoint(-4.0f, 19.0f, -4.0f); + this.SegmentBFMid.setTextureSize(64, 32); + this.SegmentBFMid.mirror = true; + this.setRotation(this.SegmentBFMid, 0.0f, 0.0f, 0.0f); + this.SegmentUBMid = new ModelRenderer((ModelBase)this, 30, 12); + this.SegmentUBMid.addBox(0.0f, 0.0f, 0.0f, 8, 1, 1); + this.SegmentUBMid.setRotationPoint(-4.0f, 12.0f, 3.0f); + this.SegmentUBMid.setTextureSize(64, 32); + this.SegmentUBMid.mirror = true; + this.setRotation(this.SegmentUBMid, 0.0f, 0.0f, 0.0f); + this.SegmentBBMid = new ModelRenderer((ModelBase)this, 30, 12); + this.SegmentBBMid.addBox(0.0f, 0.0f, 0.0f, 8, 1, 1); + this.SegmentBBMid.setRotationPoint(-4.0f, 19.0f, 3.0f); + this.SegmentBBMid.setTextureSize(64, 32); + this.SegmentBBMid.mirror = true; + this.setRotation(this.SegmentBBMid, 0.0f, 0.0f, 0.0f); + this.SegmentUFMid = new ModelRenderer((ModelBase)this, 30, 12); + this.SegmentUFMid.addBox(0.0f, 0.0f, 0.0f, 8, 1, 1); + this.SegmentUFMid.setRotationPoint(-4.0f, 12.0f, -4.0f); + this.SegmentUFMid.setTextureSize(64, 32); + this.SegmentUFMid.mirror = true; + this.setRotation(this.SegmentUFMid, 0.0f, 0.0f, 0.0f); + this.SegmentLBMid = new ModelRenderer((ModelBase)this, 48, 19); + this.SegmentLBMid.addBox(0.0f, 0.0f, 0.0f, 1, 6, 1); + this.SegmentLBMid.setRotationPoint(3.0f, 13.0f, 3.0f); + this.SegmentLBMid.setTextureSize(64, 32); + this.SegmentLBMid.mirror = true; + this.setRotation(this.SegmentLBMid, 0.0f, 0.0f, 0.0f); + this.SegmentLFMid = new ModelRenderer((ModelBase)this, 48, 19); + this.SegmentLFMid.addBox(0.0f, 0.0f, 0.0f, 1, 6, 1); + this.SegmentLFMid.setRotationPoint(3.0f, 13.0f, -4.0f); + this.SegmentLFMid.setTextureSize(64, 32); + this.SegmentLFMid.mirror = true; + this.setRotation(this.SegmentLFMid, 0.0f, 0.0f, 0.0f); + this.SegmentRBMid = new ModelRenderer((ModelBase)this, 48, 19); + this.SegmentRBMid.addBox(0.0f, 0.0f, 0.0f, 1, 6, 1); + this.SegmentRBMid.setRotationPoint(-4.0f, 13.0f, 3.0f); + this.SegmentRBMid.setTextureSize(64, 32); + this.SegmentRBMid.mirror = true; + this.setRotation(this.SegmentRBMid, 0.0f, 0.0f, 0.0f); + this.SegmentRFMid = new ModelRenderer((ModelBase)this, 48, 19); + this.SegmentRFMid.addBox(0.0f, 0.0f, 0.0f, 1, 6, 1); + this.SegmentRFMid.setRotationPoint(-4.0f, 13.0f, -4.0f); + this.SegmentRFMid.setTextureSize(64, 32); + this.SegmentRFMid.mirror = true; + this.setRotation(this.SegmentRFMid, 0.0f, 0.0f, 0.0f); + this.SegmentMidDiag4 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag4.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag4.setRotationPoint(-3.99f, 12.0f, -3.0f); + this.SegmentMidDiag4.setTextureSize(64, 32); + this.SegmentMidDiag4.mirror = true; + this.setRotation(this.SegmentMidDiag4, -0.7853982f, 0.0f, 0.0f); + this.SegmentRUMid = new ModelRenderer((ModelBase)this, 48, 12); + this.SegmentRUMid.addBox(0.0f, 0.0f, 0.0f, 1, 1, 6); + this.SegmentRUMid.setRotationPoint(-4.0f, 12.0f, -3.0f); + this.SegmentRUMid.setTextureSize(64, 32); + this.SegmentRUMid.mirror = true; + this.setRotation(this.SegmentRUMid, 0.0f, 0.0f, 0.0f); + this.SegmentBRMid = new ModelRenderer((ModelBase)this, 48, 12); + this.SegmentBRMid.addBox(0.0f, 0.0f, 0.0f, 1, 1, 6); + this.SegmentBRMid.setRotationPoint(-4.0f, 19.0f, -3.0f); + this.SegmentBRMid.setTextureSize(64, 32); + this.SegmentBRMid.mirror = true; + this.setRotation(this.SegmentBRMid, 0.0f, 0.0f, 0.0f); + this.SegmentBLMid = new ModelRenderer((ModelBase)this, 48, 12); + this.SegmentBLMid.addBox(0.0f, 0.0f, 0.0f, 1, 1, 6); + this.SegmentBLMid.setRotationPoint(3.0f, 19.0f, -3.0f); + this.SegmentBLMid.setTextureSize(64, 32); + this.SegmentBLMid.mirror = true; + this.setRotation(this.SegmentBLMid, 0.0f, 0.0f, 0.0f); + this.SegmentLUMid = new ModelRenderer((ModelBase)this, 48, 12); + this.SegmentLUMid.addBox(0.0f, 0.0f, 0.0f, 1, 1, 6); + this.SegmentLUMid.setRotationPoint(3.0f, 12.0f, -3.0f); + this.SegmentLUMid.setTextureSize(64, 32); + this.SegmentLUMid.mirror = true; + this.setRotation(this.SegmentLUMid, 0.0f, 0.0f, 0.0f); + this.SegmentMidDiag3 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag3.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag3.setRotationPoint(-4.0f, 19.0f, -4.0f); + this.SegmentMidDiag3.setTextureSize(64, 32); + this.SegmentMidDiag3.mirror = true; + this.setRotation(this.SegmentMidDiag3, 0.7853982f, 0.0f, 0.0f); + this.SegmentMidDiag7 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag7.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag7.setRotationPoint(-2.99f, 12.0f, 4.0f); + this.SegmentMidDiag7.setTextureSize(64, 32); + this.SegmentMidDiag7.mirror = true; + this.setRotation(this.SegmentMidDiag7, -0.7853982f, 1.570796f, 0.0f); + this.SegmentMidDiag8 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag8.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag8.setRotationPoint(-4.0f, 19.0f, 4.0f); + this.SegmentMidDiag8.setTextureSize(64, 32); + this.SegmentMidDiag8.mirror = true; + this.setRotation(this.SegmentMidDiag8, 0.7853982f, 1.570796f, 0.0f); + this.SegmentMidDiag1 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag1.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag1.setRotationPoint(3.0f, 19.0f, -4.0f); + this.SegmentMidDiag1.setTextureSize(64, 32); + this.SegmentMidDiag1.mirror = true; + this.setRotation(this.SegmentMidDiag1, 0.7853982f, 0.0f, 0.0f); + this.SegmentMidDiag2 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag2.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag2.setRotationPoint(3.01f, 12.0f, -3.0f); + this.SegmentMidDiag2.setTextureSize(64, 32); + this.SegmentMidDiag2.mirror = true; + this.setRotation(this.SegmentMidDiag2, -0.7853982f, 0.0f, 0.0f); + this.SegmentMidDiag6 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag6.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag6.setRotationPoint(-4.0f, 19.0f, -3.0f); + this.SegmentMidDiag6.setTextureSize(64, 32); + this.SegmentMidDiag6.mirror = true; + this.setRotation(this.SegmentMidDiag6, 0.7853982f, 1.570796f, 0.0f); + this.SegmentMidDiag5 = new ModelRenderer((ModelBase)this, 0, 0); + this.SegmentMidDiag5.addBox(0.0f, 0.0f, 0.0f, 1, 1, 10); + this.SegmentMidDiag5.setRotationPoint(-2.99f, 12.0f, -3.0f); + this.SegmentMidDiag5.setTextureSize(64, 32); + this.SegmentMidDiag5.mirror = true; + this.setRotation(this.SegmentMidDiag5, -0.7853982f, 1.570796f, 0.0f); + this.SegmentUBLeft = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentUBLeft.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentUBLeft.setRotationPoint(4.0f, 12.0f, 3.0f); + this.SegmentUBLeft.setTextureSize(64, 32); + this.SegmentUBLeft.mirror = true; + this.setRotation(this.SegmentUBLeft, 0.0f, 0.0f, 0.0f); + this.SegmentUFLeft = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentUFLeft.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentUFLeft.setRotationPoint(4.0f, 12.0f, -4.0f); + this.SegmentUFLeft.setTextureSize(64, 32); + this.SegmentUFLeft.mirror = true; + this.setRotation(this.SegmentUFLeft, 0.0f, 0.0f, 0.0f); + this.SegmentBFLeft = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentBFLeft.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentBFLeft.setRotationPoint(4.0f, 19.0f, -4.0f); + this.SegmentBFLeft.setTextureSize(64, 32); + this.SegmentBFLeft.mirror = true; + this.setRotation(this.SegmentBFLeft, 0.0f, 0.0f, 0.0f); + this.SegmentBBLeft = new ModelRenderer((ModelBase)this, 0, 13); + this.SegmentBBLeft.addBox(0.0f, 0.0f, 0.0f, 4, 1, 1); + this.SegmentBBLeft.setRotationPoint(4.0f, 19.0f, 3.0f); + this.SegmentBBLeft.setTextureSize(64, 32); + this.SegmentBBLeft.mirror = true; + this.setRotation(this.SegmentBBLeft, 0.0f, 0.0f, 0.0f); + this.fixPositions(); + } + + public void fixPositions() { + this.SegmentBLBack.setRotationPoint(3.0f, 19.0f, 4.0f); + this.SegmentLUBack.setRotationPoint(3.0f, 12.0f, 4.0f); + this.SegmentRUBack.setRotationPoint(-4.0f, 12.0f, 4.0f); + this.SegmentBRBack.setRotationPoint(-4.0f, 19.0f, 4.0f); + this.SegmentBLFront.setRotationPoint(3.0f, 19.0f, -8.0f); + this.SegmentLUFront.setRotationPoint(3.0f, 12.0f, -8.0f); + this.SegmentRUFront.setRotationPoint(-4.0f, 12.0f, -8.0f); + this.SegmentBRFront.setRotationPoint(-4.0f, 19.0f, -8.0f); + this.SegmentLBUp.setRotationPoint(3.0f, 8.0f, 3.0f); + this.SegmentRBUp.setRotationPoint(-4.0f, 8.0f, 3.0f); + this.SegmentLFUp.setRotationPoint(3.0f, 8.0f, -4.0f); + this.SegmentRFUp.setRotationPoint(-4.0f, 8.0f, -4.0f); + this.SegmentUBRight.setRotationPoint(-8.0f, 12.0f, 3.0f); + this.SegmentBFRight.setRotationPoint(-8.0f, 19.0f, -4.0f); + this.SegmentUFRight.setRotationPoint(-8.0f, 12.0f, -4.0f); + this.SegmentBBRight.setRotationPoint(-8.0f, 19.0f, 3.0f); + this.SegmentLFDown.setRotationPoint(3.0f, 20.0f, -4.0f); + this.SegmentLBDown.setRotationPoint(3.0f, 20.0f, 3.0f); + this.SegmentRBDown.setRotationPoint(-4.0f, 20.0f, 3.0f); + this.SegmentRFDown.setRotationPoint(-4.0f, 20.0f, -4.0f); + this.SegmentBFMid.setRotationPoint(-4.0f, 19.0f, -4.0f); + this.SegmentUBMid.setRotationPoint(-4.0f, 12.0f, 3.0f); + this.SegmentBBMid.setRotationPoint(-4.0f, 19.0f, 3.0f); + this.SegmentUFMid.setRotationPoint(-4.0f, 12.0f, -4.0f); + this.SegmentLBMid.setRotationPoint(3.0f, 13.0f, 3.0f); + this.SegmentLFMid.setRotationPoint(3.0f, 13.0f, -4.0f); + this.SegmentRBMid.setRotationPoint(-4.0f, 13.0f, 3.0f); + this.SegmentRFMid.setRotationPoint(-4.0f, 13.0f, -4.0f); + this.SegmentRUMid.setRotationPoint(-4.0f, 12.0f, -3.0f); + this.SegmentBRMid.setRotationPoint(-4.0f, 19.0f, -3.0f); + this.SegmentBLMid.setRotationPoint(3.0f, 19.0f, -3.0f); + this.SegmentLUMid.setRotationPoint(3.0f, 12.0f, -3.0f); + this.SegmentMidDiag1.setRotationPoint(2.99f, 19.1f, -4.0f); + this.SegmentMidDiag2.setRotationPoint(2.99f, 12.0f, -3.1f); + this.SegmentMidDiag3.setRotationPoint(-3.99f, 19.1f, -4.0f); + this.SegmentMidDiag4.setRotationPoint(-3.99f, 12.0f, -3.1f); + this.SegmentMidDiag5.setRotationPoint(-3.1f, 12.0f, -2.99f); + this.SegmentMidDiag6.setRotationPoint(-4.0f, 19.1f, -2.99f); + this.SegmentMidDiag7.setRotationPoint(-3.1f, 12.0f, 3.99f); + this.SegmentMidDiag8.setRotationPoint(-4.0f, 19.0f, 3.99f); + this.SegmentUBLeft.setRotationPoint(4.0f, 12.0f, 3.0f); + this.SegmentUFLeft.setRotationPoint(4.0f, 12.0f, -4.0f); + this.SegmentBFLeft.setRotationPoint(4.0f, 19.0f, -4.0f); + this.SegmentBBLeft.setRotationPoint(4.0f, 19.0f, 3.0f); + } + + public void render(boolean up, boolean down, boolean left, boolean right, boolean front, boolean back, boolean foot) { + float scale = 0.0625f; + if (up) { + this.SegmentLBUp.render(scale); + this.SegmentRBUp.render(scale); + this.SegmentLFUp.render(scale); + this.SegmentRFUp.render(scale); + } + if (down) { + this.SegmentLFDown.render(scale); + this.SegmentLBDown.render(scale); + this.SegmentRBDown.render(scale); + this.SegmentRFDown.render(scale); + } + if (left) { + this.SegmentUBLeft.render(scale); + this.SegmentUFLeft.render(scale); + this.SegmentBFLeft.render(scale); + this.SegmentBBLeft.render(scale); + } + if (right) { + this.SegmentUBRight.render(scale); + this.SegmentBFRight.render(scale); + this.SegmentUFRight.render(scale); + this.SegmentBBRight.render(scale); + } + if (front) { + this.SegmentBLFront.render(scale); + this.SegmentLUFront.render(scale); + this.SegmentRUFront.render(scale); + this.SegmentBRFront.render(scale); + } + if (back) { + this.SegmentBLBack.render(scale); + this.SegmentLUBack.render(scale); + this.SegmentRUBack.render(scale); + this.SegmentBRBack.render(scale); + } + if (foot) { + this.FootBottom.render(scale); + this.FootTop.render(scale); + } + this.SegmentBFMid.render(scale); + this.SegmentUBMid.render(scale); + this.SegmentBBMid.render(scale); + this.SegmentUFMid.render(scale); + this.SegmentLBMid.render(scale); + this.SegmentLFMid.render(scale); + this.SegmentRBMid.render(scale); + this.SegmentRFMid.render(scale); + this.SegmentRUMid.render(scale); + this.SegmentBRMid.render(scale); + this.SegmentBLMid.render(scale); + this.SegmentLUMid.render(scale); + this.SegmentMidDiag1.render(scale); + this.SegmentMidDiag2.render(scale); + this.SegmentMidDiag3.render(scale); + this.SegmentMidDiag4.render(scale); + this.SegmentMidDiag5.render(scale); + this.SegmentMidDiag6.render(scale); + this.SegmentMidDiag7.render(scale); + this.SegmentMidDiag8.render(scale); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelDropBox.java b/src/main/java/assemblyline/client/model/ModelDropBox.java new file mode 100644 index 0000000..3c8ea0d --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelDropBox.java @@ -0,0 +1,103 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelDropBox +extends ModelBase { + ModelRenderer Left; + ModelRenderer Top; + ModelRenderer Front; + ModelRenderer LeftB; + ModelRenderer Back; + ModelRenderer Right; + ModelRenderer RightB; + ModelRenderer Bottom; + ModelRenderer Back3; + ModelRenderer Back2; + + public ModelDropBox() { + this.textureWidth = 128; + this.textureHeight = 128; + this.Left = new ModelRenderer((ModelBase)this, 33, 43); + this.Left.addBox(7.0f, -10.0f, -8.0f, 1, 7, 15); + this.Left.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Left.setTextureSize(128, 128); + this.Left.mirror = true; + this.setRotation(this.Left, 0.0f, 0.0f, 0.0f); + this.Top = new ModelRenderer((ModelBase)this, 0, 65); + this.Top.addBox(-7.0f, -11.0f, -7.0f, 14, 1, 14); + this.Top.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Top.setTextureSize(128, 128); + this.Top.mirror = true; + this.setRotation(this.Top, 0.0f, 0.0f, 0.0f); + this.Front = new ModelRenderer((ModelBase)this, 0, 33); + this.Front.addBox(-8.0f, -4.0f, -7.5f, 16, 5, 1); + this.Front.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Front.setTextureSize(128, 128); + this.Front.mirror = true; + this.setRotation(this.Front, 0.5235988f, 0.0f, 0.0f); + this.LeftB = new ModelRenderer((ModelBase)this, 36, 21); + this.LeftB.addBox(7.0f, -3.0f, -6.0f, 1, 8, 13); + this.LeftB.setRotationPoint(0.0f, 19.0f, 0.0f); + this.LeftB.setTextureSize(128, 128); + this.LeftB.mirror = true; + this.setRotation(this.LeftB, 0.0f, 0.0f, 0.0f); + this.Back = new ModelRenderer((ModelBase)this, 0, 96); + this.Back.addBox(-5.0f, -8.0f, 4.0f, 10, 10, 4); + this.Back.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Back.setTextureSize(128, 128); + this.Back.mirror = true; + this.setRotation(this.Back, 0.0f, 0.0f, 0.0f); + this.Right = new ModelRenderer((ModelBase)this, 0, 42); + this.Right.addBox(-8.0f, -10.0f, -8.0f, 1, 7, 15); + this.Right.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Right.setTextureSize(128, 128); + this.Right.mirror = true; + this.setRotation(this.Right, 0.0f, 0.0f, 0.0f); + this.RightB = new ModelRenderer((ModelBase)this, 36, 0); + this.RightB.addBox(-8.0f, -3.0f, -6.0f, 1, 8, 13); + this.RightB.setRotationPoint(0.0f, 19.0f, 0.0f); + this.RightB.setTextureSize(128, 128); + this.RightB.mirror = true; + this.setRotation(this.RightB, 0.0f, 0.0f, 0.0f); + this.Bottom = new ModelRenderer((ModelBase)this, 0, 81); + this.Bottom.addBox(-7.0f, 4.0f, -6.0f, 14, 1, 13); + this.Bottom.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Bottom.setTextureSize(128, 128); + this.Bottom.mirror = true; + this.setRotation(this.Bottom, 0.0f, 0.0f, 0.0f); + this.Back3 = new ModelRenderer((ModelBase)this, 0, 23); + this.Back3.addBox(-7.0f, -10.0f, -9.0f, 14, 8, 1); + this.Back3.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Back3.setTextureSize(128, 128); + this.Back3.mirror = true; + this.setRotation(this.Back3, -0.1919862f, 0.0f, 0.0f); + this.Back2 = new ModelRenderer((ModelBase)this, 0, 7); + this.Back2.addBox(-7.0f, -10.0f, 3.0f, 14, 14, 1); + this.Back2.setRotationPoint(0.0f, 19.0f, 0.0f); + this.Back2.setTextureSize(128, 128); + this.Back2.mirror = true; + this.setRotation(this.Back2, 0.0f, 0.0f, 0.0f); + } + + public void render(float f5) { + this.Left.render(f5); + this.Top.render(f5); + this.Front.render(f5); + this.LeftB.render(f5); + this.Back.render(f5); + this.Right.render(f5); + this.RightB.render(f5); + this.Bottom.render(f5); + this.Back.render(f5); + this.Back.render(f5); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelHelper.java b/src/main/java/assemblyline/client/model/ModelHelper.java new file mode 100644 index 0000000..ee4dc0d --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelHelper.java @@ -0,0 +1,142 @@ +package assemblyline.client.model; + +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +public class ModelHelper { + private static int gTexWidth = 64; + private static int gTexHeight = 32; + private static int sTexWidth = 64; + private static int sTexHeight = 32; + private static int texOffsetX = 0; + private static int texOffsetY = 0; + private static float texScale = 16.0f; + private static boolean clip = false; + + private static void drawQuadRaw(Vec3 v1, Vec3 v2, Vec3 v3, Vec3 v4, ForgeDirection side) { + float yMax; + float xMax; + GL11.glBegin((int)7); + float quadWidth = 1.0f; + float quadHeight = 1.0f; + float subWidth = (float)sTexWidth / (float)gTexWidth; + float subHeight = (float)sTexHeight / (float)gTexHeight; + float xMin = (float)texOffsetX / (float)sTexWidth * subWidth; + float yMin = (float)texOffsetY / (float)sTexHeight * subHeight; + float subSqX = 0.0f; + float subSqY = 0.0f; + float subSqWidth = 0.25f * ((float)sTexWidth / (float)gTexWidth); + float subSqHeight = 0.5f * ((float)sTexHeight / (float)gTexHeight); + switch (side) { + case UP: { + subSqX = 2.0f * subSqWidth; + subSqY = 0.0f; + quadWidth = (float)Math.abs(v2.xCoord - v1.xCoord); + quadHeight = (float)Math.abs(v4.zCoord - v1.zCoord); + break; + } + case DOWN: { + subSqX = 1.0f * subSqWidth; + subSqY = 0.0f; + quadWidth = (float)Math.abs(v2.xCoord - v1.xCoord); + quadHeight = (float)Math.abs(v4.zCoord - v1.zCoord); + break; + } + case EAST: { + subSqX = 0.0f; + subSqY = subSqHeight; + quadWidth = (float)Math.abs(v2.zCoord - v1.zCoord); + quadHeight = (float)Math.abs(v4.yCoord - v1.yCoord); + break; + } + case WEST: { + subSqX = 2.0f * subSqWidth; + subSqY = subSqHeight; + quadWidth = (float)Math.abs(v2.zCoord - v1.zCoord); + quadHeight = (float)Math.abs(v4.yCoord - v1.yCoord); + break; + } + case SOUTH: { + subSqX = subSqWidth; + subSqY = subSqHeight; + quadWidth = (float)Math.abs(v2.xCoord - v1.xCoord); + quadHeight = (float)Math.abs(v4.yCoord - v1.yCoord); + break; + } + case NORTH: { + subSqX = 3.0f * subSqWidth; + subSqY = subSqHeight; + quadWidth = (float)Math.abs(v2.xCoord - v1.xCoord); + quadHeight = (float)Math.abs(v4.yCoord - v1.yCoord); + break; + } + } + xMin += subSqX; + yMin += subSqY; + if (clip) { + xMax = (xMin += (1.0f - quadWidth) * subSqWidth) + subSqWidth * quadWidth; + yMax = (yMin += (1.0f - quadHeight) * subSqHeight) + subSqHeight * quadHeight; + } else { + xMax = xMin + subSqWidth; + yMax = yMin + subSqHeight; + } + GL11.glTexCoord2f((float)xMin, (float)yMin); + GL11.glVertex3d((double)v1.xCoord, (double)v1.yCoord, (double)v1.zCoord); + GL11.glTexCoord2f((float)xMax, (float)yMin); + GL11.glVertex3d((double)v2.xCoord, (double)v2.yCoord, (double)v2.zCoord); + GL11.glTexCoord2f((float)xMax, (float)yMax); + GL11.glVertex3d((double)v3.xCoord, (double)v3.yCoord, (double)v3.zCoord); + GL11.glTexCoord2f((float)xMin, (float)yMax); + GL11.glVertex3d((double)v4.xCoord, (double)v4.yCoord, (double)v4.zCoord); + GL11.glEnd(); + } + + private static void drawCuboidRaw(Vec3 v1, Vec3 v2, Vec3 v3, Vec3 v4, Vec3 v5, Vec3 v6, Vec3 v7, Vec3 v8) { + ModelHelper.drawQuadRaw(v1, v2, v3, v4, ForgeDirection.UP); + ModelHelper.drawQuadRaw(v7, v6, v3, v2, ForgeDirection.EAST); + ModelHelper.drawQuadRaw(v5, v6, v7, v8, ForgeDirection.DOWN); + ModelHelper.drawQuadRaw(v5, v8, v1, v4, ForgeDirection.WEST); + ModelHelper.drawQuadRaw(v6, v5, v4, v3, ForgeDirection.NORTH); + ModelHelper.drawQuadRaw(v8, v7, v2, v1, ForgeDirection.SOUTH); + } + + public static void drawCuboid(float xOffset, float yOffset, float zOffset, float xSize, float ySize, float zSize) { + float x = xOffset; + float y = yOffset; + float z = zOffset; + float x2 = x + xSize; + float y2 = y + ySize; + float z2 = z + zSize; + Vec3 v1 = Vec3.createVectorHelper((double)x, (double)y2, (double)z2); + Vec3 v2 = Vec3.createVectorHelper((double)x2, (double)y2, (double)z2); + Vec3 v3 = Vec3.createVectorHelper((double)x2, (double)y2, (double)z); + Vec3 v4 = Vec3.createVectorHelper((double)x, (double)y2, (double)z); + Vec3 v5 = Vec3.createVectorHelper((double)x, (double)y, (double)z); + Vec3 v6 = Vec3.createVectorHelper((double)x2, (double)y, (double)z); + Vec3 v7 = Vec3.createVectorHelper((double)x2, (double)y, (double)z2); + Vec3 v8 = Vec3.createVectorHelper((double)x, (double)y, (double)z2); + ModelHelper.drawCuboidRaw(v1, v2, v3, v4, v5, v6, v7, v8); + } + + public static void setTextureOffset(int xOffset, int yOffset) { + texOffsetX = xOffset; + texOffsetY = yOffset; + } + + public static void setGlobalTextureResolution(int width, int height) { + gTexWidth = width; + gTexHeight = height; + } + + public static void setTextureSubResolution(int width, int height) { + sTexWidth = width; + sTexHeight = height; + } + + public static void setTextureClip(boolean clip) { + ModelHelper.clip = clip; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelLaserDrill.java b/src/main/java/assemblyline/client/model/ModelLaserDrill.java new file mode 100644 index 0000000..0ae9218 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelLaserDrill.java @@ -0,0 +1,135 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelLaserDrill +extends ModelBase { + ModelRenderer Tip; + ModelRenderer Upper_plating; + ModelRenderer Middle_plating; + ModelRenderer Shape3_1; + ModelRenderer Shape3_2; + ModelRenderer Shape3_3; + ModelRenderer Shape3_4; + ModelRenderer LowerPlating_1; + ModelRenderer LowerPlating_2; + ModelRenderer Bump_1; + ModelRenderer Bump_2; + ModelRenderer Bump_3; + ModelRenderer Bump_4; + ModelRenderer Cross; + + public ModelLaserDrill() { + this.textureWidth = 64; + this.textureHeight = 32; + this.Tip = new ModelRenderer((ModelBase)this, 0, 8); + this.Tip.addBox(-1.0f, 0.0f, -1.0f, 2, 16, 2); + this.Tip.setRotationPoint(0.0f, 8.0f, 0.0f); + this.Tip.setTextureSize(64, 32); + this.Tip.mirror = true; + this.setRotation(this.Tip, 0.0f, 0.0f, 0.0f); + this.Upper_plating = new ModelRenderer((ModelBase)this, 0, 0); + this.Upper_plating.addBox(-2.0f, 0.0f, -2.0f, 4, 1, 4); + this.Upper_plating.setRotationPoint(0.0f, 11.0f, 0.0f); + this.Upper_plating.setTextureSize(64, 32); + this.Upper_plating.mirror = true; + this.setRotation(this.Upper_plating, 0.0f, 0.0f, 0.0f); + this.Middle_plating = new ModelRenderer((ModelBase)this, 16, 0); + this.Middle_plating.addBox(-3.0f, 0.0f, -3.0f, 6, 1, 6); + this.Middle_plating.setRotationPoint(0.0f, 15.0f, 0.0f); + this.Middle_plating.setTextureSize(64, 32); + this.Middle_plating.mirror = true; + this.setRotation(this.Middle_plating, 0.0f, 0.0f, 0.0f); + this.Shape3_1 = new ModelRenderer((ModelBase)this, 8, 8); + this.Shape3_1.addBox(2.0f, 0.0f, -1.0f, 1, 6, 2); + this.Shape3_1.setRotationPoint(0.0f, 11.0f, 0.0f); + this.Shape3_1.setTextureSize(64, 32); + this.Shape3_1.mirror = true; + this.setRotation(this.Shape3_1, 0.0f, -3.141593f, 0.0f); + this.Shape3_2 = new ModelRenderer((ModelBase)this, 8, 8); + this.Shape3_2.addBox(2.0f, 0.0f, -1.0f, 1, 6, 2); + this.Shape3_2.setRotationPoint(0.0f, 11.0f, 0.0f); + this.Shape3_2.setTextureSize(64, 32); + this.Shape3_2.mirror = true; + this.setRotation(this.Shape3_2, 0.0f, -1.570796f, 0.0f); + this.Shape3_3 = new ModelRenderer((ModelBase)this, 8, 8); + this.Shape3_3.addBox(2.0f, 0.0f, -1.0f, 1, 6, 2); + this.Shape3_3.setRotationPoint(0.0f, 11.0f, 0.0f); + this.Shape3_3.setTextureSize(64, 32); + this.Shape3_3.mirror = true; + this.setRotation(this.Shape3_3, 0.0f, 1.570796f, 0.0f); + this.Shape3_4 = new ModelRenderer((ModelBase)this, 8, 8); + this.Shape3_4.addBox(2.0f, 0.0f, -1.0f, 1, 6, 2); + this.Shape3_4.setRotationPoint(0.0f, 11.0f, 0.0f); + this.Shape3_4.setTextureSize(64, 32); + this.Shape3_4.mirror = true; + this.setRotation(this.Shape3_4, 0.0f, 0.0f, 0.0f); + this.LowerPlating_1 = new ModelRenderer((ModelBase)this, 40, 0); + this.LowerPlating_1.addBox(-2.0f, 0.0f, -2.0f, 4, 1, 4); + this.LowerPlating_1.setRotationPoint(0.0f, 18.0f, 0.0f); + this.LowerPlating_1.setTextureSize(64, 32); + this.LowerPlating_1.mirror = true; + this.setRotation(this.LowerPlating_1, 0.0f, 0.0f, 0.0f); + this.LowerPlating_2 = new ModelRenderer((ModelBase)this, 40, 0); + this.LowerPlating_2.addBox(-2.0f, 0.0f, -2.0f, 4, 1, 4); + this.LowerPlating_2.setRotationPoint(0.0f, 20.0f, 0.0f); + this.LowerPlating_2.setTextureSize(64, 32); + this.LowerPlating_2.mirror = true; + this.setRotation(this.LowerPlating_2, 0.0f, 0.0f, 0.0f); + this.Bump_1 = new ModelRenderer((ModelBase)this, 56, 0); + this.Bump_1.addBox(-0.5f, -0.5f, -0.5f, 1, 4, 1); + this.Bump_1.setRotationPoint(0.0f, 12.0f, 3.0f); + this.Bump_1.setTextureSize(64, 32); + this.Bump_1.mirror = true; + this.setRotation(this.Bump_1, 0.0f, 0.7853982f, 0.0f); + this.Bump_2 = new ModelRenderer((ModelBase)this, 56, 0); + this.Bump_2.addBox(-0.5f, -0.5f, -0.5f, 1, 4, 1); + this.Bump_2.setRotationPoint(3.0f, 12.0f, 0.0f); + this.Bump_2.setTextureSize(64, 32); + this.Bump_2.mirror = true; + this.setRotation(this.Bump_2, 0.0f, 0.7853982f, 0.0f); + this.Bump_3 = new ModelRenderer((ModelBase)this, 56, 0); + this.Bump_3.addBox(-0.5f, -0.5f, -0.5f, 1, 4, 1); + this.Bump_3.setRotationPoint(0.0f, 12.0f, -3.0f); + this.Bump_3.setTextureSize(64, 32); + this.Bump_3.mirror = true; + this.setRotation(this.Bump_3, 0.0f, 0.7853982f, 0.0f); + this.Bump_4 = new ModelRenderer((ModelBase)this, 56, 0); + this.Bump_4.addBox(-0.5f, -0.5f, -0.5f, 1, 4, 1); + this.Bump_4.setRotationPoint(-3.0f, 12.0f, 0.0f); + this.Bump_4.setTextureSize(64, 32); + this.Bump_4.mirror = true; + this.setRotation(this.Bump_4, 0.0f, 0.7853982f, 0.0f); + this.Cross = new ModelRenderer((ModelBase)this, 14, 8); + this.Cross.addBox(-0.5f, -0.5f, -0.5f, 3, 1, 3); + this.Cross.setRotationPoint(-1.5f, 11.0f, 0.0f); + this.Cross.setTextureSize(64, 32); + this.Cross.mirror = true; + this.setRotation(this.Cross, 0.0f, 0.7853982f, 0.0f); + } + + public void render(float rotation, float f5) { + this.Tip.render(f5); + this.Upper_plating.render(f5); + this.Middle_plating.render(f5); + this.Shape3_1.render(f5); + this.Shape3_2.render(f5); + this.Shape3_3.render(f5); + this.Shape3_4.render(f5); + this.LowerPlating_1.render(f5); + this.LowerPlating_2.render(f5); + this.Bump_1.render(f5); + this.Bump_2.render(f5); + this.Bump_3.render(f5); + this.Bump_4.render(f5); + this.Cross.render(f5); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelManipulator.java b/src/main/java/assemblyline/client/model/ModelManipulator.java new file mode 100644 index 0000000..05fe8e5 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelManipulator.java @@ -0,0 +1,189 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelManipulator +extends ModelBase { + ModelRenderer bBELTLong; + ModelRenderer FBELT; + ModelRenderer BacPanel; + ModelRenderer BBelt; + ModelRenderer FRL; + ModelRenderer MRL; + ModelRenderer FLL; + ModelRenderer BLL; + ModelRenderer MRoller; + ModelRenderer BRoller; + ModelRenderer tBELT; + ModelRenderer FRoller; + ModelRenderer BRL; + ModelRenderer BML; + ModelRenderer tBELTLong; + ModelRenderer RPanel; + ModelRenderer LPanel; + ModelRenderer TopPanel; + ModelRenderer RCPanel; + ModelRenderer LCPanel; + + public ModelManipulator() { + this.textureWidth = 128; + this.textureHeight = 128; + this.bBELTLong = new ModelRenderer((ModelBase)this, 0, 66); + this.bBELTLong.addBox(0.0f, 0.0f, 0.0f, 14, 1, 16); + this.bBELTLong.setRotationPoint(-7.0f, 22.0f, -8.0f); + this.bBELTLong.setTextureSize(128, 128); + this.bBELTLong.mirror = true; + this.setRotation(this.bBELTLong, 0.0f, 0.0f, 0.0f); + this.FBELT = new ModelRenderer((ModelBase)this, 0, 16); + this.FBELT.addBox(0.0f, 0.0f, 0.0f, 14, 2, 1); + this.FBELT.setRotationPoint(-7.0f, 20.0f, -8.0f); + this.FBELT.setTextureSize(128, 128); + this.FBELT.mirror = true; + this.setRotation(this.FBELT, 0.0f, 0.0f, 0.0f); + this.BacPanel = new ModelRenderer((ModelBase)this, 0, 86); + this.BacPanel.addBox(0.0f, -12.0f, 0.0f, 14, 12, 1); + this.BacPanel.setRotationPoint(-7.0f, 24.0f, 7.0f); + this.BacPanel.setTextureSize(128, 128); + this.BacPanel.mirror = true; + this.setRotation(this.BacPanel, 0.0f, 0.0f, 0.0f); + this.BBelt = new ModelRenderer((ModelBase)this, 0, 31); + this.BBelt.addBox(0.0f, 0.0f, 0.0f, 14, 1, 14); + this.BBelt.setRotationPoint(-7.0f, 22.0f, -7.0f); + this.BBelt.setTextureSize(128, 128); + this.BBelt.mirror = true; + this.setRotation(this.BBelt, 0.0f, 0.0f, 0.0f); + this.FRL = new ModelRenderer((ModelBase)this, 0, 20); + this.FRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.FRL.setRotationPoint(-8.0f, 21.0f, -6.0f); + this.FRL.setTextureSize(128, 128); + this.FRL.mirror = true; + this.setRotation(this.FRL, 0.0f, 0.0f, 0.0f); + this.MRL = new ModelRenderer((ModelBase)this, 0, 20); + this.MRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.MRL.setRotationPoint(-8.0f, 21.0f, -1.0f); + this.MRL.setTextureSize(128, 128); + this.MRL.mirror = true; + this.setRotation(this.MRL, 0.0f, 0.0f, 0.0f); + this.FLL = new ModelRenderer((ModelBase)this, 0, 20); + this.FLL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.FLL.setRotationPoint(7.0f, 21.0f, -6.0f); + this.FLL.setTextureSize(128, 128); + this.FLL.mirror = true; + this.setRotation(this.FLL, 0.0f, 0.0f, 0.0f); + this.BLL = new ModelRenderer((ModelBase)this, 0, 20); + this.BLL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BLL.setRotationPoint(7.0f, 21.0f, 4.0f); + this.BLL.setTextureSize(128, 128); + this.BLL.mirror = true; + this.setRotation(this.BLL, 0.0f, 0.0f, 0.0f); + this.MRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.MRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.MRoller.setRotationPoint(0.0f, 21.0f, 0.0f); + this.MRoller.setTextureSize(128, 128); + this.MRoller.mirror = true; + this.setRotation(this.MRoller, 0.0f, 0.0f, 0.0f); + this.BRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.BRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.BRoller.setRotationPoint(0.0f, 21.0f, 5.0f); + this.BRoller.setTextureSize(128, 128); + this.BRoller.mirror = true; + this.setRotation(this.BRoller, 0.0f, 0.0f, 0.0f); + this.tBELT = new ModelRenderer((ModelBase)this, 0, 0); + this.tBELT.addBox(0.0f, 0.0f, 0.0f, 14, 1, 14); + this.tBELT.setRotationPoint(-7.0f, 19.0f, -7.0f); + this.tBELT.setTextureSize(128, 128); + this.tBELT.mirror = true; + this.setRotation(this.tBELT, 0.0f, 0.0f, 0.0f); + this.FRoller = new ModelRenderer((ModelBase)this, 0, 26); + this.FRoller.addBox(-7.0f, -1.0f, -1.0f, 14, 2, 2); + this.FRoller.setRotationPoint(0.0f, 21.0f, -5.0f); + this.FRoller.setTextureSize(128, 128); + this.FRoller.mirror = true; + this.setRotation(this.FRoller, 0.0f, 0.0f, 0.0f); + this.BRL = new ModelRenderer((ModelBase)this, 0, 20); + this.BRL.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BRL.setRotationPoint(-8.0f, 21.0f, 4.0f); + this.BRL.setTextureSize(128, 128); + this.BRL.mirror = true; + this.setRotation(this.BRL, 0.0f, 0.0f, 0.0f); + this.BML = new ModelRenderer((ModelBase)this, 0, 20); + this.BML.addBox(0.0f, 0.0f, 0.0f, 1, 3, 2); + this.BML.setRotationPoint(7.0f, 21.0f, -1.0f); + this.BML.setTextureSize(128, 128); + this.BML.mirror = true; + this.setRotation(this.BML, 0.0f, 0.0f, 0.0f); + this.tBELTLong = new ModelRenderer((ModelBase)this, 0, 48); + this.tBELTLong.addBox(0.0f, 0.0f, 0.0f, 14, 1, 16); + this.tBELTLong.setRotationPoint(-7.0f, 19.0f, -8.0f); + this.tBELTLong.setTextureSize(128, 128); + this.tBELTLong.mirror = true; + this.setRotation(this.tBELTLong, 0.0f, 0.0f, 0.0f); + this.RPanel = new ModelRenderer((ModelBase)this, 65, 41); + this.RPanel.addBox(0.0f, -2.0f, -8.0f, 1, 4, 16); + this.RPanel.setRotationPoint(-8.0f, 19.0f, 0.0f); + this.RPanel.setTextureSize(128, 128); + this.RPanel.mirror = true; + this.setRotation(this.RPanel, 0.0f, 0.0f, 0.0f); + this.LPanel = new ModelRenderer((ModelBase)this, 65, 20); + this.LPanel.addBox(0.0f, -2.0f, -8.0f, 1, 4, 16); + this.LPanel.setRotationPoint(7.0f, 19.0f, 0.0f); + this.LPanel.setTextureSize(128, 128); + this.LPanel.mirror = true; + this.setRotation(this.LPanel, 0.0f, 0.0f, 0.0f); + this.TopPanel = new ModelRenderer((ModelBase)this, 0, 105); + this.TopPanel.addBox(0.0f, 0.0f, 0.0f, 14, 2, 10); + this.TopPanel.setRotationPoint(-7.0f, 12.0f, -3.0f); + this.TopPanel.setTextureSize(128, 128); + this.TopPanel.mirror = true; + this.setRotation(this.TopPanel, 0.0f, 0.0f, 0.0f); + this.RCPanel = new ModelRenderer((ModelBase)this, 50, 105); + this.RCPanel.addBox(-1.0f, 0.0f, 0.0f, 2, 5, 10); + this.RCPanel.setRotationPoint(-7.0f, 14.0f, -3.0f); + this.RCPanel.setTextureSize(128, 128); + this.RCPanel.mirror = true; + this.setRotation(this.RCPanel, 0.0f, 0.0f, 0.0f); + this.LCPanel = new ModelRenderer((ModelBase)this, 76, 105); + this.LCPanel.addBox(0.0f, 0.0f, 0.0f, 2, 5, 10); + this.LCPanel.setRotationPoint(6.0f, 14.0f, -3.0f); + this.LCPanel.setTextureSize(128, 128); + this.LCPanel.mirror = true; + this.setRotation(this.LCPanel, 0.0f, 0.0f, 0.0f); + } + + public void render(float f5, boolean isLongBelt, int radians) { + this.BacPanel.render(f5); + this.RPanel.render(f5); + this.LPanel.render(f5); + this.TopPanel.render(f5); + this.RCPanel.render(f5); + this.LCPanel.render(f5); + this.FRL.render(f5); + this.MRL.render(f5); + this.FLL.render(f5); + this.BLL.render(f5); + this.BRL.render(f5); + this.BML.render(f5); + this.MRoller.rotateAngleX = radians; + this.BRoller.rotateAngleX = radians; + this.FRoller.rotateAngleX = radians; + this.MRoller.render(f5); + this.BRoller.render(f5); + this.FRoller.render(f5); + if (isLongBelt) { + this.tBELTLong.render(f5); + this.bBELTLong.render(f5); + } else { + this.FBELT.render(f5); + this.tBELT.render(f5); + this.BBelt.render(f5); + } + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/model/ModelRejectorPiston.java b/src/main/java/assemblyline/client/model/ModelRejectorPiston.java new file mode 100644 index 0000000..d303968 --- /dev/null +++ b/src/main/java/assemblyline/client/model/ModelRejectorPiston.java @@ -0,0 +1,157 @@ +package assemblyline.client.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; + +public class ModelRejectorPiston +extends ModelBase { + ModelRenderer BodyBottom; + ModelRenderer PistonFace2; + ModelRenderer PistonShaft; + ModelRenderer Piston; + ModelRenderer H1; + ModelRenderer H2; + ModelRenderer H3; + ModelRenderer PistonFace; + ModelRenderer WireCCRight; + ModelRenderer WireCCLeft; + ModelRenderer BodyP2; + ModelRenderer BodyP1; + ModelRenderer LeftSide; + ModelRenderer RightSide; + ModelRenderer PistonBack; + ModelRenderer WireCCFront; + + public ModelRejectorPiston() { + this.textureWidth = 128; + this.textureHeight = 128; + this.BodyBottom = new ModelRenderer((ModelBase)this, 29, 69); + this.BodyBottom.addBox(-5.0f, 0.0f, -2.0f, 10, 5, 15); + this.BodyBottom.setRotationPoint(0.0f, 19.0f, -6.0f); + this.BodyBottom.setTextureSize(128, 128); + this.BodyBottom.mirror = true; + this.setRotation(this.BodyBottom, 0.0f, 0.0f, 0.0f); + this.PistonFace2 = new ModelRenderer((ModelBase)this, 0, 53); + this.PistonFace2.addBox(-2.0f, -2.0f, -1.0f, 4, 6, 1); + this.PistonFace2.setRotationPoint(0.0f, 15.0f, -6.0f); + this.PistonFace2.setTextureSize(128, 128); + this.PistonFace2.mirror = true; + this.setRotation(this.PistonFace2, 0.0f, 0.0f, 0.0f); + this.PistonShaft = new ModelRenderer((ModelBase)this, 0, 75); + this.PistonShaft.addBox(-1.5f, -1.5f, 0.0f, 3, 3, 10); + this.PistonShaft.setRotationPoint(0.0f, 16.0f, -6.0f); + this.PistonShaft.setTextureSize(128, 128); + this.PistonShaft.mirror = true; + this.setRotation(this.PistonShaft, 0.0f, 0.0f, 0.0f); + this.Piston = new ModelRenderer((ModelBase)this, 0, 22); + this.Piston.addBox(-3.0f, -1.0f, 0.0f, 6, 6, 10); + this.Piston.setRotationPoint(0.0f, 14.0f, -5.0f); + this.Piston.setTextureSize(128, 128); + this.Piston.mirror = true; + this.setRotation(this.Piston, 0.0f, 0.0f, 0.0f); + this.H1 = new ModelRenderer((ModelBase)this, 33, 23); + this.H1.addBox(-1.5f, 0.0f, 0.0f, 3, 1, 8); + this.H1.setRotationPoint(0.0f, 12.0f, -4.0f); + this.H1.setTextureSize(128, 128); + this.H1.mirror = true; + this.setRotation(this.H1, 0.0f, 0.0f, 0.0f); + this.H2 = new ModelRenderer((ModelBase)this, 90, 23); + this.H2.addBox(0.0f, -1.5f, 0.0f, 1, 3, 8); + this.H2.setRotationPoint(-4.0f, 16.0f, -4.0f); + this.H2.setTextureSize(128, 128); + this.H2.mirror = true; + this.setRotation(this.H2, 0.0f, 0.0f, 0.0f); + this.H3 = new ModelRenderer((ModelBase)this, 70, 23); + this.H3.addBox(0.0f, -1.5f, 0.0f, 1, 3, 8); + this.H3.setRotationPoint(3.0f, 16.0f, -4.0f); + this.H3.setTextureSize(128, 128); + this.H3.mirror = true; + this.setRotation(this.H3, 0.0f, 0.0f, 0.0f); + this.PistonFace = new ModelRenderer((ModelBase)this, 0, 62); + this.PistonFace.addBox(-3.0f, -2.0f, -1.0f, 6, 4, 1); + this.PistonFace.setRotationPoint(0.0f, 16.0f, -6.0f); + this.PistonFace.setTextureSize(128, 128); + this.PistonFace.mirror = true; + this.setRotation(this.PistonFace, 0.0f, 0.0f, 0.0f); + this.WireCCRight = new ModelRenderer((ModelBase)this, 69, 52); + this.WireCCRight.addBox(-3.0f, -3.0f, 0.0f, 6, 11, 1); + this.WireCCRight.setRotationPoint(0.0f, 16.0f, 7.0f); + this.WireCCRight.setTextureSize(128, 128); + this.WireCCRight.mirror = true; + this.setRotation(this.WireCCRight, 0.0f, 0.0f, 0.0f); + this.WireCCLeft = new ModelRenderer((ModelBase)this, 54, 37); + this.WireCCLeft.addBox(0.0f, -3.0f, -3.0f, 1, 8, 6); + this.WireCCLeft.setRotationPoint(7.0f, 16.0f, 0.0f); + this.WireCCLeft.setTextureSize(128, 128); + this.WireCCLeft.mirror = true; + this.setRotation(this.WireCCLeft, 0.0f, 0.0f, 0.0f); + this.BodyP2 = new ModelRenderer((ModelBase)this, 100, 60); + this.BodyP2.addBox(1.0f, -2.0f, -2.0f, 2, 7, 4); + this.BodyP2.setRotationPoint(-8.0f, 16.0f, 0.0f); + this.BodyP2.setTextureSize(128, 128); + this.BodyP2.mirror = true; + this.setRotation(this.BodyP2, 0.0f, 0.0f, 0.0f); + this.BodyP1 = new ModelRenderer((ModelBase)this, 87, 60); + this.BodyP1.addBox(3.0f, -2.0f, -2.0f, 2, 7, 4); + this.BodyP1.setRotationPoint(2.0f, 16.0f, 0.0f); + this.BodyP1.setTextureSize(128, 128); + this.BodyP1.mirror = true; + this.setRotation(this.BodyP1, 0.0f, 0.0f, 0.0f); + this.LeftSide = new ModelRenderer((ModelBase)this, 29, 91); + this.LeftSide.addBox(0.0f, 0.0f, -2.0f, 3, 3, 14); + this.LeftSide.setRotationPoint(5.0f, 21.0f, -5.0f); + this.LeftSide.setTextureSize(128, 128); + this.LeftSide.mirror = true; + this.setRotation(this.LeftSide, 0.0f, 0.0f, 0.0f); + this.RightSide = new ModelRenderer((ModelBase)this, 64, 91); + this.RightSide.addBox(0.0f, 0.0f, -2.0f, 3, 3, 14); + this.RightSide.setRotationPoint(-8.0f, 21.0f, -5.0f); + this.RightSide.setTextureSize(128, 128); + this.RightSide.mirror = true; + this.setRotation(this.RightSide, 0.0f, 0.0f, 0.0f); + this.PistonBack = new ModelRenderer((ModelBase)this, 0, 12); + this.PistonBack.addBox(-2.5f, -2.5f, -1.0f, 5, 5, 2); + this.PistonBack.setRotationPoint(0.0f, 16.0f, 6.0f); + this.PistonBack.setTextureSize(128, 128); + this.PistonBack.mirror = true; + this.setRotation(this.PistonBack, 0.0f, 0.0f, 0.0f); + this.WireCCFront = new ModelRenderer((ModelBase)this, 69, 37); + this.WireCCFront.addBox(0.0f, -3.0f, -3.0f, 1, 8, 6); + this.WireCCFront.setRotationPoint(-8.0f, 16.0f, 0.0f); + this.WireCCFront.setTextureSize(128, 128); + this.WireCCFront.mirror = true; + this.setRotation(this.WireCCFront, 0.0f, 0.0f, 0.0f); + } + + public void render(float f5) { + this.BodyBottom.render(f5); + this.Piston.render(f5); + this.H1.render(f5); + this.H2.render(f5); + this.H3.render(f5); + this.WireCCRight.render(f5); + this.WireCCLeft.render(f5); + this.BodyP2.render(f5); + this.BodyP1.render(f5); + this.LeftSide.render(f5); + this.RightSide.render(f5); + this.PistonBack.render(f5); + this.WireCCFront.render(f5); + } + + public void renderPiston(float f5, int p) { + this.PistonFace2.setRotationPoint(0.0f, 15.0f, -6.0f - (float)p); + this.PistonShaft.setRotationPoint(0.0f, 16.0f, -6.0f - (float)p); + this.PistonFace.setRotationPoint(0.0f, 16.0f, -6.0f - (float)p); + this.PistonFace2.render(f5); + this.PistonShaft.render(f5); + this.PistonFace.render(f5); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } +} + diff --git a/src/main/java/assemblyline/client/render/BlockRenderingHandler.java b/src/main/java/assemblyline/client/render/BlockRenderingHandler.java new file mode 100644 index 0000000..beef1e5 --- /dev/null +++ b/src/main/java/assemblyline/client/render/BlockRenderingHandler.java @@ -0,0 +1,97 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelConveyorBelt; +import assemblyline.client.model.ModelManipulator; +import assemblyline.client.model.ModelRejectorPiston; +import assemblyline.common.AssemblyLine; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; +import cpw.mods.fml.client.registry.RenderingRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.IBlockAccess; +import org.lwjgl.opengl.GL11; + +@SideOnly(value=Side.CLIENT) +public class BlockRenderingHandler +implements ISimpleBlockRenderingHandler { + public static BlockRenderingHandler instance = new BlockRenderingHandler(); + public static final int BLOCK_RENDER_ID = RenderingRegistry.getNextAvailableRenderId(); + private ModelConveyorBelt modelConveyorBelt = new ModelConveyorBelt(); + private ModelRejectorPiston modelEjector = new ModelRejectorPiston(); + private ModelManipulator modelInjector = new ModelManipulator(); + + @Override + public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { + if (block == AssemblyLine.blockConveyorBelt) { + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.0f, (float)1.5f, (float)0.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/belt/frame0.png")); + this.modelConveyorBelt.render(0.0625f, 0.0f, false, false, false, false); + GL11.glPopMatrix(); + } else if (block == AssemblyLine.blockRejector) { + FMLClientHandler.instance().getClient().getTextureManager(); + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/rejector.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.6f, (float)1.5f, (float)0.6f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + this.modelEjector.render(0.0625f); + this.modelEjector.renderPiston(0.0625f, 1); + GL11.glPopMatrix(); + } else if (block == AssemblyLine.blockManipulator) { + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/manipulator1.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.6f, (float)1.5f, (float)0.6f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + this.modelInjector.render(0.0625f, true, 0); + GL11.glPopMatrix(); + } else if (block == AssemblyLine.blockArmbot) { + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/armbot.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.4f, (float)0.8f, (float)0.0f); + GL11.glScalef((float)0.7f, (float)0.7f, (float)0.7f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + RenderArmbot.MODEL.render(0.0625f, 0.0f, 0.0f); + GL11.glPopMatrix(); + } else if (block == AssemblyLine.blockCraneController) { + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/crane_controller_off.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + RenderCraneController.MODEL.render(0.0625f, false, false); + GL11.glPopMatrix(); + } else if (block == AssemblyLine.blockCraneFrame) { + FMLClientHandler.instance().getClient().getTextureManager().bindTexture(new ResourceLocation("assemblyline", "textures/models/crane_frame.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + RenderCraneFrame.MODEL.render(true, true, false, false, false, false, false); + GL11.glPopMatrix(); + } + } + + @Override + public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { + return false; + } + + @Override + public boolean shouldRender3DInInventory(int par0) { + return true; + } + + @Override + public int getRenderId() { + return BLOCK_RENDER_ID; + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderArmbot.java b/src/main/java/assemblyline/client/render/RenderArmbot.java new file mode 100644 index 0000000..8540350 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderArmbot.java @@ -0,0 +1,58 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelArmbot; +import assemblyline.common.machine.armbot.TileEntityArmbot; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +public class RenderArmbot +extends TileEntitySpecialRenderer { + public static final ModelArmbot MODEL = new ModelArmbot(); + public static final String TEXTURE = "armbot.png"; + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { + if (tileEntity instanceof TileEntityArmbot) { + EntityClientPlayerMP player; + MovingObjectPosition objectPosition; + String cmdText = ((TileEntityArmbot)tileEntity).getCommandDisplayText(); + if (!(cmdText == null || cmdText.isEmpty() || (objectPosition = (player = Minecraft.getMinecraft().thePlayer).rayTrace(8.0, 1.0f)) == null || objectPosition.blockX != tileEntity.xCoord || objectPosition.blockY != tileEntity.yCoord && objectPosition.blockY != tileEntity.yCoord + 1 || objectPosition.blockZ != tileEntity.zCoord)) { + RenderHelper.renderFloatingText(cmdText, (float)x + 0.5f, (float)y + 0.25f, (float)z + 0.5f, 0xFFFFFF); + } + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/armbot.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)((float)x + 0.5f), (float)((float)y + 1.5f), (float)((float)z + 0.5f)); + GL11.glScalef((float)1.0f, (float)-1.0f, (float)-1.0f); + MODEL.render(0.0625f, ((TileEntityArmbot)tileEntity).renderYaw, ((TileEntityArmbot)tileEntity).renderPitch); + GL11.glPopMatrix(); + Vector3 handPosition = ((TileEntityArmbot)tileEntity).getDeltaHandPosition(); + handPosition.add(0.5); + handPosition.add(new Vector3(x, y, z)); + RenderItem renderItem = (RenderItem)RenderManager.instance.getEntityClassRenderObject(EntityItem.class); + TextureManager renderEngine = Minecraft.getMinecraft().renderEngine; + for (ItemStack itemStack : ((TileEntityArmbot)tileEntity).getGrabbedItems()) { + if (itemStack == null) continue; + if (((TileEntityArmbot)tileEntity).renderEntityItem == null) { + ((TileEntityArmbot)tileEntity).renderEntityItem = new EntityItem(tileEntity.getWorldObj(), 0.0, 0.0, 0.0, itemStack); + } else if (!itemStack.isItemEqual(((TileEntityArmbot)tileEntity).renderEntityItem.getEntityItem())) { + ((TileEntityArmbot)tileEntity).renderEntityItem = new EntityItem(tileEntity.getWorldObj(), 0.0, 0.0, 0.0, itemStack); + } + renderItem.doRender(((TileEntityArmbot)tileEntity).renderEntityItem, handPosition.x, handPosition.y, handPosition.z, 0.0f, f); + break; + } + } + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderConveyorBelt.java b/src/main/java/assemblyline/client/render/RenderConveyorBelt.java new file mode 100644 index 0000000..e730f1b --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderConveyorBelt.java @@ -0,0 +1,106 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelAngledBelt; +import assemblyline.client.model.ModelConveyorBelt; +import assemblyline.common.machine.belt.TileEntityConveyorBelt; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +@SideOnly(value=Side.CLIENT) +public class RenderConveyorBelt +extends TileEntitySpecialRenderer { + public static final ModelConveyorBelt MODEL = new ModelConveyorBelt(); + public static final ModelAngledBelt MODEL2 = new ModelAngledBelt(); + + private void renderAModelAt(TileEntityConveyorBelt tileEntity, double x, double y, double z, float f) { + boolean mid = tileEntity.getIsMiddleBelt(); + TileEntityConveyorBelt.SlantType slantType = tileEntity.getSlant(); + int face = tileEntity.getDirection().ordinal(); + GL11.glPushMatrix(); + GL11.glTranslatef((float)((float)x + 0.5f), (float)((float)y + 1.5f), (float)((float)z + 0.5f)); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + int frame = tileEntity.getAnimationFrame(); + if (slantType != null && slantType != TileEntityConveyorBelt.SlantType.NONE) { + boolean slantAdjust; + switch (face) { + case 2: { + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 3: { + GL11.glRotatef((float)0.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 4: { + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 5: { + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + } + if (slantType == TileEntityConveyorBelt.SlantType.UP) { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/slantedbelt/frame" + frame + ".png")); + GL11.glTranslatef((float)0.0f, (float)0.8f, (float)-0.8f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)1.0f); + slantAdjust = false; + TileEntity test = tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord + tileEntity.getDirection().offsetX, tileEntity.yCoord, tileEntity.zCoord + tileEntity.getDirection().offsetZ); + if (test != null && test instanceof TileEntityConveyorBelt && ((TileEntityConveyorBelt)test).getSlant() == TileEntityConveyorBelt.SlantType.TOP) { + GL11.glRotatef((float)10.0f, (float)1.0f, (float)0.0f, (float)0.0f); + slantAdjust = true; + } + MODEL2.render(0.0625f, true); + } else if (slantType == TileEntityConveyorBelt.SlantType.DOWN) { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/slantedbelt/frame" + frame + ".png")); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + slantAdjust = false; + TileEntity test = tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord - tileEntity.getDirection().offsetX, tileEntity.yCoord, tileEntity.zCoord - tileEntity.getDirection().offsetZ); + if (test != null && test instanceof TileEntityConveyorBelt && ((TileEntityConveyorBelt)test).getSlant() == TileEntityConveyorBelt.SlantType.TOP) { + GL11.glRotatef((float)-10.0f, (float)1.0f, (float)0.0f, (float)0.0f); + GL11.glTranslatef((float)0.0f, (float)0.25f, (float)0.0f); + slantAdjust = true; + } + MODEL2.render(0.0625f, slantAdjust); + } else { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/belt/frame" + frame + ".png")); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glTranslatef((float)0.0f, (float)-0.68f, (float)0.0f); + MODEL.render(0.0625f, (float)Math.toRadians(tileEntity.wheelRotation), tileEntity.getIsLastBelt(), tileEntity.getIsFirstBelt(), false, false); + } + } else { + switch (face) { + case 2: { + GL11.glRotatef((float)0.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 3: { + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 4: { + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 5: { + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + } + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/belt/frame" + frame + ".png")); + MODEL.render(0.0625f, (float)Math.toRadians(tileEntity.wheelRotation), tileEntity.getIsLastBelt(), tileEntity.getIsFirstBelt(), false, true); + } + Block ent = tileEntity.getWorldObj().getBlock(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); + GL11.glPopMatrix(); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { + this.renderAModelAt((TileEntityConveyorBelt)tileEntity, var2, var4, var6, var8); + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderCraneController.java b/src/main/java/assemblyline/client/render/RenderCraneController.java new file mode 100644 index 0000000..273cd53 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderCraneController.java @@ -0,0 +1,53 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelCraneController; +import assemblyline.common.machine.crane.CraneHelper; +import assemblyline.common.machine.crane.TileEntityCraneController; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +public class RenderCraneController +extends RenderImprintable { + public static final String TEXTURE = "crane_controller_off.png"; + public static final String TEXTURE_VALID = "crane_controller_on.png"; + public static final ModelCraneController MODEL = new ModelCraneController(); + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { + if (tileEntity != null && tileEntity instanceof TileEntityCraneController) { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/" + (((TileEntityCraneController)tileEntity).isCraneValid() ? TEXTURE_VALID : TEXTURE))); + ForgeDirection front = ForgeDirection.getOrientation((int)tileEntity.getWorldObj().getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord)); + ForgeDirection right = CraneHelper.rotateClockwise(front); + float angle = 0.0f; + switch (front) { + case NORTH: { + angle = 90.0f; + break; + } + case SOUTH: { + angle = 270.0f; + break; + } + case EAST: { + angle = 180.0f; + } + } + int tX = tileEntity.xCoord; + int tY = tileEntity.yCoord; + int tZ = tileEntity.zCoord; + boolean connectFront = CraneHelper.canFrameConnectTo(tileEntity, tX + front.offsetX, tY, tZ + front.offsetZ, front.getOpposite()); + boolean connectRight = CraneHelper.canFrameConnectTo(tileEntity, tX + right.offsetX, tY, tZ + right.offsetZ, right.getOpposite()); + GL11.glPushMatrix(); + GL11.glTranslated((double)(x + 0.5), (double)(y + 1.5), (double)(z + 0.5)); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glRotatef((float)angle, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glEnable((int)2896); + MODEL.render(0.0625f, connectRight, connectFront); + GL11.glPopMatrix(); + } + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderCraneFrame.java b/src/main/java/assemblyline/client/render/RenderCraneFrame.java new file mode 100644 index 0000000..b7e4932 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderCraneFrame.java @@ -0,0 +1,44 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelCraneRail; +import assemblyline.common.machine.crane.CraneHelper; +import assemblyline.common.machine.crane.TileEntityCraneRail; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +public class RenderCraneFrame +extends TileEntitySpecialRenderer { + public static final String TEXTURE = "crane_frame.png"; + public static final ModelCraneRail MODEL = new ModelCraneRail(); + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { + if (tileEntity != null && tileEntity instanceof TileEntityCraneRail) { + int tX = tileEntity.xCoord; + int tY = tileEntity.yCoord; + int tZ = tileEntity.zCoord; + boolean renderUp = CraneHelper.canFrameConnectTo(tileEntity, tX, tY + 1, tZ, ForgeDirection.DOWN); + boolean renderDown = CraneHelper.canFrameConnectTo(tileEntity, tX, tY - 1, tZ, ForgeDirection.UP); + boolean renderLeft = CraneHelper.canFrameConnectTo(tileEntity, tX - 1, tY, tZ, ForgeDirection.EAST); + boolean renderRight = CraneHelper.canFrameConnectTo(tileEntity, tX + 1, tY, tZ, ForgeDirection.WEST); + boolean renderFront = CraneHelper.canFrameConnectTo(tileEntity, tX, tY, tZ - 1, ForgeDirection.SOUTH); + boolean renderBack = CraneHelper.canFrameConnectTo(tileEntity, tX, tY, tZ + 1, ForgeDirection.NORTH); + boolean renderFoot = tileEntity.getWorldObj().isSideSolid(tX, tY - 1, tZ, ForgeDirection.UP); + if (renderLeft && renderRight || renderFront && renderBack) { + renderFoot = false; + } + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/crane_frame.png")); + GL11.glPushMatrix(); + GL11.glTranslated((double)(x + 0.5), (double)(y + 1.5), (double)(z + 0.5)); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + GL11.glEnable((int)2896); + MODEL.render(renderUp, renderDown && !renderFoot, renderLeft, renderRight, renderFront, renderBack, renderFoot); + GL11.glPopMatrix(); + } + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderCrate.java b/src/main/java/assemblyline/client/render/RenderCrate.java new file mode 100644 index 0000000..5b94660 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderCrate.java @@ -0,0 +1,158 @@ +package assemblyline.client.render; + +import assemblyline.common.block.TileEntityCrate; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.client.ForgeHooksClient; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +public class RenderCrate +extends TileEntitySpecialRenderer { + private final RenderBlocks renderBlocks = new RenderBlocks(); + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) { + Vector3 vec = new Vector3(x, y, z); + double distance = vec.distanceTo(new Vector3(0.0, 0.0, 0.0)); + if (tileEntity instanceof TileEntityCrate && distance < 15.0) { + TileEntityCrate tileCrate = (TileEntityCrate)tileEntity; + RenderItem renderItem = (RenderItem)RenderManager.instance.getEntityClassRenderObject(EntityItem.class); + String itemName = "Empty"; + String amount = ""; + ItemStack itemStack = tileCrate.getStackInSlot(0); + if (itemStack != null) { + itemName = itemStack.getDisplayName(); + amount = Integer.toString(itemStack.stackSize); + } + for (int side = 2; side < 6; ++side) { + ForgeDirection direction = ForgeDirection.getOrientation((int)side); + if (tileCrate.getWorldObj().isSideSolid(tileCrate.xCoord + direction.offsetX, tileCrate.yCoord, tileCrate.zCoord + direction.offsetZ, direction.getOpposite())) continue; + this.setupLight(tileCrate, direction.offsetX, direction.offsetZ); + OpenGlHelper.setLightmapTextureCoords((int)OpenGlHelper.lightmapTexUnit, (float)240.0f, (float)240.0f); + if (itemStack != null) { + GL11.glPushMatrix(); + switch (side) { + case 2: { + GL11.glTranslated((double)(x + 0.65), (double)(y + 0.9), (double)(z - 0.01)); + break; + } + case 3: { + GL11.glTranslated((double)(x + 0.35), (double)(y + 0.9), (double)(z + 1.01)); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 4: { + GL11.glTranslated((double)(x - 0.01), (double)(y + 0.9), (double)(z + 0.35)); + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + break; + } + case 5: { + GL11.glTranslated((double)(x + 1.01), (double)(y + 0.9), (double)(z + 0.65)); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + } + float scale = 0.03125f; + GL11.glScalef((float)(0.6f * scale), (float)(0.6f * scale), (float)0.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + TextureManager renderEngine = Minecraft.getMinecraft().renderEngine; + GL11.glDisable((int)2896); + if (!ForgeHooksClient.renderInventoryItem((RenderBlocks)this.renderBlocks, renderEngine, (ItemStack)itemStack, (boolean)true, (float)0.0f, (float)0.0f, (float)0.0f)) { + renderItem.renderItemIntoGUI(this.func_147498_b(), renderEngine, itemStack, 0, 0); + } + GL11.glEnable((int)2896); + GL11.glPopMatrix(); + } + this.renderText(itemName, side, 0.02f, x, y - (double)0.35f, z); + if (amount == "") continue; + this.renderText(amount, side, 0.02f, x, y - (double)0.15f, z); + } + } + } + + private void setupLight(TileEntity tileEntity, int xDifference, int zDifference) { + World world = tileEntity.getWorldObj(); + if (world.getBlock(tileEntity.xCoord + xDifference, tileEntity.yCoord, tileEntity.zCoord + zDifference).isOpaqueCube()) { + return; + } + int br = world.getLightBrightnessForSkyBlocks(tileEntity.xCoord + xDifference, tileEntity.yCoord, tileEntity.zCoord + zDifference, 0); + int var11 = br % 65536; + int var12 = br / 65536; + float scale = 0.6f; + OpenGlHelper.setLightmapTextureCoords((int)OpenGlHelper.lightmapTexUnit, (float)((float)var11 * scale), (float)((float)var12 * scale)); + } + + private void renderText(String text, int side, float maxScale, double x, double y, double z) { + GL11.glPushMatrix(); + GL11.glPolygonOffset((float)-10.0f, (float)-10.0f); + GL11.glEnable((int)32823); + float displayX = 0.0f; + float displayY = 0.0f; + float displayWidth = 1.0f; + float displayHeight = 1.0f; + GL11.glTranslated((double)x, (double)y, (double)z); + switch (side) { + case 3: { + GL11.glTranslatef((float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)0.0f, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)90.0f, (float)1.0f, (float)0.0f, (float)0.0f); + break; + } + case 2: { + GL11.glTranslatef((float)1.0f, (float)1.0f, (float)1.0f); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)90.0f, (float)1.0f, (float)0.0f, (float)0.0f); + break; + } + case 5: { + GL11.glTranslatef((float)0.0f, (float)1.0f, (float)1.0f); + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)90.0f, (float)1.0f, (float)0.0f, (float)0.0f); + break; + } + case 4: { + GL11.glTranslatef((float)1.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)-90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)90.0f, (float)1.0f, (float)0.0f, (float)0.0f); + } + } + GL11.glTranslatef((float)(displayWidth / 2.0f), (float)1.0f, (float)(displayHeight / 2.0f)); + GL11.glRotatef((float)-90.0f, (float)1.0f, (float)0.0f, (float)0.0f); + FontRenderer fontRenderer = super.func_147498_b(); + int requiredWidth = Math.max(fontRenderer.getStringWidth(text), 1); + int lineHeight = fontRenderer.FONT_HEIGHT + 2; + int requiredHeight = lineHeight * 1; + float scaler = 0.8f; + float scaleX = displayWidth / (float)requiredWidth; + float scaleY = displayHeight / (float)requiredHeight; + float scale = scaleX * scaler; + if (maxScale > 0.0f) { + scale = Math.min(scale, maxScale); + } + GL11.glScalef((float)scale, (float)(-scale), (float)scale); + GL11.glDepthMask((boolean)false); + int realHeight = (int)Math.floor(displayHeight / scale); + int realWidth = (int)Math.floor(displayWidth / scale); + int offsetX = (realWidth - requiredWidth) / 2; + int offsetY = (realHeight - requiredHeight) / 2; + GL11.glDisable((int)2896); + fontRenderer.drawString("\u00a7f" + text, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2, 1); + GL11.glEnable((int)2896); + GL11.glDepthMask((boolean)true); + GL11.glDisable((int)32823); + GL11.glPopMatrix(); + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderDetector.java b/src/main/java/assemblyline/client/render/RenderDetector.java new file mode 100644 index 0000000..368f1e3 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderDetector.java @@ -0,0 +1,38 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelHelper; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.tileentity.TileEntity; +import org.lwjgl.opengl.GL11; +import universalelectricity.core.vector.Vector3; + +@SideOnly(value=Side.CLIENT) +public class RenderDetector +extends RenderImprintable { + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) { + super.renderTileEntityAt(tileEntity, x, y, z, var8); + } + + public static void render(boolean isInverted, Vector3 position) { //TODO: WTF + GL11.glPushMatrix(); + GL11.glTranslated((double)position.x, (double)position.y, (double)position.z); + if (isInverted) { + // empty if block + } + ModelHelper.setGlobalTextureResolution(128, 128); + ModelHelper.setTextureClip(false); + ModelHelper.setTextureOffset(0, 64); + ModelHelper.setTextureSubResolution(64, 64); + ModelHelper.drawCuboid(0.45f, 0.75f, 0.45f, 0.125f, 0.25f, 0.125f); + ModelHelper.setTextureOffset(0, 0); + ModelHelper.setTextureSubResolution(128, 64); + ModelHelper.drawCuboid(0.25f, 0.25f, 0.25f, 0.5f, 0.5f, 0.5f); + ModelHelper.setTextureOffset(64, 64); + ModelHelper.setTextureSubResolution(64, 32); + ModelHelper.drawCuboid(0.375f, 0.1875f, 0.375f, 0.25f, 0.0625f, 0.25f); + GL11.glPopMatrix(); + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderHelper.java b/src/main/java/assemblyline/client/render/RenderHelper.java new file mode 100644 index 0000000..8d2e8f4 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderHelper.java @@ -0,0 +1,54 @@ +package assemblyline.client.render; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; +import org.lwjgl.opengl.GL11; + +public class RenderHelper { + public static void renderFloatingText(String text, float x, float y, float z) { + RenderHelper.renderFloatingText(text, x, y, z, 0xFFFFFF); + } + + public static void renderFloatingText(String text, float x, float y, float z, int color) { + RenderManager renderManager = RenderManager.instance; + FontRenderer fontRenderer = renderManager.getFontRenderer(); + float scale = 0.027f; + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)0.5f); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(x + 0.0f), (float)(y + 2.3f), (float)z); + GL11.glNormal3f((float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)(-renderManager.playerViewY), (float)0.0f, (float)1.0f, (float)0.0f); + GL11.glRotatef((float)renderManager.playerViewX, (float)1.0f, (float)0.0f, (float)0.0f); + GL11.glScalef((float)(-scale), (float)(-scale), (float)scale); + GL11.glDisable((int)2896); + OpenGlHelper.setLightmapTextureCoords((int)OpenGlHelper.lightmapTexUnit, (float)240.0f, (float)240.0f); + GL11.glDepthMask((boolean)false); + GL11.glDisable((int)2929); + GL11.glEnable((int)3042); + GL11.glBlendFunc((int)770, (int)771); + Tessellator tessellator = Tessellator.instance; + int yOffset = 0; + GL11.glDisable((int)3553); + tessellator.startDrawingQuads(); + int stringMiddle = fontRenderer.getStringWidth(text) / 2; + tessellator.setColorRGBA_F(0.0f, 0.0f, 0.0f, 0.5f); + tessellator.addVertex((double)(-stringMiddle - 1), (double)(-1 + yOffset), 0.0); + tessellator.addVertex((double)(-stringMiddle - 1), (double)(8 + yOffset), 0.0); + tessellator.addVertex((double)(stringMiddle + 1), (double)(8 + yOffset), 0.0); + tessellator.addVertex((double)(stringMiddle + 1), (double)(-1 + yOffset), 0.0); + tessellator.draw(); + GL11.glEnable((int)3553); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)0.5f); + fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color); + GL11.glEnable((int)2929); + GL11.glDepthMask((boolean)true); + fontRenderer.drawString(text, -fontRenderer.getStringWidth(text) / 2, yOffset, color); + GL11.glEnable((int)2896); + GL11.glDisable((int)3042); + GL11.glColor4f((float)1.0f, (float)1.0f, (float)1.0f, (float)1.0f); + GL11.glPopMatrix(); + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderImprintable.java b/src/main/java/assemblyline/client/render/RenderImprintable.java new file mode 100644 index 0000000..242c0a4 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderImprintable.java @@ -0,0 +1,34 @@ +package assemblyline.client.render; + +import assemblyline.common.machine.imprinter.ItemImprinter; +import assemblyline.common.machine.imprinter.TileEntityFilterable; +import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; + +public abstract class RenderImprintable +extends TileEntitySpecialRenderer { + @Override + public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) { + EntityClientPlayerMP player; + MovingObjectPosition objectPosition; + TileEntityFilterable tileFilterable; + ItemStack filter; + if (tileEntity != null && tileEntity instanceof TileEntityFilterable && (filter = (tileFilterable = (TileEntityFilterable)tileEntity).getFilter()) != null && (objectPosition = (player = Minecraft.getMinecraft().thePlayer).rayTrace(8.0, 1.0f)) != null && objectPosition.blockX == tileFilterable.xCoord && objectPosition.blockY == tileFilterable.yCoord && objectPosition.blockZ == tileFilterable.zCoord) { + ArrayList filters = ItemImprinter.getFilters(filter); + for (int i = 0; i < filters.size(); ++i) { + if (((TileEntityFilterable)tileEntity).isInverted()) { + RenderHelper.renderFloatingText(((ItemStack)filters.get(i)).getTooltip((EntityPlayer)player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float)x + 0.5f, (float)y + (float)i * 0.25f - 1.0f, (float)z + 0.5f, 0xFF8888); + continue; + } + RenderHelper.renderFloatingText(((ItemStack)filters.get(i)).getTooltip((EntityPlayer)player, Minecraft.getMinecraft().gameSettings.advancedItemTooltips).get(0).toString(), (float)x + 0.5f, (float)y + (float)i * 0.25f - 1.0f, (float)z + 0.5f, 0x88FF88); + } + } + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderManipulator.java b/src/main/java/assemblyline/client/render/RenderManipulator.java new file mode 100644 index 0000000..5631667 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderManipulator.java @@ -0,0 +1,43 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelManipulator; +import assemblyline.common.machine.TileEntityManipulator; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +public class RenderManipulator +extends RenderImprintable { + private ModelManipulator model = new ModelManipulator(); + + private void renderAModelAt(TileEntityManipulator tileEntity, double x, double y, double z, float f) { + int face = tileEntity.getDirection().ordinal(); + GL11.glPushMatrix(); + GL11.glTranslatef((float)((float)x + 0.5f), (float)((float)y + 1.5f), (float)((float)z + 0.5f)); + GL11.glRotatef((float)180.0f, (float)0.0f, (float)0.0f, (float)1.0f); + if (tileEntity.isOutput()) { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/manipulator1.png")); + } else { + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/manipulator2.png")); + } + if (face == 2) { + GL11.glRotatef((float)0.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } else if (face == 3) { + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } else if (face == 4) { + GL11.glRotatef((float)270.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } else if (face == 5) { + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + this.model.render(0.0625f, true, 0); + GL11.glPopMatrix(); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { + this.renderAModelAt((TileEntityManipulator)tileEntity, var2, var4, var6, var8); + super.renderTileEntityAt(tileEntity, var2, var4, var6, var8); + } +} + diff --git a/src/main/java/assemblyline/client/render/RenderRejector.java b/src/main/java/assemblyline/client/render/RenderRejector.java new file mode 100644 index 0000000..9dd0711 --- /dev/null +++ b/src/main/java/assemblyline/client/render/RenderRejector.java @@ -0,0 +1,46 @@ +package assemblyline.client.render; + +import assemblyline.client.model.ModelRejectorPiston; +import assemblyline.common.machine.TileEntityRejector; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +public class RenderRejector +extends RenderImprintable { + private ModelRejectorPiston model = new ModelRejectorPiston(); + + private void renderAModelAt(TileEntityRejector tileEntity, double x, double y, double z, float f) { + boolean fire = tileEntity.firePiston; + int face = tileEntity.getDirection().ordinal(); + int pos = 0; + if (fire) { + pos = 8; + } + this.bindTexture(new ResourceLocation("assemblyline", "textures/models/rejector.png")); + GL11.glPushMatrix(); + GL11.glTranslatef((float)((float)x + 0.5f), (float)((float)y + 1.5f), (float)((float)z + 0.5f)); + GL11.glScalef((float)1.0f, (float)-1.0f, (float)-1.0f); + if (face == 2) { + GL11.glRotatef((float)180.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + if (face == 3) { + GL11.glRotatef((float)0.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } else if (face == 4) { + GL11.glRotatef((float)90.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } else if (face == 5) { + GL11.glRotatef((float)270.0f, (float)0.0f, (float)1.0f, (float)0.0f); + } + this.model.render(0.0625f); + this.model.renderPiston(0.0625f, pos); + GL11.glPopMatrix(); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) { + this.renderAModelAt((TileEntityRejector)tileEntity, var2, var4, var6, var8); + super.renderTileEntityAt(tileEntity, var2, var4, var6, var8); + } +} + diff --git a/src/main/java/assemblyline/common/AssemblyLine.java b/src/main/java/assemblyline/common/AssemblyLine.java new file mode 100644 index 0000000..50005d7 --- /dev/null +++ b/src/main/java/assemblyline/common/AssemblyLine.java @@ -0,0 +1,184 @@ +package assemblyline.common; + +import assemblyline.common.CommonProxy; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockCrate; +import assemblyline.common.block.BlockTurntable; +import assemblyline.common.block.ItemBlockCrate; +import assemblyline.common.machine.BlockManipulator; +import assemblyline.common.machine.BlockRejector; +import assemblyline.common.machine.armbot.BlockArmbot; +import assemblyline.common.machine.belt.BlockConveyorBelt; +import assemblyline.common.machine.command.GrabDictionary; +import assemblyline.common.machine.crane.BlockCraneController; +import assemblyline.common.machine.crane.BlockCraneFrame; +import assemblyline.common.machine.detector.BlockDetector; +import assemblyline.common.machine.encoder.BlockEncoder; +import assemblyline.common.machine.encoder.ItemDisk; +import assemblyline.common.machine.imprinter.BlockImprinter; +import assemblyline.common.machine.imprinter.ItemImprinter; +import assemblyline.common.network.MessageEncoder; +import assemblyline.common.network.MessageEncoderHandler; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.ModMetadata; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import java.io.File; +import java.util.Arrays; +import java.util.logging.Logger; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import universalelectricity.prefab.TranslationHelper; +import universalelectricity.prefab.multiblock.BlockMulti; + +@Mod(modid="AssemblyLine", name="Assembly Line", version="0.3.5.117", dependencies="after:BasicComponents; after:IC2", useMetadata=true) +public class AssemblyLine { + public static final String MAJOR_VERSION = "0"; + public static final String MINOR_VERSION = "3"; + public static final String REVIS_VERSION = "5"; + public static final String BUILD_VERSION = "117"; + public static final String MOD_ID = "AssemblyLine"; + public static final String MOD_NAME = "Assembly Line"; + public static final String VERSION = "0.3.5.117"; + public static final String CHANNEL = "AssemblyLine"; + @SidedProxy(clientSide="assemblyline.client.ClientProxy", serverSide="assemblyline.common.CommonProxy") + public static CommonProxy proxy; + @Mod.Instance(value="AssemblyLine") + public static AssemblyLine instance; + @Mod.Metadata(value="AssemblyLine") + public static ModMetadata meta; + public static final String LANGUAGE_PATH = "/assets/assemblyline/languages/"; + private static final String[] LANGUAGES_SUPPORTED; + public static final Configuration CONFIGURATION; + public static final int BLOCK_ID_PREFIX = 3030; + public static Block blockConveyorBelt; + public static Block blockManipulator; + public static BlockCrate blockCrate; + public static Block blockImprinter; + public static Block blockEncoder; + public static Block blockDetector; + public static Block blockRejector; + public static Block blockArmbot; + public static Block blockCraneController; + public static Block blockCraneFrame; + public static Block blockTurntable; + public static BlockMulti blockMulti; + public static final int ITEM_ID_PREFIX = 13030; + public static Item itemImprint; + public static Item itemDisk; + public static ItemStack ic2Wrench; + public static Logger FMLog; + public static final boolean DEBUG = false; + public static boolean REQUIRE_NO_POWER; + public static SimpleNetworkWrapper NETWORK; + + @EventHandler + public void preInit(FMLPreInitializationEvent event) { + //FMLog.setParent(FMLLog.getLogger()); + instance = this; + CONFIGURATION.load(); + blockConveyorBelt = new BlockConveyorBelt(); + blockManipulator = new BlockManipulator(); + blockCrate = new BlockCrate(); + blockImprinter = new BlockImprinter(); + blockDetector = new BlockDetector(); + blockRejector = new BlockRejector(); + blockEncoder = new BlockEncoder(); + blockArmbot = new BlockArmbot(); + blockMulti = new BlockMulti(); + blockCraneController = new BlockCraneController(); + blockCraneFrame = new BlockCraneFrame(); + blockTurntable = new BlockTurntable(); + itemImprint = new ItemImprinter(); + itemDisk = new ItemDisk(); + REQUIRE_NO_POWER = !CONFIGURATION.get("general", "requirePower", true).getBoolean(true); + CONFIGURATION.save(); + NetworkRegistry.INSTANCE.registerGuiHandler((Object)this, (IGuiHandler)proxy); + NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID); + NETWORK.registerMessage(new MessageEncoderHandler(), MessageEncoder.class, 0, Side.SERVER); + GameRegistry.registerBlock(blockConveyorBelt, "conveyor_belt"); + GameRegistry.registerBlock(blockCrate, ItemBlockCrate.class, "crate"); + GameRegistry.registerBlock(blockManipulator, "manipulator"); + GameRegistry.registerBlock(blockImprinter, "imprinter"); + GameRegistry.registerBlock(blockEncoder, "encoder"); + GameRegistry.registerBlock(blockDetector, "detector"); + GameRegistry.registerBlock(blockRejector, "rejector"); + GameRegistry.registerBlock(blockArmbot, "armbot"); + GameRegistry.registerBlock(blockTurntable, "turntable"); + GameRegistry.registerBlock(blockCraneController, "crane_controller"); + GameRegistry.registerBlock(blockCraneFrame, "crane_frame"); + GameRegistry.registerItem(itemDisk, "disk"); + GameRegistry.registerItem(itemImprint, "imprint"); + TabAssemblyLine.itemStack = new ItemStack(blockConveyorBelt); + proxy.preInit(); + } + + @EventHandler + public void load(FMLInitializationEvent evt) { + proxy.init(); + GrabDictionary.registerList(); + FMLog.info("Loaded: " + TranslationHelper.loadLanguages(LANGUAGE_PATH, LANGUAGES_SUPPORTED) + " languages."); + AssemblyLine.meta.modId = "AssemblyLine"; + AssemblyLine.meta.name = MOD_NAME; + AssemblyLine.meta.description = "A mod that brings conveyor belt transporting systems to Minecraft."; + AssemblyLine.meta.url = "http://calclavia.com/universalelectricity/?m=18"; + AssemblyLine.meta.logoFile = "/al_logo.png"; + AssemblyLine.meta.version = VERSION; + AssemblyLine.meta.authorList = Arrays.asList("DarkGuardsman, Briaman, Calclavia"); + AssemblyLine.meta.credits = "Please see the website."; + AssemblyLine.meta.autogenerated = false; + this.createStandardRecipes(); + this.createUERecipes(); + } + + private void createUERecipes() { + System.out.println("BasicComponents Found...adding UE recipes for Assembly Line."); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockArmbot, new Object[]{"II ", "SIS", "MCM", Character.valueOf('S'), "plateSteel", Character.valueOf('C'), "advancedCircuit", Character.valueOf('I'), "ingotSteel", Character.valueOf('M'), "motor"})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(itemDisk, new Object[]{"III", "ICI", "III", Character.valueOf('I'), itemImprint, Character.valueOf('C'), "advancedCircuit"})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockEncoder, new Object[]{"SIS", "SCS", "SSS", Character.valueOf('I'), itemImprint, Character.valueOf('S'), "ingotSteel", Character.valueOf('C'), "advancedCircuit"})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockDetector, new Object[]{"SES", "SCS", "S S", Character.valueOf('S'), "ingotSteel", Character.valueOf('C'), "basicCircuit", Character.valueOf('E'), Items.ender_eye})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 10), new Object[]{"III", "WMW", Character.valueOf('I'), "ingotSteel", Character.valueOf('W'), Blocks.planks, Character.valueOf('M'), "motor"})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockRejector, new Object[]{"WPW", "@R@", Character.valueOf('@'), "ingotSteel", Character.valueOf('R'), Items.redstone, Character.valueOf('P'), Blocks.piston, Character.valueOf('C'), "basicCircuit", Character.valueOf('W'), "copperWire"})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockTurntable, new Object[]{"M", "P", Character.valueOf('M'), "motor", Character.valueOf('P'), Blocks.piston})); + GameRegistry.addRecipe((IRecipe)new ShapelessOreRecipe(new ItemStack(blockManipulator, 2), new Object[]{Blocks.dispenser, "basicCircuit"})); + } + + private void createStandardRecipes() { + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(new ItemStack(itemImprint, 2), new Object[]{"R", "P", "I", Character.valueOf('P'), Items.paper, Character.valueOf('R'), Items.redstone, Character.valueOf('I'), new ItemStack(Items.dye, 1, 0)})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(blockImprinter, new Object[]{"SIS", "SPS", "WCW", Character.valueOf('S'), Items.iron_ingot, Character.valueOf('C'), Blocks.chest, Character.valueOf('W'), Blocks.crafting_table, Character.valueOf('P'), Blocks.piston, Character.valueOf('I'), new ItemStack(Items.dye, 1, 0)})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(new ItemStack(blockCrate, 1, 0), new Object[]{"TST", "S S", "TST", Character.valueOf('S'), Items.iron_ingot, Character.valueOf('T'), Blocks.log})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(new ItemStack(blockCrate, 1, 1), new Object[]{"TST", "SCS", "TST", Character.valueOf('C'), new ItemStack(blockCrate, 1, 0), Character.valueOf('S'), Items.iron_ingot, Character.valueOf('T'), Blocks.log})); + GameRegistry.addRecipe((IRecipe)new ShapedOreRecipe(new ItemStack(blockCrate, 1, 2), new Object[]{"TST", "SCS", "TST", Character.valueOf('C'), new ItemStack(blockCrate, 1, 1), Character.valueOf('S'), Items.iron_ingot, Character.valueOf('T'), Blocks.log})); + } + + public static void printSidedData(String data) { + System.out.print(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT ? "[C]" : "[S]"); + System.out.println(" " + data); + } + + static { + LANGUAGES_SUPPORTED = new String[]{"en_US"}; + CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity/AssemblyLine.cfg")); + ic2Wrench = null; + FMLog = Logger.getLogger(MOD_NAME); + REQUIRE_NO_POWER = false; + } +} + diff --git a/src/main/java/assemblyline/common/CommonProxy.java b/src/main/java/assemblyline/common/CommonProxy.java new file mode 100644 index 0000000..8413c43 --- /dev/null +++ b/src/main/java/assemblyline/common/CommonProxy.java @@ -0,0 +1,114 @@ +package assemblyline.common; + +import assemblyline.common.block.TileEntityCrate; +import assemblyline.common.machine.TileEntityManipulator; +import assemblyline.common.machine.TileEntityRejector; +import assemblyline.common.machine.armbot.TileEntityArmbot; +import assemblyline.common.machine.belt.TileEntityConveyorBelt; +import assemblyline.common.machine.crane.TileEntityCraneController; +import assemblyline.common.machine.crane.TileEntityCraneRail; +import assemblyline.common.machine.detector.TileEntityDetector; +import assemblyline.common.machine.encoder.ContainerEncoder; +import assemblyline.common.machine.encoder.TileEntityEncoder; +import assemblyline.common.machine.imprinter.ContainerImprinter; +import assemblyline.common.machine.imprinter.TileEntityImprinter; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.common.registry.GameRegistry; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.prefab.multiblock.TileEntityMulti; + +public class CommonProxy +implements IGuiHandler { + public static final int GUI_IMPRINTER = 1; + public static final int GUI_ENCODER = 2; + + public void preInit() { + } + + public void init() { + GameRegistry.registerTileEntity(TileEntityConveyorBelt.class, (String)"ALConveyorBelt"); + GameRegistry.registerTileEntity(TileEntityRejector.class, (String)"ALSorter"); + GameRegistry.registerTileEntity(TileEntityManipulator.class, (String)"ALManipulator"); + GameRegistry.registerTileEntity(TileEntityCrate.class, (String)"ALCrate"); + GameRegistry.registerTileEntity(TileEntityDetector.class, (String)"ALDetector"); + GameRegistry.registerTileEntity(TileEntityEncoder.class, (String)"ALEncoder"); + GameRegistry.registerTileEntity(TileEntityArmbot.class, (String)"ALArmbot"); + GameRegistry.registerTileEntity(TileEntityCraneController.class, (String)"ALCraneController"); + GameRegistry.registerTileEntity(TileEntityCraneRail.class, (String)"ALCraneRail"); + GameRegistry.registerTileEntity(TileEntityImprinter.class, (String)"ALImprinter"); + GameRegistry.registerTileEntity(TileEntityMulti.class, (String)"ALMulti"); + } + + private void extractZipToLocation(File zipFile, String sourceFolder, String destFolder) { + try { + File destFile = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getFile("."), destFolder); + String destinationName = destFile.getAbsolutePath(); + byte[] buf = new byte[1024]; + ZipInputStream zipinputstream = null; + zipinputstream = new ZipInputStream(new FileInputStream(zipFile)); + ZipEntry zipentry = zipinputstream.getNextEntry(); + while (zipentry != null) { + int n; + String zipentryName = zipentry.getName(); + if (!zipentryName.startsWith(sourceFolder)) { + zipentry = zipinputstream.getNextEntry(); + continue; + } + String entryName = destinationName + zipentryName.substring(Math.min(zipentryName.length(), sourceFolder.length() - 1)); + entryName = entryName.replace('/', File.separatorChar); + entryName = entryName.replace('\\', File.separatorChar); + File newFile = new File(entryName); + if (zipentry.isDirectory()) { + if (!newFile.mkdirs()) break; + zipentry = zipinputstream.getNextEntry(); + continue; + } + FileOutputStream fileoutputstream = new FileOutputStream(entryName); + while ((n = zipinputstream.read(buf, 0, 1024)) > -1) { + fileoutputstream.write(buf, 0, n); + } + fileoutputstream.close(); + zipinputstream.closeEntry(); + zipentry = zipinputstream.getNextEntry(); + } + zipinputstream.close(); + } + catch (Exception e) { + System.out.println("Error while loading AssemblyLine Lua libraries: "); + e.printStackTrace(); + } + } + + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null) { + switch (ID) { + case 1: { + return new ContainerImprinter(player.inventory, (TileEntityImprinter)tileEntity); + } + case 2: { + if (tileEntity == null || !(tileEntity instanceof TileEntityEncoder)) break; + return new ContainerEncoder(player.inventory, (TileEntityEncoder)tileEntity); + } + } + } + return null; + } + + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + return null; + } + + public boolean isCtrKeyDown() { + return false; + } +} + diff --git a/src/main/java/assemblyline/common/Pair.java b/src/main/java/assemblyline/common/Pair.java new file mode 100644 index 0000000..b9d835b --- /dev/null +++ b/src/main/java/assemblyline/common/Pair.java @@ -0,0 +1,35 @@ +package assemblyline.common; + +public class Pair { + private final Object left; + private final Object right; + + public Pair(Object left, Object right) { + this.left = left; + this.right = right; + } + + public Object getKey() { + return this.left; + } + + public Object getValue() { + return this.right; + } + + public int hashCode() { + return this.left.hashCode() ^ this.right.hashCode(); + } + + public boolean equals(Object o) { + if (o == null) { + return false; + } + if (!(o instanceof Pair)) { + return false; + } + Pair pairo = (Pair)o; + return this.left.equals(pairo.getKey()) && this.right.equals(pairo.getValue()); + } +} + diff --git a/src/main/java/assemblyline/common/PathfinderCrate.java b/src/main/java/assemblyline/common/PathfinderCrate.java new file mode 100644 index 0000000..303da52 --- /dev/null +++ b/src/main/java/assemblyline/common/PathfinderCrate.java @@ -0,0 +1,63 @@ +package assemblyline.common; + +import assemblyline.common.block.TileEntityCrate; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +public class PathfinderCrate { + public IPathCallBack callBackCheck = new IPathCallBack(){ + + @Override + public boolean isValidNode(PathfinderCrate finder, ForgeDirection direction, TileEntity provider, TileEntity node) { + return node instanceof TileEntityCrate; + } + + @Override + public boolean onSearch(PathfinderCrate finder, TileEntity provider) { + return false; + } + }; + public List iteratedNodes; + public List results; + + public PathfinderCrate() { + this.clear(); + } + + public boolean findNodes(TileEntity provider) { + if (provider != null) { + this.iteratedNodes.add(provider); + if (this.callBackCheck.onSearch(this, provider)) { + return false; + } + for (int i = 0; i < 6; ++i) { + TileEntity connectedTile = VectorHelper.getTileEntityFromSide(provider.getWorldObj(), new Vector3(provider), ForgeDirection.getOrientation((int)i)); + if (this.iteratedNodes.contains((Object)connectedTile) || !this.callBackCheck.isValidNode(this, ForgeDirection.getOrientation((int)i), provider, connectedTile) || this.findNodes(connectedTile)) continue; + return false; + } + } + return true; + } + + public PathfinderCrate init(TileEntity provider) { + this.findNodes(provider); + return this; + } + + public PathfinderCrate clear() { + this.iteratedNodes = new ArrayList<>(); + this.results = new ArrayList(); + return this; + } + + public static interface IPathCallBack { + public boolean isValidNode(PathfinderCrate var1, ForgeDirection var2, TileEntity var3, TileEntity var4); + + public boolean onSearch(PathfinderCrate var1, TileEntity var2); + } +} + diff --git a/src/main/java/assemblyline/common/TabAssemblyLine.java b/src/main/java/assemblyline/common/TabAssemblyLine.java new file mode 100644 index 0000000..92536cb --- /dev/null +++ b/src/main/java/assemblyline/common/TabAssemblyLine.java @@ -0,0 +1,25 @@ +package assemblyline.common; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class TabAssemblyLine +extends CreativeTabs { + public static final TabAssemblyLine INSTANCE = new TabAssemblyLine("assemblyline"); + public static ItemStack itemStack; + + public TabAssemblyLine(String par2Str) { + super(par2Str); + } + + public ItemStack getIconItemStack() { + return itemStack; + } + + @Override + public Item getTabIconItem() { + return itemStack.getItem(); + } +} + diff --git a/src/main/java/assemblyline/common/block/BlockALMachine.java b/src/main/java/assemblyline/common/block/BlockALMachine.java new file mode 100644 index 0000000..a986e20 --- /dev/null +++ b/src/main/java/assemblyline/common/block/BlockALMachine.java @@ -0,0 +1,45 @@ +package assemblyline.common.block; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.prefab.block.BlockAdvanced; + +public abstract class BlockALMachine +extends BlockAdvanced { + public IIcon machine_icon; + + public BlockALMachine(Material material) { + super(material); + } + + @SideOnly(value=Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister iconReg) { + this.machine_icon = iconReg.registerIcon("assemblyline:machine"); + } + + @SideOnly(value=Side.CLIENT) + @Override + public IIcon getIcon(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) { + return this.machine_icon; + } + + @SideOnly(value=Side.CLIENT) + @Override + public IIcon getIcon(int par1, int par2) { + return this.machine_icon; + } + + @Override + public TileEntity createTileEntity(World w, int meta) { + return this.createNewTileEntity(w, meta); + } + +} + diff --git a/src/main/java/assemblyline/common/block/BlockCrate.java b/src/main/java/assemblyline/common/block/BlockCrate.java new file mode 100644 index 0000000..a82b556 --- /dev/null +++ b/src/main/java/assemblyline/common/block/BlockCrate.java @@ -0,0 +1,239 @@ +package assemblyline.common.block; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.PathfinderCrate; +import assemblyline.common.TabAssemblyLine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; + +public class BlockCrate +extends BlockALMachine { + IIcon crate_icon; + + public BlockCrate() { + super(UniversalElectricity.machine); + this.setBlockName("crate"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg) { + this.crate_icon = iconReg.registerIcon("assemblyline:crate"); + } + + @Override + public IIcon getIcon(IBlockAccess iBlockAccess, int x, int y, int z, int side) { + return this.crate_icon; + } + + @Override + public IIcon getIcon(int side, int metadata) { + return this.crate_icon; + } + + @Override + public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { + if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityCrate) { + TileEntityCrate tileEntity = (TileEntityCrate)world.getTileEntity(x, y, z); + boolean allMode = world.getWorldTime() - tileEntity.prevClickTime < 10L; + tileEntity.prevClickTime = world.getWorldTime(); + this.tryEject(tileEntity, player, allMode); + } + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + if (super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ)) { + return true; + } + if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityCrate) { + TileEntityCrate tileEntity = (TileEntityCrate)world.getTileEntity(x, y, z); + boolean allMode = world.getWorldTime() - tileEntity.prevClickTime < 10L; + tileEntity.prevClickTime = world.getWorldTime(); + ItemStack current = entityPlayer.inventory.getCurrentItem(); + if (side == 1 || side > 1 && (double)hitY > 0.5 || !entityPlayer.capabilities.isCreativeMode) { + if (current != null && (current.getMaxStackSize() > 1 || current.getItem() == Item.getItemFromBlock(this))) { + this.tryInsert(tileEntity, entityPlayer, allMode); + } + } else if (side == 0 || side > 1 && (double)hitY <= 0.5) { + this.tryEject(tileEntity, entityPlayer, allMode); + } + } + return true; + } + + public void tryInsert(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch) { + boolean success = allMode ? this.insertAllItems(tileEntity, player) : this.insertCurrentItem(tileEntity, player); + if (!success && doSearch) { + PathfinderCrate pathfinder = new PathfinderCrate().init(tileEntity); + for (TileEntity checkTile : pathfinder.iteratedNodes) { + if (!(checkTile instanceof TileEntityCrate)) continue; + AssemblyLine.blockCrate.tryInsert((TileEntityCrate)checkTile, player, allMode, false); + } + } + } + + public void tryInsert(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode) { + this.tryInsert(tileEntity, player, allMode, true); + } + + public void tryEject(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode) { + if (allMode && !player.isSneaking()) { + this.ejectItems(tileEntity, player, tileEntity.getMaxLimit()); + } else if (player.isSneaking()) { + this.ejectItems(tileEntity, player, 1); + } else { + ItemStack stack = tileEntity.getStackInSlot(0); + if (stack != null) { + this.ejectItems(tileEntity, player, stack.getMaxStackSize()); + } + } + } + + public boolean insertCurrentItem(TileEntityCrate tileEntity, EntityPlayer player) { + ItemStack currentStack = player.getCurrentEquippedItem(); + if (currentStack != null) { + if (currentStack.isStackable()) { + if (tileEntity.getStackInSlot(0) != null && !tileEntity.getStackInSlot(0).isItemEqual(currentStack)) { + return false; + } + player.inventory.setInventorySlotContents(player.inventory.currentItem, BlockCrate.putIn(tileEntity, currentStack)); + return true; + } + if (currentStack.getItem() == Item.getItemFromBlock(AssemblyLine.blockCrate)) { + ItemStack containedStack = ItemBlockCrate.getContainingItemStack(currentStack); + ItemStack crateStack = tileEntity.getStackInSlot(0); + if (containedStack != null && (crateStack == null || crateStack != null && containedStack.getItem() == crateStack.getItem() && containedStack.getItemDamage() == crateStack.getItemDamage())) { + ItemStack returned = BlockCrate.putIn(tileEntity, containedStack); + ItemBlockCrate.setContainingItemStack(currentStack, returned); + return true; + } + } + } + return false; + } + + public boolean insertAllItems(TileEntityCrate tileEntity, EntityPlayer player) { + ItemStack requestStack = null; + if (tileEntity.getStackInSlot(0) != null) { + requestStack = tileEntity.getStackInSlot(0).copy(); + } + if (requestStack == null) { + requestStack = player.getCurrentEquippedItem(); + } + if (requestStack != null && requestStack.isStackable()) { + boolean success = false; + for (int i = 0; i < player.inventory.getSizeInventory(); ++i) { + ItemStack currentStack = player.inventory.getStackInSlot(i); + if (currentStack == null || !requestStack.isItemEqual(currentStack)) continue; + player.inventory.setInventorySlotContents(i, BlockCrate.putIn(tileEntity, currentStack)); + if (player instanceof EntityPlayerMP) { + ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer); + } + success = true; + } + return success; + } + return false; + } + + public boolean ejectItems(TileEntityCrate tileEntity, EntityPlayer player, int requestSize) { + World world = tileEntity.getWorldObj(); + ItemStack containingStack = tileEntity.getStackInSlot(0); + if (containingStack != null) { + if (containingStack.stackSize > 0 && requestSize > 0) { + int amountToTake = Math.min(containingStack.stackSize, requestSize); + ItemStack dropStack = containingStack.copy(); + dropStack.stackSize = amountToTake; + if (!world.isRemote) { + EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack); + entityItem.delayBeforeCanPickup = 0; + world.spawnEntityInWorld((Entity)entityItem); + } + containingStack.stackSize -= amountToTake; + } + if (containingStack.stackSize <= 0) { + containingStack = null; + } + tileEntity.setInventorySlotContents(0, containingStack); + return true; + } + return false; + } + + public static ItemStack putIn(TileEntityCrate tileEntity, ItemStack itemStack) { + ItemStack containingStack = tileEntity.getStackInSlot(0); + if (containingStack != null) { + if (containingStack.isStackable() && containingStack.isItemEqual(itemStack)) { + int newStackSize = containingStack.stackSize + itemStack.stackSize; + int overFlowAmount = newStackSize - tileEntity.getInventoryStackLimit(); + itemStack.stackSize = overFlowAmount > 0 ? overFlowAmount : 0; + containingStack.stackSize = newStackSize; + tileEntity.setInventorySlotContents(0, containingStack); + } + } else { + tileEntity.setInventorySlotContents(0, itemStack.copy()); + itemStack.stackSize = 0; + } + if (itemStack.stackSize <= 0) { + return null; + } + return itemStack; + } + + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntityCrate tileEntity; + ItemStack containingStack; + if (!world.isRemote && world.getTileEntity(x, y, z) != null && (containingStack = (tileEntity = (TileEntityCrate)world.getTileEntity(x, y, z)).getStackInSlot(0)) != null && containingStack.stackSize > 0) { + float var6 = 0.7f; + double var7 = (double)(world.rand.nextFloat() * var6) + (double)(1.0f - var6) * 0.5; + double var9 = (double)(world.rand.nextFloat() * var6) + (double)(1.0f - var6) * 0.5; + double var11 = (double)(world.rand.nextFloat() * var6) + (double)(1.0f - var6) * 0.5; + ItemStack dropStack = new ItemStack((Block)this, 1, tileEntity.getTier()); + ItemBlockCrate.setContainingItemStack(dropStack, containingStack); + EntityItem var13 = new EntityItem(world, (double)x + var7, (double)y + var9, (double)z + var11, dropStack); + var13.delayBeforeCanPickup = 10; + world.spawnEntityInWorld((Entity)var13); + tileEntity.setInventorySlotContents(0, null); + world.setBlock(x, y, z, Blocks.air, 0, 3); + return true; + } + return false; + } + + @Override + public int damageDropped(int metadata) { + return metadata; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityCrate(); + } + + @Override + public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List list) { + for (int i = 0; i < 3; ++i) { + list.add(new ItemStack((Block)this, 1, i)); + } + } +} + diff --git a/src/main/java/assemblyline/common/block/BlockTurntable.java b/src/main/java/assemblyline/common/block/BlockTurntable.java new file mode 100644 index 0000000..266aa7e --- /dev/null +++ b/src/main/java/assemblyline/common/block/BlockTurntable.java @@ -0,0 +1,138 @@ +package assemblyline.common.block; + +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.implement.IRotatable; + +public class BlockTurntable +extends BlockALMachine { + private IIcon top; + + public BlockTurntable() { + super(Material.piston); + this.setBlockName("turntable"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg) { + super.registerBlockIcons(iconReg); + this.top = iconReg.registerIcon("assemblyline:turntable"); + } + + @Override + public void updateTick(World world, int x, int y, int z, Random par5Random) { + this.updateTurntableState(world, x, y, z); + } + + @Override + @SideOnly(value=Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + if (side == ForgeDirection.UP.ordinal()) { + return this.top; + } + return this.machine_icon; + } + + @Override + @SideOnly(value=Side.CLIENT) + public IIcon getIcon(int side, int meta) { + if (side == ForgeDirection.UP.ordinal()) { + return this.top; + } + return this.machine_icon; + } + + public static int determineOrientation(World world, int x, int y, int z, EntityPlayer entityPlayer) { + int var7; + if (MathHelper.abs((float)((float)entityPlayer.posX - (float)x)) < 2.0f && MathHelper.abs((float)((float)entityPlayer.posZ - (float)z)) < 2.0f) { + double var5 = entityPlayer.posY + 1.82 - (double)entityPlayer.yOffset; + if (var5 - (double)y > 2.0) { + return 1; + } + if ((double)y - var5 > 0.0) { + return 0; + } + } + return (var7 = MathHelper.floor_double((double)((double)(entityPlayer.rotationYaw * 4.0f / 360.0f) + 0.5)) & 3) == 0 ? 2 : (var7 == 1 ? 5 : (var7 == 2 ? 3 : (var7 == 3 ? 4 : 0))); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack stack) { + int metadata = BlockTurntable.determineOrientation(world, x, y, z, (EntityPlayer)par5EntityLiving); + world.setBlockMetadataWithNotify(x, y, z, metadata, 3); + world.scheduleBlockUpdate(x, y, z, this, 20); + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { + world.scheduleBlockUpdate(x, y, z, this, 20); + } + + private void updateTurntableState(World world, int x, int y, int z) { + if (world.isBlockIndirectlyGettingPowered(x, y, z)) { + try { + Vector3 position = new Vector3(x, y, z); + position.modifyPositionFromSide(ForgeDirection.UP); + IRotatable rotatable = null; + TileEntity tileEntity = position.getTileEntity((IBlockAccess)world); + Block block = position.getBlock((IBlockAccess)world); + if (tileEntity instanceof IRotatable) { + rotatable = (IRotatable)tileEntity; + } else if (block instanceof IRotatable) { + rotatable = (IRotatable)block; + } + if (rotatable != null) { + ForgeDirection newDir = ((IRotatable)tileEntity).getDirection((IBlockAccess)world, x, y, z); + switch (newDir) { + case EAST: + newDir = ForgeDirection.SOUTH; + break; + case NORTH: + newDir = ForgeDirection.EAST; + break; + case SOUTH: + newDir = ForgeDirection.WEST; + break; + case WEST: + newDir = ForgeDirection.NORTH; + break; + default: + break; + + } + rotatable.setDirection(world, x, y, z, newDir); + world.markBlockForUpdate(position.intX(), position.intY(), position.intZ()); + world.playSoundEffect((double)x + 0.5, (double)y + 0.5, (double)z + 0.5, "tile.piston.in", 0.5f, world.rand.nextFloat() * 0.15f + 0.6f); + } + } + catch (Exception e) { + System.out.println("Failed to rotate:"); + e.printStackTrace(); + } + } + } + + @Override + public TileEntity createNewTileEntity(World arg0, int arg1) { + return null; + } +} + diff --git a/src/main/java/assemblyline/common/block/ItemBlockCrate.java b/src/main/java/assemblyline/common/block/ItemBlockCrate.java new file mode 100644 index 0000000..c1f46d0 --- /dev/null +++ b/src/main/java/assemblyline/common/block/ItemBlockCrate.java @@ -0,0 +1,96 @@ +package assemblyline.common.block; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.world.World; + +public class ItemBlockCrate +extends ItemBlock { + public ItemBlockCrate(Block block) { + super(block); + this.setMaxStackSize(1); + } + + @Override + public String getUnlocalizedName(ItemStack itemStack) { + return this.getUnlocalizedName() + "." + itemStack.getItemDamage(); + } + + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { + ItemStack containingStack = ItemBlockCrate.getContainingItemStack(itemStack); + if (containingStack != null) { + par3List.add(containingStack.getDisplayName()); + par3List.add("Amount: " + containingStack.stackSize); + } else { + par3List.add("Empty"); + } + } + + @Override + public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5) { + if (entity instanceof EntityPlayer) { + EntityPlayer player = (EntityPlayer)entity; + ItemStack containingStack = ItemBlockCrate.getContainingItemStack(itemStack); + if (containingStack != null) { + player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int)((float)containingStack.stackSize / (float)TileEntityCrate.getMaxLimit(itemStack.getItemDamage())) * 5)); + } + } + } + + public static void setContainingItemStack(ItemStack itemStack, ItemStack containingStack) { + if (itemStack.stackTagCompound == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + if (containingStack != null) { + NBTTagCompound itemTagCompound = new NBTTagCompound(); + containingStack.stackSize = Math.abs(containingStack.stackSize); + containingStack.writeToNBT(itemTagCompound); + itemStack.getTagCompound().setTag("Item", (NBTBase)itemTagCompound); + itemStack.getTagCompound().setInteger("Count", containingStack.stackSize); + } else { + itemStack.getTagCompound().setTag("Item", (NBTBase)new NBTTagCompound()); + itemStack.getTagCompound().setInteger("Count", 0); + } + } + + public static ItemStack getContainingItemStack(ItemStack itemStack) { + if (itemStack.stackTagCompound == null) { + itemStack.setTagCompound(new NBTTagCompound()); + return null; + } + NBTTagCompound itemTagCompound = itemStack.getTagCompound().getCompoundTag("Item"); + ItemStack containingStack = ItemStack.loadItemStackFromNBT((NBTTagCompound)itemTagCompound); + if (containingStack != null) { + containingStack.stackSize = itemStack.getTagCompound().getInteger("Count"); + } + return containingStack; + } + + @Override + public int getMetadata(int metadata) { + return metadata; + } + + @Override + public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { + if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) { + ItemStack containingItem = ItemBlockCrate.getContainingItemStack(stack); + if (world.getTileEntity(x, y, z) != null && containingItem != null && containingItem.stackSize > 0) { + TileEntityCrate tileEntity = (TileEntityCrate)world.getTileEntity(x, y, z); + tileEntity.setInventorySlotContents(0, containingItem); + } + } + return true; + } +} + diff --git a/src/main/java/assemblyline/common/block/TileEntityCrate.java b/src/main/java/assemblyline/common/block/TileEntityCrate.java new file mode 100644 index 0000000..5bcbe52 --- /dev/null +++ b/src/main/java/assemblyline/common/block/TileEntityCrate.java @@ -0,0 +1,227 @@ +package assemblyline.common.block; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import universalelectricity.prefab.implement.ITier; +import universalelectricity.prefab.tile.TileEntityAdvanced; + +public class TileEntityCrate +extends TileEntityAdvanced +implements ITier, +IInventory { + private ItemStack[] containingItems = new ItemStack[1]; + public long prevClickTime = -1000L; + + public int getMaxLimit() { + return TileEntityCrate.getMaxLimit(this.getTier()); + } + + public static int getMaxLimit(int tier) { + if (tier >= 2) { + return 16384; + } + if (tier >= 1) { + return 4096; + } + return 2048; + } + + @Override + public boolean canUpdate() { + return false; + } + + /*@Override + public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) { + if (this.field_70331_k.isRemote) { + try { + if (dataStream.readBoolean()) { + if (this.containingItems[0] == null) { + this.containingItems[0] = new ItemStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt()); + } else { + this.containingItems[0].field_77993_c = dataStream.readInt(); + this.containingItems[0].stackSize = dataStream.readInt(); + this.containingItems[0].setItemDamage(dataStream.readInt()); + } + } else { + this.containingItems[0] = null; + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + }*/ + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + if (nbt.getBoolean("containsItems")) { + if (containingItems[0] == null) { + containingItems[0] = new ItemStack(Item.getItemById(nbt.getShort("id")), nbt.getByte("Count"), nbt.getShort("Damage")); + } else { + containingItems[0].readFromNBT(nbt); + } + } else { + containingItems[0] = null; + } + } + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + if (this.containingItems[0] != null) { + nbt.setBoolean("containsItems", true); + containingItems[0].writeToNBT(nbt); + //return PacketManager.getPacket("AssemblyLine", this, new Object[]{true, this.containingItems[0].field_77993_c, this.containingItems[0].stackSize, this.containingItems[0].getItemDamage()}); + } else { + nbt.setBoolean("containsItems", false); + } + //return PacketManager.getPacket("AssemblyLine", this, new Object[]{false}); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + } + + @Override + public ItemStack getStackInSlot(int par1) { + return this.containingItems[par1]; + } + + @Override + public ItemStack decrStackSize(int par1, int par2) { + if (this.containingItems[par1] != null) { + if (this.containingItems[par1].stackSize <= par2) { + ItemStack var3 = this.containingItems[par1]; + this.setInventorySlotContents(par1, null); + return var3; + } + ItemStack var3 = this.containingItems[par1].splitStack(par2); + if (this.containingItems[par1].stackSize == 0) { + this.containingItems[par1] = null; + } + this.setInventorySlotContents(par1, this.containingItems[par1]); + return var3; + } + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int par1) { + if (this.containingItems[par1] != null) { + ItemStack var2 = this.containingItems[par1]; + this.containingItems[par1] = null; + return var2; + } + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) { + if (stack != null) { + if (stack.isStackable()) { + this.containingItems[slot] = stack; + if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { + stack.stackSize = this.getInventoryStackLimit(); + } + } + } else { + this.containingItems[slot] = null; + } + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + @Override + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagList var2 = nbt.getTagList("Items", 10); + this.containingItems = new ItemStack[this.getSizeInventory()]; + for (int var3 = 0; var3 < var2.tagCount(); ++var3) { + NBTTagCompound var4 = (NBTTagCompound)var2.getCompoundTagAt(var3); + byte var5 = var4.getByte("Slot"); + if (var5 < 0 || var5 >= this.containingItems.length) continue; + this.containingItems[var5] = ItemStack.loadItemStackFromNBT((NBTTagCompound)var4); + } + if (this.containingItems[0] != null) { + this.containingItems[0].stackSize = nbt.getInteger("Count"); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagList var2 = new NBTTagList(); + for (int var3 = 0; var3 < this.containingItems.length; ++var3) { + if (this.containingItems[var3] == null) continue; + NBTTagCompound var4 = new NBTTagCompound(); + var4.setByte("Slot", (byte)var3); + this.containingItems[var3].writeToNBT(var4); + var2.appendTag((NBTBase)var4); + } + nbt.setTag("Items", (NBTBase)var2); + if (this.containingItems[0] != null) { + nbt.setInteger("Count", this.containingItems[0].stackSize); + } + } + + @Override + public int getInventoryStackLimit() { + return this.getMaxLimit(); + } + + @Override + public int getSizeInventory() { + return this.containingItems.length; + } + + @Override + public String getInventoryName() { + return "Crate"; + } + + @Override + public int getTier() { + return this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public void setTier(int tier) { + this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, tier, 3); + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return true; + } +} + diff --git a/src/main/java/assemblyline/common/machine/BlockBeltSorter.java b/src/main/java/assemblyline/common/machine/BlockBeltSorter.java new file mode 100644 index 0000000..8808241 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/BlockBeltSorter.java @@ -0,0 +1,23 @@ +package assemblyline.common.machine; + +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import net.minecraft.block.material.Material; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class BlockBeltSorter +extends BlockALMachine { + public BlockBeltSorter() { + super(Material.iron); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + this.setBlockName("BeltSorter"); + } + + @Override + public TileEntity createNewTileEntity(World arg0, int arg1) { + // TODO Auto-generated method stub + return null; + } +} + diff --git a/src/main/java/assemblyline/common/machine/BlockManipulator.java b/src/main/java/assemblyline/common/machine/BlockManipulator.java new file mode 100644 index 0000000..eca2803 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/BlockManipulator.java @@ -0,0 +1,82 @@ +package assemblyline.common.machine; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.machine.imprinter.BlockImprintable; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; + +public class BlockManipulator +extends BlockImprintable { + public BlockManipulator() { + super("manipulator", UniversalElectricity.machine, TabAssemblyLine.INSTANCE); + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.29f, 1.0f); + } + + public AxisAlignedBB func_71911_a_(World par1World, int par2, int par3, int par4) { + return AxisAlignedBB.getBoundingBox((double)par2, (double)par3, (double)par4, (double)par2 + 1.0, (double)par3 + 1.0, (double)par4 + 1.0); + } + + @Override + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityManipulator) { + ((TileEntityManipulator)tileEntity).selfPulse = !((TileEntityManipulator)tileEntity).selfPulse; + } + return true; + } + + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityManipulator) { + TileEntityManipulator manip = (TileEntityManipulator)tileEntity; + boolean manipMode = manip.isOutput(); + boolean inverted = manip.isInverted(); + if (manipMode && !inverted) { + manip.toggleInversion(); + } else if (manipMode && inverted) { + manip.toggleOutput(); + manip.toggleInversion(); + } else if (!manipMode && !inverted) { + manip.toggleInversion(); + } else { + manip.toggleOutput(); + manip.toggleInversion(); + } + } + return true; + } + + @Override + public TileEntity createNewTileEntity(World var1, int metadata) { + return new TileEntityManipulator(); + } + + @Override + @SideOnly(value=Side.CLIENT) + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public int damageDropped(int par1) { + return 0; + } +} + diff --git a/src/main/java/assemblyline/common/machine/BlockRejector.java b/src/main/java/assemblyline/common/machine/BlockRejector.java new file mode 100644 index 0000000..fc01770 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/BlockRejector.java @@ -0,0 +1,39 @@ +package assemblyline.common.machine; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.machine.imprinter.BlockImprintable; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; + +public class BlockRejector +extends BlockImprintable { + public BlockRejector() { + super("rejector", UniversalElectricity.machine, TabAssemblyLine.INSTANCE); + } + + @Override + public TileEntity createNewTileEntity(World var1, int metadata) { + return new TileEntityRejector(); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + @SideOnly(value=Side.CLIENT) + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } +} + diff --git a/src/main/java/assemblyline/common/machine/TileEntityAssemblyNetwork.java b/src/main/java/assemblyline/common/machine/TileEntityAssemblyNetwork.java new file mode 100644 index 0000000..58cf748 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/TileEntityAssemblyNetwork.java @@ -0,0 +1,73 @@ +package assemblyline.common.machine; + +import assemblyline.common.AssemblyLine; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.prefab.tile.TileEntityElectricityRunnable; + +public abstract class TileEntityAssemblyNetwork +extends TileEntityElectricityRunnable { + public int powerTransferRange = 0; + + public boolean isRunning() { + return AssemblyLine.REQUIRE_NO_POWER || this.powerTransferRange > 0 || this.wattsReceived > this.getRequest().getWatts(); + } + + public void updatePowerTransferRange() { + int maximumTransferRange = 0; + for (int i = 0; i < 6; ++i) { + ForgeDirection direction = ForgeDirection.getOrientation((int)i); + TileEntity tileEntity = this.worldObj.getTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); + if (tileEntity == null || !(tileEntity instanceof TileEntityAssemblyNetwork)) continue; + TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork)tileEntity; + if (assemblyNetwork.powerTransferRange <= maximumTransferRange) continue; + maximumTransferRange = assemblyNetwork.powerTransferRange; + } + this.powerTransferRange = Math.max(maximumTransferRange - 1, 0); + } + + @Override + public void updateEntity() { + super.updateEntity(); + this.onUpdate(); + if (this.ticks % 10L == 0L) { + if (this.wattsReceived >= this.getRequest().getWatts()) { + this.wattsReceived -= this.getRequest().getWatts(); + this.powerTransferRange = this.getMaxTransferRange(); + } else { + this.powerTransferRange = 0; + this.updatePowerTransferRange(); + } + if (!this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + } + + protected void onUpdate() { + } + + @Override + public ElectricityPack getRequest() { + return new ElectricityPack(1.0, this.getVoltage()); + } + + protected int getMaxTransferRange() { + return 20; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setDouble("wattsReceived", this.wattsReceived); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.wattsReceived = nbt.getDouble("wattsReceived"); + } +} + diff --git a/src/main/java/assemblyline/common/machine/TileEntityManipulator.java b/src/main/java/assemblyline/common/machine/TileEntityManipulator.java new file mode 100644 index 0000000..9ff3c80 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/TileEntityManipulator.java @@ -0,0 +1,312 @@ +package assemblyline.common.machine; + +import assemblyline.api.IManipulator; +import assemblyline.common.block.BlockCrate; +import assemblyline.common.block.TileEntityCrate; +import assemblyline.common.machine.imprinter.TileEntityFilterable; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.implement.IRedstoneReceptor; +import universalelectricity.prefab.implement.IRotatable; +import universalelectricity.prefab.multiblock.TileEntityMulti; + +public class TileEntityManipulator +extends TileEntityFilterable +implements IRotatable, +IRedstoneReceptor, +IManipulator { + public boolean selfPulse = false; + private boolean isOutput = false; + private boolean isRedstonePowered = false; + + public boolean isOutput() { + return this.isOutput; + } + + public void setOutput(boolean isOutput) { + this.isOutput = isOutput; + if (!this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + public void toggleOutput() { + this.setOutput(!this.isOutput()); + } + + @Override + protected void onUpdate() { + if (!this.worldObj.isRemote) { + if (this.ticks % 20L == 0L) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + if (!this.isDisabled() && this.isRunning()) { + if (!this.isOutput) { + this.inject(); + } else { + if (this.selfPulse && this.ticks % 10L == 0L) { + this.isRedstonePowered = true; + } + if (this.isRedstonePowered) { + this.eject(); + } + } + } + } + } + + @Override + public void inject() { + Vector3 inputPosition = new Vector3(this); + Vector3 outputUp = new Vector3(this); + outputUp.modifyPositionFromSide(ForgeDirection.UP); + Vector3 outputDown = new Vector3(this); + outputDown.modifyPositionFromSide(ForgeDirection.DOWN); + Vector3 outputPosition = new Vector3(this); + outputPosition.modifyPositionFromSide(this.getDirection().getOpposite()); + if (outputPosition.getTileEntity((IBlockAccess)this.worldObj) instanceof TileEntityManipulator && ((TileEntityManipulator)outputPosition.getTileEntity((IBlockAccess)this.worldObj)).getDirection() == this.getDirection().getOpposite()) { + return; + } + AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox((double)inputPosition.x, (double)inputPosition.y, (double)inputPosition.z, (double)(inputPosition.x + 1.0), (double)(inputPosition.y + 1.0), (double)(inputPosition.z + 1.0)); + List itemsInBound = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds); + for (EntityItem entity : itemsInBound) { + if (entity.isDead) continue; + ItemStack remainingStack = entity.getEntityItem().copy(); + if (this.getFilter() != null && !this.isFiltering(remainingStack)) continue; + if ((remainingStack = this.tryPlaceInPosition(remainingStack, outputUp, ForgeDirection.DOWN)) != null) { + remainingStack = this.tryPlaceInPosition(remainingStack, outputDown, ForgeDirection.UP); + } + if (remainingStack != null) { + remainingStack = this.tryPlaceInPosition(remainingStack, outputPosition, this.getDirection().getOpposite()); + } + if (remainingStack != null && remainingStack.stackSize > 0) { + this.throwItem(outputPosition, remainingStack); + } + entity.setDead(); + } + } + + @Override + public void eject() { + this.onPowerOff(); + Vector3 inputUp = new Vector3(this); + inputUp.modifyPositionFromSide(ForgeDirection.UP); + Vector3 inputDown = new Vector3(this); + inputDown.modifyPositionFromSide(ForgeDirection.DOWN); + Vector3 inputPosition = new Vector3(this); + inputPosition.modifyPositionFromSide(this.getDirection().getOpposite()); + Vector3 outputPosition = new Vector3(this); + outputPosition.modifyPositionFromSide(this.getDirection()); + ItemStack itemStack = this.tryGrabFromPosition(inputUp, ForgeDirection.DOWN); + if (itemStack == null) { + itemStack = this.tryGrabFromPosition(inputDown, ForgeDirection.UP); + } + if (itemStack == null) { + itemStack = this.tryGrabFromPosition(inputPosition, this.getDirection().getOpposite()); + } + if (itemStack != null && itemStack.stackSize > 0) { + this.throwItem(outputPosition, itemStack); + } + } + + public void throwItem(Vector3 outputPosition, ItemStack items) { + if (!this.worldObj.isRemote) { + EntityItem entityItem = new EntityItem(this.worldObj, outputPosition.x + 0.5, outputPosition.y + 0.8, outputPosition.z + 0.5, items); + entityItem.motionX = 0.0; + entityItem.motionZ = 0.0; + entityItem.motionY /= 5.0; + entityItem.delayBeforeCanPickup = 20; + this.worldObj.spawnEntityInWorld((Entity)entityItem); + } + } + + private ItemStack tryPlaceInPosition(ItemStack itemStack, Vector3 position, ForgeDirection direction) { + TileEntity tileEntity = position.getTileEntity((IBlockAccess)this.worldObj); + if (tileEntity != null && itemStack != null) { + if (tileEntity instanceof TileEntityMulti) { + Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition; + if (mainBlockPosition != null && !(mainBlockPosition.getTileEntity((IBlockAccess)this.worldObj) instanceof TileEntityMulti)) { + return this.tryPlaceInPosition(itemStack, mainBlockPosition, direction); + } + } else if (tileEntity instanceof TileEntityChest) { + TileEntityChest[] chests = new TileEntityChest[]{(TileEntityChest)tileEntity, null}; + for (int i = 2; i < 6; ++i) { + ForgeDirection searchDirection = ForgeDirection.getOrientation((int)i); + Vector3 searchPosition = position.clone(); + searchPosition.modifyPositionFromSide(searchDirection); + if (searchPosition.getTileEntity((IBlockAccess)this.worldObj) == null || searchPosition.getTileEntity((IBlockAccess)this.worldObj).getClass() != chests[0].getClass()) continue; + chests[1] = (TileEntityChest)searchPosition.getTileEntity((IBlockAccess)this.worldObj); + break; + } + for (TileEntityChest chest : chests) { + if (chest == null) continue; + for (int i = 0; i < chest.getSizeInventory(); ++i) { + if ((itemStack = this.addStackToInventory(i, (IInventory)chest, itemStack)) != null) continue; + return null; + } + } + } else { + if (tileEntity instanceof TileEntityCrate) { + return BlockCrate.putIn((TileEntityCrate)tileEntity, itemStack); + } + if (tileEntity instanceof ISidedInventory) { + int startIndex; + ISidedInventory inventory = (ISidedInventory)tileEntity; + for (int i : inventory.getAccessibleSlotsFromSide(direction.ordinal())) { + if ((itemStack = this.addStackToInventory(i, (IInventory)inventory, itemStack)) != null) continue; + return null; + } + } else if (tileEntity instanceof IInventory) { + IInventory inventory = (IInventory)tileEntity; + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + if ((itemStack = this.addStackToInventory(i, inventory, itemStack)) != null) continue; + return null; + } + } + } + } + if (itemStack.stackSize <= 0) { + return null; + } + return itemStack; + } + + public ItemStack addStackToInventory(int slotIndex, IInventory inventory, ItemStack itemStack) { + if (inventory.getSizeInventory() > slotIndex) { + ItemStack stackInInventory = inventory.getStackInSlot(slotIndex); + if (stackInInventory == null) { + inventory.setInventorySlotContents(slotIndex, itemStack); + if (inventory.getStackInSlot(slotIndex) == null) { + return itemStack; + } + return null; + } + if (stackInInventory.isItemEqual(itemStack) && stackInInventory.isStackable()) { + stackInInventory = stackInInventory.copy(); + int stackLim = Math.min(inventory.getInventoryStackLimit(), itemStack.getMaxStackSize()); + int rejectedAmount = Math.max(stackInInventory.stackSize + itemStack.stackSize - stackLim, 0); + stackInInventory.stackSize = Math.min(Math.max(stackInInventory.stackSize + itemStack.stackSize - rejectedAmount, 0), inventory.getInventoryStackLimit()); + itemStack.stackSize = rejectedAmount; + inventory.setInventorySlotContents(slotIndex, stackInInventory); + } + } + if (itemStack.stackSize <= 0) { + return null; + } + return itemStack; + } + + private ItemStack tryGrabFromPosition(Vector3 position, ForgeDirection direction) { + ItemStack returnStack; + block6: { + TileEntity tileEntity; + block9: { + int startIndex; + block8: { + block7: { + returnStack = null; + tileEntity = position.getTileEntity((IBlockAccess)this.worldObj); + if (tileEntity == null) break block6; + if (!(tileEntity instanceof TileEntityMulti)) break block7; + Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition; + if (mainBlockPosition != null && !(mainBlockPosition.getTileEntity((IBlockAccess)this.worldObj) instanceof TileEntityMulti)) { + return this.tryGrabFromPosition(mainBlockPosition, direction); + } + break block6; + } + if (!(tileEntity instanceof TileEntityChest)) break block8; + TileEntityChest[] chests = new TileEntityChest[]{(TileEntityChest)tileEntity, null}; + for (int i = 2; i < 6; ++i) { + ForgeDirection searchDirection = ForgeDirection.getOrientation((int)i); + Vector3 searchPosition = position.clone(); + searchPosition.modifyPositionFromSide(searchDirection); + if (searchPosition.getTileEntity((IBlockAccess)this.worldObj) == null || searchPosition.getTileEntity((IBlockAccess)this.worldObj).getClass() != chests[0].getClass()) continue; + chests[1] = (TileEntityChest)searchPosition.getTileEntity((IBlockAccess)this.worldObj); + break; + } + for (TileEntityChest chest : chests) { + if (chest == null) continue; + for (int i = 0; i < chest.getSizeInventory(); ++i) { + ItemStack itemStack = this.removeStackFromInventory(i, (IInventory)chest); + if (itemStack == null) continue; + returnStack = itemStack; + break block6; + } + } + break block6; + } + if (!(tileEntity instanceof ISidedInventory)) break block9; + ISidedInventory inventory = (ISidedInventory)tileEntity; + for (int i : inventory.getAccessibleSlotsFromSide(direction.ordinal())) { + ItemStack itemStack = this.removeStackFromInventory(i, (IInventory)inventory); + if (itemStack == null) continue; + returnStack = itemStack; + break block6; + } + break block6; + } + if (!(tileEntity instanceof IInventory)) break block6; + IInventory inventory = (IInventory)tileEntity; + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + ItemStack itemStack = this.removeStackFromInventory(i, inventory); + if (itemStack == null) continue; + returnStack = itemStack; + break; + } + } + return returnStack; + } + + public ItemStack removeStackFromInventory(int slotIndex, IInventory inventory) { + if (inventory.getStackInSlot(slotIndex) != null) { + ItemStack itemStack = inventory.getStackInSlot(slotIndex).copy(); + if (this.getFilter() == null || this.isFiltering(itemStack)) { + itemStack.stackSize = 1; + inventory.decrStackSize(slotIndex, 1); + return itemStack; + } + } + return null; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.isOutput = nbt.getBoolean("isOutput"); + this.selfPulse = nbt.getBoolean("selfpulse"); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setBoolean("isOutput", this.isOutput); + nbt.setBoolean("selfpulse", this.selfPulse); + } + + @Override + public void onPowerOn() { + this.isRedstonePowered = true; + } + + @Override + public void onPowerOff() { + this.isRedstonePowered = false; + } + + @Override + public boolean canConnect(ForgeDirection dir) { + return dir != this.getDirection(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/TileEntityRejector.java b/src/main/java/assemblyline/common/machine/TileEntityRejector.java new file mode 100644 index 0000000..1ad411f --- /dev/null +++ b/src/main/java/assemblyline/common/machine/TileEntityRejector.java @@ -0,0 +1,85 @@ +package assemblyline.common.machine; + +import assemblyline.common.machine.imprinter.TileEntityFilterable; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; + +public class TileEntityRejector +extends TileEntityFilterable { + public boolean firePiston = false; + + @Override + protected int getMaxTransferRange() { + return 20; + } + + @Override + public void onUpdate() { + super.onUpdate(); + if (this.ticks % 5L == 0L && !this.isDisabled()) { + int metadata = this.getBlockMetadata(); + this.firePiston = false; + Vector3 searchPosition = new Vector3(this); + searchPosition.modifyPositionFromSide(this.getDirection()); + TileEntity tileEntity = searchPosition.getTileEntity((IBlockAccess)this.worldObj); + try { + boolean flag = false; + if (this.isRunning()) { + AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox((double)searchPosition.x, (double)searchPosition.y, (double)searchPosition.z, (double)(searchPosition.x + 1.0), (double)(searchPosition.y + 1.0), (double)(searchPosition.z + 1.0)); + List entitiesInFront = this.worldObj.getEntitiesWithinAABB(Entity.class, bounds); + for (Entity entity : entitiesInFront) { + if (!this.canEntityBeThrow(entity)) continue; + this.throwItem(this.getDirection(), entity); + flag = true; + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + public void throwItem(ForgeDirection side, Entity entity) { + this.firePiston = true; + entity.motionX = (double)side.offsetX * 0.2; + entity.motionY += 0.10000000298023223; + entity.motionZ = (double)side.offsetZ * 0.2; + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + public boolean canEntityBeThrow(Entity entity) { + if (entity instanceof EntityItem) { + EntityItem entityItem = (EntityItem)entity; + ItemStack itemStack = entityItem.getEntityItem(); + return this.isFiltering(itemStack); + } + return false; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.firePiston = nbt.getBoolean("piston"); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setBoolean("piston", this.firePiston); + } + + @Override + public boolean canConnect(ForgeDirection dir) { + return dir != this.getDirection(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/armbot/BlockArmbot.java b/src/main/java/assemblyline/common/machine/armbot/BlockArmbot.java new file mode 100644 index 0000000..183afd3 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/armbot/BlockArmbot.java @@ -0,0 +1,79 @@ +package assemblyline.common.machine.armbot; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Random; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import universalelectricity.core.UniversalElectricity; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.multiblock.IMultiBlock; + +public class BlockArmbot +extends BlockALMachine { + public BlockArmbot() { + super(UniversalElectricity.machine); + this.setBlockName("armbot"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + public void onBlockAdded(World world, int x, int y, int z) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof IMultiBlock) { + ((IMultiBlock)tileEntity).onCreate(new Vector3(x, y, z)); + } + } + + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof IMultiBlock) { + return ((IMultiBlock)tileEntity).onActivated(player); + } + return false; + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof IMultiBlock) { + ((IMultiBlock)tileEntity).onDestroy(tileEntity); + } + this.dropBlockAsItem(world, x, y, z, new ItemStack(this)); + super.breakBlock(world, x, y, z, par5, par6); + } + + @Override + public int quantityDropped(Random par1Random) { + return 0; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityArmbot(); + } + + @SideOnly(value=Side.CLIENT) + @Override + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean canProvidePower() { + return true; + } +} + diff --git a/src/main/java/assemblyline/common/machine/armbot/TileEntityArmbot.java b/src/main/java/assemblyline/common/machine/armbot/TileEntityArmbot.java new file mode 100644 index 0000000..843387f --- /dev/null +++ b/src/main/java/assemblyline/common/machine/armbot/TileEntityArmbot.java @@ -0,0 +1,684 @@ +package assemblyline.common.machine.armbot; + +import assemblyline.api.IArmbot; +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.CommandDrop; +import assemblyline.common.machine.command.CommandFire; +import assemblyline.common.machine.command.CommandGrab; +import assemblyline.common.machine.command.CommandManager; +import assemblyline.common.machine.command.CommandReturn; +import assemblyline.common.machine.command.CommandRotateBy; +import assemblyline.common.machine.command.CommandRotateTo; +import assemblyline.common.machine.command.CommandUse; +import assemblyline.common.machine.encoder.ItemDisk; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IComputerAccess; +import dan200.computercraft.api.peripheral.IPeripheral; +import dark.library.helpers.ItemFindingHelper; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.block.IElectricityStorage; +import universalelectricity.core.vector.Vector3; +import universalelectricity.prefab.TranslationHelper; +import universalelectricity.prefab.multiblock.IMultiBlock; + +public class TileEntityArmbot +extends TileEntityAssemblyNetwork +implements IMultiBlock, +IInventory, +IElectricityStorage, +IArmbot, +IPeripheral { + private final CommandManager commandManager = new CommandManager(); + private static final int PACKET_COMMANDS = 128; + protected ItemStack disk = null; + public final double WATT_REQUEST = 20.0; + public double wattsReceived = 0.0; + private int playerUsing = 0; + private int computersAttached = 0; + private List connectedComputers = new ArrayList(); + public float rotationPitch = 0.0f; + public float rotationYaw = 0.0f; + public float renderPitch = 0.0f; + public float renderYaw = 0.0f; + private int ticksSincePower = 0; + public final float ROTATION_SPEED = 1.3f; + private String displayText = ""; + public boolean isProvidingPower = false; + private final List grabbedEntities = new ArrayList<>(); + private final List grabbedItems = new ArrayList(); + public EntityItem renderEntityItem = null; + + @Override + public void onUpdate() { + Vector3 handPosition = this.getHandPosition(); + for (Entity entity : this.grabbedEntities) { + if (entity == null) continue; + entity.setPosition(handPosition.x, handPosition.y, handPosition.z); + entity.motionX = 0.0; + entity.motionY = 0.0; + entity.motionZ = 0.0; + if (!(entity instanceof EntityItem)) continue; + ((EntityItem)entity).delayBeforeCanPickup = 20; + ((EntityItem)entity).age = 0; + } + if (this.isRunning()) { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.disk == null && this.computersAttached == 0) { + this.commandManager.clear(); + if (this.grabbedEntities.size() > 0 || this.grabbedItems.size() > 0) { + this.addCommand(CommandDrop.class); + } else if (!this.commandManager.hasTasks() && ((double)Math.abs(this.rotationYaw - 0.0f) > 0.01 || (double)Math.abs(this.rotationPitch - 0.0f) > 0.01)) { + this.addCommand(CommandReturn.class); + } + this.commandManager.setCurrentTask(0); + } + if (!this.worldObj.isRemote) { + this.commandManager.onUpdate(); + } + this.ticksSincePower = 0; + } else { + ++this.ticksSincePower; + } + if (!this.worldObj.isRemote) { + if (!this.commandManager.hasTasks()) { + this.displayText = ""; + } else { + try { + Command curCommand = (Command)this.commandManager.getCommands().get(this.commandManager.getCurrentTask()); + if (curCommand != null) { + this.displayText = curCommand.toString(); + } + } + catch (Exception ex) { + // empty catch block + } + } + } + if (Math.abs(this.renderYaw - this.rotationYaw) > 0.001f) { + float speedYaw; + if (this.renderYaw > this.rotationYaw) { + if (Math.abs(this.renderYaw - this.rotationYaw) >= 180.0f) { + this.getClass(); + speedYaw = 1.3f; + } else { + this.getClass(); + speedYaw = -1.3f; + } + } else if (Math.abs(this.renderYaw - this.rotationYaw) >= 180.0f) { + this.getClass(); + speedYaw = -1.3f; + } else { + this.getClass(); + speedYaw = 1.3f; + } + this.renderYaw += speedYaw; + while (this.renderYaw < 0.0f) { + this.renderYaw += 360.0f; + } + while (this.renderYaw > 360.0f) { + this.renderYaw -= 360.0f; + } + if (this.ticks % 5L == 0L && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + this.worldObj.playSound((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, "assemblyline:conveyor", 0.8f, 1.7f, true); + } + float f = Math.abs(this.renderYaw - this.rotationYaw); + this.getClass(); + if (f < 1.3f + 0.1f) { + this.renderYaw = this.rotationYaw; + } + for (Entity e : (List)this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)(this.yCoord + 2), (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 3), (double)(this.zCoord + 1)))) { + e.rotationYaw = this.renderYaw; + } + } + if (Math.abs(this.renderPitch - this.rotationPitch) > 0.001f) { + float speedPitch; + if (this.renderPitch > this.rotationPitch) { + this.getClass(); + speedPitch = -1.3f; + } else { + this.getClass(); + speedPitch = 1.3f; + } + this.renderPitch += speedPitch; + while (this.renderPitch < 0.0f) { + this.renderPitch += 60.0f; + } + while (this.renderPitch > 60.0f) { + this.renderPitch -= 60.0f; + } + if (this.ticks % 4L == 0L && FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + this.worldObj.playSound((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, "assemblyline:conveyor", 2.0f, 2.5f, true); + } + float f = Math.abs(this.renderPitch - this.rotationPitch); + this.getClass(); + if (f < 1.3f + 0.1f) { + this.renderPitch = this.rotationPitch; + } + for (Entity e : (List)this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)(this.yCoord + 2), (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 3), (double)(this.zCoord + 1)))) { + e.rotationPitch = this.renderPitch; + } + } + while (this.rotationYaw < 0.0f) { + this.rotationYaw += 360.0f; + } + while (this.rotationYaw > 360.0f) { + this.rotationYaw -= 360.0f; + } + while (this.rotationPitch < 0.0f) { + this.rotationPitch += 60.0f; + } + while (this.rotationPitch > 60.0f) { + this.rotationPitch -= 60.0f; + } + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 20L == 0L) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + public Command getCurrentCommand() { + if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size()) { + return (Command)this.commandManager.getCommands().get(this.commandManager.getCurrentTask()); + } + return null; + } + + public Vector3 getHandPosition() { + Vector3 position = new Vector3(this); + position.add(0.5); + position.add(this.getDeltaHandPosition()); + return position; + } + + public Vector3 getDeltaHandPosition() { + double distance = 1.0; + Vector3 delta = new Vector3(); + delta.y = Math.sin(Math.toRadians(this.renderPitch)) * distance * 2.0; + double dH = Math.cos(Math.toRadians(this.renderPitch)) * distance; + delta.x = Math.sin(Math.toRadians(-this.renderYaw)) * dH; + delta.z = Math.cos(Math.toRadians(-this.renderYaw)) * dH; + return delta; + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound data = new NBTTagCompound(); + this.writeToNBT(data); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setTag("data", data); + nbt.setInteger("transferRange", this.powerTransferRange); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.powerTransferRange = nbt.getInteger("transferRange"); + NBTTagCompound data = nbt.getCompoundTag("data"); + this.readFromNBT(data); + } + } + + @Override + public int getSizeInventory() { + return 1; + } + + @Override + public String getInventoryName() { + return TranslationHelper.getLocal("tile.armbot.name"); + } + + @Override + public ItemStack getStackInSlot(int par1) { + return this.disk; + } + + @Override + public ItemStack decrStackSize(int par1, int par2) { + if (this.disk != null) { + if (this.disk.stackSize <= par2) { + ItemStack var3 = this.disk; + this.disk = null; + return var3; + } + ItemStack var3 = this.disk.splitStack(par2); + if (this.disk.stackSize == 0) { + this.disk = null; + } + return var3; + } + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int par1) { + if (this.disk != null) { + ItemStack var2 = this.disk; + this.disk = null; + return var2; + } + return null; + } + + @Override + public void setInventorySlotContents(int par1, ItemStack par2ItemStack) { + this.disk = par2ItemStack; + this.markDirty(); + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0; + } + + @Override + public void openInventory() { + ++this.playerUsing; + } + + @Override + public void closeInventory() { + --this.playerUsing; + } + + public String getCommandDisplayText() { + return this.displayText; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagCompound diskNBT = nbt.getCompoundTag("disk"); + this.disk = diskNBT != null ? ItemStack.loadItemStackFromNBT((NBTTagCompound)diskNBT) : null; + this.rotationYaw = nbt.getFloat("yaw"); + this.rotationPitch = nbt.getFloat("pitch"); + if (this.worldObj != null && this.worldObj.isRemote) { + this.displayText = nbt.getString("cmdText"); + } + this.commandManager.setCurrentTask(nbt.getInteger("curTask")); + NBTTagList entities = nbt.getTagList("entities", 10); + this.grabbedEntities.clear(); + for (int i = 0; i < entities.tagCount(); ++i) { + NBTTagCompound entityTag = (NBTTagCompound)entities.getCompoundTagAt(i); + if (entityTag == null) continue; + Entity entity = EntityList.createEntityFromNBT((NBTTagCompound)entityTag, (World)this.worldObj); + this.grabbedEntities.add(entity); + } + NBTTagList items = nbt.getTagList("items", 10); + this.grabbedItems.clear(); + for (int i = 0; i < items.tagCount(); ++i) { + NBTTagCompound itemTag = (NBTTagCompound)items.getCompoundTagAt(i); + if (itemTag == null) continue; + ItemStack item = ItemStack.loadItemStackFromNBT((NBTTagCompound)itemTag); + this.grabbedItems.add(item); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagCompound diskNBT = new NBTTagCompound(); + if (this.disk != null) { + this.disk.writeToNBT(diskNBT); + } + nbt.setTag("disk", (NBTBase)diskNBT); + nbt.setFloat("yaw", this.rotationYaw); + nbt.setFloat("pitch", this.rotationPitch); + nbt.setString("cmdText", this.displayText); + nbt.setInteger("curTask", this.commandManager.getCurrentTask()); + NBTTagList entities = new NBTTagList(); + for (Entity entity : this.grabbedEntities) { + if (entity == null) continue; + NBTTagCompound entityNBT = new NBTTagCompound(); + entity.writeToNBT(entityNBT); + entity.writeToNBTOptional(entityNBT); + entities.appendTag((NBTBase)entityNBT); + } + nbt.setTag("entities", (NBTBase)entities); + NBTTagList items = new NBTTagList(); + for (ItemStack itemStack : this.grabbedItems) { + if (itemStack == null) continue; + NBTTagCompound entityNBT = new NBTTagCompound(); + itemStack.writeToNBT(entityNBT); + items.appendTag((NBTBase)entityNBT); + } + nbt.setTag("items", (NBTBase)items); + } + + @Override + public double getJoules() { + return this.wattsReceived; + } + + @Override + public void setJoules(double joules) { + this.wattsReceived = joules; + } + + @Override + public double getMaxJoules() { + return 1000.0; + } + + @Override + public boolean onActivated(EntityPlayer player) { + ItemStack containingStack = this.getStackInSlot(0); + if (containingStack != null) { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + EntityItem dropStack = new EntityItem(this.worldObj, player.posX, player.posY, player.posZ, containingStack); + dropStack.delayBeforeCanPickup = 0; + this.worldObj.spawnEntityInWorld((Entity)dropStack); + } + this.setInventorySlotContents(0, null); + return true; + } + if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemDisk) { + this.setInventorySlotContents(0, player.getCurrentEquippedItem()); + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + return true; + } + return false; + } + + public void markDirty() { + this.commandManager.clear(); + if (this.disk != null) { + List commands = ItemDisk.getCommands(this.disk); + for (String commandString : commands) { + String commandName = commandString.split(" ")[0]; + Class command = Command.getCommand(commandName); + if (command == null) continue; + ArrayList commandParameters = new ArrayList(); + for (String param : commandString.split(" ")) { + if (param.equals(commandName)) continue; + commandParameters.add(param); + } + this.addCommand(command, commandParameters.toArray(new String[0])); + } + } else { + this.addCommand(Command.getCommand("DROP")); + this.addCommand(Command.getCommand("RETURN")); + } + } + + public void addCommand(Class command) { + this.commandManager.addCommand(this, command); + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + public void addCommand(Class command, String[] parameters) { + this.commandManager.addCommand(this, command, parameters); + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + @Override + public void onCreate(Vector3 placedPosition) { + AssemblyLine.blockMulti.makeFakeBlock(this.worldObj, Vector3.add(placedPosition, new Vector3(0.0, 1.0, 0.0)), placedPosition); + } + + @Override + public void onDestroy(TileEntity callingBlock) { + this.worldObj.setBlock(this.xCoord, this.yCoord, this.zCoord, Blocks.air, 0, 3); + this.worldObj.setBlock(this.xCoord, this.yCoord + 1, this.zCoord, Blocks.air, 0, 3); + } + + @Override + public String getType() { + return "ArmBot"; + } + + @Override + public String[] getMethodNames() { + return new String[]{"rotateBy", "rotateTo", "grab", "drop", "reset", "isWorking", "touchingEntity", "use", "fire", "return", "clear", "isHolding"}; + } + + @Override + public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException { + switch (method) { + case 0: { + if (arguments.length > 0) { + try { + double yaw = (Double)arguments[0]; + double pitch = (Double)arguments[1]; + this.addCommand(CommandRotateBy.class, new String[]{Double.toString(yaw), Double.toString(pitch)}); + break; + } + catch (Exception ex) { + ex.printStackTrace(); + throw new IllegalArgumentException("expected number"); + } + } + throw new IllegalArgumentException("expected number"); + } + case 1: { + if (arguments.length > 0) { + try { + double yaw = (Double)arguments[0]; + double pitch = (Double)arguments[1]; + this.addCommand(CommandRotateTo.class, new String[]{Double.toString(yaw), Double.toString(pitch)}); + break; + } + catch (Exception ex) { + ex.printStackTrace(); + throw new IllegalArgumentException("expected number"); + } + } + throw new IllegalArgumentException("expected number"); + } + case 2: { + this.addCommand(CommandGrab.class); + break; + } + case 3: { + this.addCommand(CommandDrop.class); + break; + } + case 4: { + this.commandManager.clear(); + this.addCommand(CommandReturn.class); + break; + } + case 5: { + return new Object[]{this.commandManager.hasTasks()}; + } + case 6: { + Vector3 serachPosition = this.getHandPosition(); + List found = this.worldObj.getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox((double)(serachPosition.x - 0.5), (double)(serachPosition.y - 0.5), (double)(serachPosition.z - 0.5), (double)(serachPosition.x + 0.5), (double)(serachPosition.y + 0.5), (double)(serachPosition.z + 0.5))); + if (found != null && found.size() > 0) { + for (int i = 0; i < found.size(); ++i) { + if (found.get(i) == null || found.get(i) instanceof EntityPlayer || ((Entity)found.get((int)i)).ridingEntity != null) continue; + return new Object[]{true}; + } + } + return new Object[]{false}; + } + case 7: { + if (arguments.length > 0) { + try { + int times = (Integer)arguments[0]; + this.addCommand(CommandUse.class, new String[]{Integer.toString(times)}); + break; + } + catch (Exception ex) { + ex.printStackTrace(); + throw new IllegalArgumentException("expected number"); + } + } + this.addCommand(CommandUse.class); + break; + } + case 8: { + if (arguments.length > 0) { + try { + float strength = (float)((Double)arguments[0]).doubleValue(); + this.addCommand(CommandFire.class, new String[]{Float.toString(strength)}); + break; + } + catch (Exception ex) { + ex.printStackTrace(); + throw new IllegalArgumentException("expected number"); + } + } + this.addCommand(CommandFire.class); + break; + } + case 9: { + this.addCommand(CommandReturn.class); + break; + } + case 10: { + this.commandManager.clear(); + break; + } + case 11: { + return new Object[]{this.grabbedEntities.size() > 0}; + } + } + return null; + } + + //TODO: WTF + //@Override + public boolean canAttachToSide(int side) { + return side != ForgeDirection.UP.ordinal(); + } + + @Override + public void attach(IComputerAccess computer) { + ++this.computersAttached; + List list = this.connectedComputers; + synchronized (list) { + this.connectedComputers.add(computer); + } + } + + @Override + public void detach(IComputerAccess computer) { + --this.computersAttached; + List list = this.connectedComputers; + synchronized (list) { + this.connectedComputers.remove(computer); + } + } + + @Override + public List getGrabbedEntities() { + return this.grabbedEntities; + } + + @Override + public List getGrabbedItems() { + return this.grabbedItems; + } + + @Override + public void grabEntity(Entity entity) { + if (entity instanceof EntityItem) { + this.grabItem(((EntityItem)entity).getEntityItem()); + entity.setDead(); + } else { + this.grabbedEntities.add(entity); + } + } + + @Override + public void grabItem(ItemStack itemStack) { + this.grabbedItems.add(itemStack); + } + + @Override + public void dropEntity(Entity entity) { + this.grabbedEntities.remove((Object)entity); + } + + @Override + public void dropItem(ItemStack itemStack) { + Vector3 handPosition = this.getHandPosition(); + this.worldObj.spawnEntityInWorld((Entity)new EntityItem(this.worldObj, handPosition.x, handPosition.y, handPosition.z, itemStack)); + this.grabbedItems.remove((Object)itemStack); + } + + @Override + public void dropAll() { + Vector3 handPosition = this.getHandPosition(); + Iterator it = this.grabbedItems.iterator(); + while (it.hasNext()) { + ItemFindingHelper.dropItemStackExact(this.worldObj, handPosition.x, handPosition.y, handPosition.z, (ItemStack)it.next()); + } + this.grabbedEntities.clear(); + this.grabbedItems.clear(); + } + + public boolean isProvidingPowerSide(ForgeDirection dir) { + return this.isProvidingPower && dir.getOpposite() == this.getFacingDirectionFromAngle(); + } + + public ForgeDirection getFacingDirectionFromAngle() { + float angle = MathHelper.wrapAngleTo180_float((float)this.rotationYaw); + if (angle >= -45.0f && angle <= 45.0f) { + return ForgeDirection.SOUTH; + } + if (angle >= 45.0f && angle <= 135.0f) { + return ForgeDirection.WEST; + } + if (angle >= 135.0f && angle <= -135.0f) { + return ForgeDirection.NORTH; + } + return ForgeDirection.EAST; + } + + @Override + public boolean canConnect(ForgeDirection direction) { + return direction == ForgeDirection.DOWN; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return false; + } + + @Override + public boolean equals(IPeripheral other) { + return super.equals(other); + } +} + diff --git a/src/main/java/assemblyline/common/machine/belt/BlockConveyorBelt.java b/src/main/java/assemblyline/common/machine/belt/BlockConveyorBelt.java new file mode 100644 index 0000000..2f1ad67 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/belt/BlockConveyorBelt.java @@ -0,0 +1,257 @@ +package assemblyline.common.machine.belt; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; + +public class BlockConveyorBelt +extends BlockALMachine { + public BlockConveyorBelt() { + super(UniversalElectricity.machine); + this.setBlockName("conveyorBelt"); + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.3f, 1.0f); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + if (world.getTileEntity(x, y, z) instanceof TileEntityConveyorBelt) { + TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt)world.getTileEntity(x, y, z); + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.UP || tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.DOWN) { + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.96f, 1.0f); + return; + } + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.TOP) { + this.setBlockBounds(0.0f, 0.68f, 0.0f, 1.0f, 0.96f, 1.0f); + return; + } + } + this.setBlockBounds(0.0f, 0.0f, 0.0f, 1.0f, 0.3f, 1.0f); + } + + @Override + public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { + TileEntity t = world.getTileEntity(x, y, z); + if (t != null && t instanceof TileEntityConveyorBelt) { + TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt)t; + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.UP || tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.DOWN) { + return AxisAlignedBB.getBoundingBox((double)x + this.minX, (double)y + this.minY, (double)z + this.minZ, (double)x + 1.0, (double)y + 1.0, (double)z + 1.0); + } + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.TOP) { + return AxisAlignedBB.getBoundingBox((double)x + this.minX, (double)y + (double)0.68f, (double)z + this.minZ, (double)x + this.maxX, (double)y + (double)0.98f, (double)z + this.maxZ); + } + } + return AxisAlignedBB.getBoundingBox((double)x + this.minX, (double)y + this.minY, (double)z + this.minZ, (double)x + this.maxX, (double)y + this.maxY, (double)z + this.maxZ); + } + + @Override + public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity) { + AxisAlignedBB newBounds; + TileEntity t = world.getTileEntity(x, y, z); + if (t != null && t instanceof TileEntityConveyorBelt) { + TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt)t; + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.UP || tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.DOWN) { + AxisAlignedBB boundBottom = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)(x + 1), (double)y + 0.3, (double)(z + 1)); + AxisAlignedBB boundTop = null; + ForgeDirection direction = tileEntity.getDirection(); + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.UP) { + if (direction.offsetX > 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)((float)x + (float)direction.offsetX / 2.0f), (double)y, (double)z, (double)(x + 1), (double)y + 0.8, (double)(z + 1)); + } else if (direction.offsetX < 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)((float)x + (float)direction.offsetX / -2.0f), (double)y + 0.8, (double)(z + 1)); + } else if (direction.offsetZ > 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)((float)z + (float)direction.offsetZ / 2.0f), (double)(x + 1), (double)y + 0.8, (double)(z + 1)); + } else if (direction.offsetZ < 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)(x + 1), (double)y + 0.8, (double)((float)z + (float)direction.offsetZ / -2.0f)); + } + } else if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.DOWN) { + if (direction.offsetX > 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)((float)x + (float)direction.offsetX / 2.0f), (double)y + 0.8, (double)(z + 1)); + } else if (direction.offsetX < 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)((float)x + (float)direction.offsetX / -2.0f), (double)y, (double)z, (double)(x + 1), (double)y + 0.8, (double)(z + 1)); + } else if (direction.offsetZ > 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)(x + 1), (double)y + 0.8, (double)((float)z + (float)direction.offsetZ / 2.0f)); + } else if (direction.offsetZ < 0) { + boundTop = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)((float)z + (float)direction.offsetZ / -2.0f), (double)(x + 1), (double)y + 0.8, (double)(z + 1)); + } + } + if (par5AxisAlignedBB.intersectsWith(boundBottom)) { + par6List.add(boundBottom); + } + if (boundTop != null && par5AxisAlignedBB.intersectsWith(boundTop)) { + par6List.add(boundTop); + } + return; + } + if (tileEntity.getSlant() == TileEntityConveyorBelt.SlantType.TOP) { + AxisAlignedBB newBounds2 = AxisAlignedBB.getBoundingBox((double)x, (double)y + 0.68, (double)z, (double)(x + 1), (double)y + 0.98, (double)(z + 1)); + if (newBounds2 != null && par5AxisAlignedBB.intersectsWith(newBounds2)) { + par6List.add(newBounds2); + } + return; + } + } + if ((newBounds = AxisAlignedBB.getBoundingBox((double)x, (double)y, (double)z, (double)(x + 1), (double)y + 0.3, (double)(z + 1))) != null && par5AxisAlignedBB.intersectsWith(newBounds)) { + par6List.add(newBounds); + } + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack stack) { + int angle = MathHelper.floor_double((double)((double)(par5EntityLiving.rotationYaw * 4.0f / 360.0f) + 0.5)) & 3; + int change = 2; + switch (angle) { + case 0: { + change = 3; + break; + } + case 1: { + change = 4; + break; + } + case 2: { + change = 2; + break; + } + case 3: { + change = 5; + } + } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + } + + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + int original = world.getBlockMetadata(x, y, z); + int change = 2; + switch (original) { + case 2: { + change = 4; + break; + } + case 3: { + change = 5; + break; + } + case 4: { + change = 3; + break; + } + case 5: { + change = 2; + } + } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + return true; + } + + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt)world.getTileEntity(x, y, z); + int slantOrdinal = tileEntity.getSlant().ordinal() + 1; + if (slantOrdinal >= TileEntityConveyorBelt.SlantType.values().length) { + slantOrdinal = 0; + } + tileEntity.setSlant(TileEntityConveyorBelt.SlantType.values()[slantOrdinal]); + return true; + } + + @Override + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { + TileEntityConveyorBelt tileEntity = (TileEntityConveyorBelt)world.getTileEntity(x, y, z); + tileEntity.updatePowerTransferRange(); + if (tileEntity.IgnoreList.contains((Object)entity)) { + return; + } + if (tileEntity.isRunning() && !world.isBlockIndirectlyGettingPowered(x, y, z)) { + tileEntity.getClass(); + float acceleration = 0.01f; + tileEntity.getClass(); + float maxSpeed = 0.1f; + TileEntityConveyorBelt.SlantType slantType = tileEntity.getSlant(); + ForgeDirection direction = tileEntity.getDirection(); + if (entity instanceof EntityLiving) { + acceleration *= 5.0f; + maxSpeed *= 10.0f; + } + entity.addVelocity((double)((float)direction.offsetX * acceleration), 0.0, (double)((float)direction.offsetZ * acceleration)); + if (direction.offsetX != 0 && Math.abs(entity.motionX) > (double)maxSpeed) { + entity.motionX = (float)direction.offsetX * maxSpeed; + entity.motionZ = 0.0; + } + if (direction.offsetZ != 0 && Math.abs(entity.motionZ) > (double)maxSpeed) { + entity.motionZ = (float)direction.offsetZ * maxSpeed; + entity.motionX = 0.0; + } + entity.motionY += (double)0.0125f; + if (entity instanceof EntityItem) { + double difference; + if (direction.offsetX != 0) { + difference = (double)z + 0.5 - entity.posZ; + entity.motionZ += difference * 0.1; + } else if (direction.offsetZ != 0) { + difference = (double)x + 0.5 - entity.posX; + entity.motionX += difference * 0.1; + } + ++((EntityItem)entity).age; + boolean foundSneaking = false; + for (EntityPlayer player : (List) world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox((double)(x - 1), (double)(y - 1), (double)(z - 1), (double)(x + 1), (double)(y + 1), (double)(z + 1)))) { + if (!player.isSneaking()) continue; + foundSneaking = true; + } + ((EntityItem)entity).delayBeforeCanPickup = foundSneaking ? 0 : 20; + entity.onGround = false; + } + if (slantType == TileEntityConveyorBelt.SlantType.UP) { + if (entity.motionY < 0.4) { + entity.addVelocity(0.0, 0.4, 0.0); + } + } else if (slantType == TileEntityConveyorBelt.SlantType.DOWN && entity.motionY > -0.1) { + entity.addVelocity(0.0, -0.1, 0.0); + } + } + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityConveyorBelt(); + } + + @Override + @SideOnly(value=Side.CLIENT) + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public int damageDropped(int par1) { + return 0; + } +} + diff --git a/src/main/java/assemblyline/common/machine/belt/TileEntityConveyorBelt.java b/src/main/java/assemblyline/common/machine/belt/TileEntityConveyorBelt.java new file mode 100644 index 0000000..0336b2f --- /dev/null +++ b/src/main/java/assemblyline/common/machine/belt/TileEntityConveyorBelt.java @@ -0,0 +1,256 @@ +package assemblyline.common.machine.belt; + +import assemblyline.api.IBelt; +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.TileEntityAssemblyNetwork; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.implement.IRotatable; + +public class TileEntityConveyorBelt +extends TileEntityAssemblyNetwork +implements IBelt, +IRotatable { + public static final int MAX_FRAME = 13; + public static final int MAX_SLANT_FRAME = 23; + public final float acceleration = 0.01f; + public final float maxSpeed = 0.1f; + public float wheelRotation = 0.0f; + private int animFrame = 0; + private SlantType slantType = SlantType.NONE; + public List IgnoreList = new ArrayList<>(); + + @Override + public void updatePowerTransferRange() { + ForgeDirection direction; + int maximumTransferRange = 0; + for (int i = 0; i < 6; ++i) { + direction = ForgeDirection.getOrientation((int)i); + TileEntity tileEntity = this.worldObj.getTileEntity(this.xCoord + direction.offsetX, this.yCoord + direction.offsetY, this.zCoord + direction.offsetZ); + if (tileEntity == null || !(tileEntity instanceof TileEntityAssemblyNetwork)) continue; + TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork)tileEntity; + if (assemblyNetwork.powerTransferRange <= maximumTransferRange) continue; + maximumTransferRange = assemblyNetwork.powerTransferRange; + } + for (int d = 0; d <= 1; ++d) { + direction = this.getDirection(); + if (d == 1) { + direction = direction.getOpposite(); + } + for (int i = -1; i <= 1; ++i) { + TileEntity tileEntity = this.worldObj.getTileEntity(this.xCoord + direction.offsetX, this.yCoord + i, this.zCoord + direction.offsetZ); + if (tileEntity == null || !(tileEntity instanceof TileEntityAssemblyNetwork)) continue; + TileEntityAssemblyNetwork assemblyNetwork = (TileEntityAssemblyNetwork)tileEntity; + if (assemblyNetwork.powerTransferRange <= maximumTransferRange) continue; + maximumTransferRange = assemblyNetwork.powerTransferRange; + } + } + this.powerTransferRange = Math.max(maximumTransferRange - 1, 0); + } + + @Override + public void onUpdate() { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.ticks % 10L == 0L) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + ArrayList newList = new ArrayList(); + for (Entity ent : this.IgnoreList) { + if (!this.getAffectedEntities().contains((Object)ent)) continue; + newList.add(ent); + } + this.IgnoreList = newList; + if (this.isRunning() && !this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) { + if (this.ticks % 10L == 0L && this.worldObj.isRemote && this.worldObj.getBlock(this.xCoord - 1, this.yCoord, this.zCoord) != AssemblyLine.blockConveyorBelt && this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord - 1) != AssemblyLine.blockConveyorBelt) { + this.worldObj.playSound((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, "assemblyline:conveyor", 0.5f, 0.7f, true); + } + this.wheelRotation += 40.0f; + if (this.wheelRotation > 360.0f) { + this.wheelRotation = 0.0f; + } + float wheelRotPct = this.wheelRotation / 360.0f; + if (this.getSlant() == SlantType.NONE || this.getSlant() == SlantType.TOP) { + this.animFrame = (int)(wheelRotPct * 13.0f); + if (this.animFrame < 0) { + this.animFrame = 0; + } + if (this.animFrame > 13) { + this.animFrame = 13; + } + } else { + this.animFrame = (int)(wheelRotPct * 23.0f); + if (this.animFrame < 0) { + this.animFrame = 0; + } + if (this.animFrame > 23) { + this.animFrame = 23; + } + } + } + } + + @Override + protected int getMaxTransferRange() { + return 20; + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setDouble("wattsReceived", this.wattsReceived); + nbt.setInteger("slantType", this.slantType.ordinal()); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + } + + public SlantType getSlant() { + return this.slantType; + } + + public void setSlant(SlantType slantType) { + if (slantType == null) { + slantType = SlantType.NONE; + } + this.slantType = slantType; + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + public boolean getIsFirstBelt() { + ForgeDirection front = this.getDirection(); + ForgeDirection back = this.getDirection().getOpposite(); + TileEntity fBelt = this.worldObj.getTileEntity(this.xCoord + front.offsetX, this.yCoord + front.offsetY, this.zCoord + front.offsetZ); + TileEntity BBelt = this.worldObj.getTileEntity(this.xCoord + back.offsetX, this.yCoord + back.offsetY, this.zCoord + back.offsetZ); + if (fBelt instanceof TileEntityConveyorBelt) { + ForgeDirection TD; + ForgeDirection fD = ((TileEntityConveyorBelt)fBelt).getDirection(); + return fD == (TD = this.getDirection()); + } + return false; + } + + public boolean getIsMiddleBelt() { + ForgeDirection front = this.getDirection(); + ForgeDirection back = this.getDirection().getOpposite(); + TileEntity fBelt = this.worldObj.getTileEntity(this.xCoord + front.offsetX, this.yCoord + front.offsetY, this.zCoord + front.offsetZ); + TileEntity BBelt = this.worldObj.getTileEntity(this.xCoord + back.offsetX, this.yCoord + back.offsetY, this.zCoord + back.offsetZ); + if (fBelt instanceof TileEntityConveyorBelt && BBelt instanceof TileEntityConveyorBelt) { + ForgeDirection fD = ((TileEntityConveyorBelt)fBelt).getDirection(); + ForgeDirection BD = ((TileEntityConveyorBelt)BBelt).getDirection(); + ForgeDirection TD = this.getDirection(); + return fD == TD && BD == TD; + } + return false; + } + + public boolean getIsLastBelt() { + ForgeDirection front = this.getDirection(); + ForgeDirection back = this.getDirection().getOpposite(); + TileEntity fBelt = this.worldObj.getTileEntity(this.xCoord + front.offsetX, this.yCoord + front.offsetY, this.zCoord + front.offsetZ); + TileEntity BBelt = this.worldObj.getTileEntity(this.xCoord + back.offsetX, this.yCoord + back.offsetY, this.zCoord + back.offsetZ); + if (BBelt instanceof TileEntityConveyorBelt) { + ForgeDirection TD; + ForgeDirection BD = ((TileEntityConveyorBelt)BBelt).getDirection(); + return BD == (TD = this.getDirection()); + } + return false; + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.wattsReceived = nbt.getDouble("wattsReceived"); + this.slantType = SlantType.values()[nbt.getInteger("slantType")]; + } + } + + @Override + public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection) { + this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 3); + } + + @Override + public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) { + return ForgeDirection.getOrientation((int)this.getBlockMetadata()); + } + + public ForgeDirection getDirection() { + return this.getDirection((IBlockAccess)this.worldObj, this.xCoord, this.yCoord, this.zCoord); + } + + public void setDirection(ForgeDirection facingDirection) { + this.setDirection(this.worldObj, this.xCoord, this.yCoord, this.zCoord, facingDirection); + } + + @Override + public List getAffectedEntities() { + AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)); + return this.worldObj.getEntitiesWithinAABB(Entity.class, bounds); + } + + public int getAnimationFrame() { + if (!this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord)) { + TileEntity te = null; + te = this.worldObj.getTileEntity(this.xCoord - 1, this.yCoord, this.zCoord); + if (te != null && te instanceof TileEntityConveyorBelt && ((TileEntityConveyorBelt)te).getSlant() == this.slantType) { + return ((TileEntityConveyorBelt)te).getAnimationFrame(); + } + te = this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord - 1); + if (te != null && te instanceof TileEntityConveyorBelt && ((TileEntityConveyorBelt)te).getSlant() == this.slantType) { + return ((TileEntityConveyorBelt)te).getAnimationFrame(); + } + } + return this.animFrame; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.slantType = SlantType.values()[nbt.getByte("slant")]; + if (this.worldObj != null) { + this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, nbt.getInteger("rotation"), 3); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setByte("slant", (byte)this.slantType.ordinal()); + if (this.worldObj != null) { + nbt.setInteger("rotation", this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + } + } + + @Override + public void IgnoreEntity(Entity entity) { + if (!this.IgnoreList.contains((Object)entity)) { + this.IgnoreList.add(entity); + } + } + + @Override + public boolean canConnect(ForgeDirection direction) { + return direction == ForgeDirection.DOWN; + } + + public static enum SlantType { + NONE, + UP, + DOWN, + TOP; + + } +} + diff --git a/src/main/java/assemblyline/common/machine/belt/TileEntityCoveredBelt.java b/src/main/java/assemblyline/common/machine/belt/TileEntityCoveredBelt.java new file mode 100644 index 0000000..2611e3f --- /dev/null +++ b/src/main/java/assemblyline/common/machine/belt/TileEntityCoveredBelt.java @@ -0,0 +1,6 @@ +package assemblyline.common.machine.belt; + +public class TileEntityCoveredBelt +extends TileEntityConveyorBelt { +} + diff --git a/src/main/java/assemblyline/common/machine/belt/TileEntityElevatorBelt.java b/src/main/java/assemblyline/common/machine/belt/TileEntityElevatorBelt.java new file mode 100644 index 0000000..9aee214 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/belt/TileEntityElevatorBelt.java @@ -0,0 +1,23 @@ +package assemblyline.common.machine.belt; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.tileentity.TileEntity; + +public class TileEntityElevatorBelt +extends TileEntityConveyorBelt { + public List conveyList = new ArrayList(); + + public void doBeltAction() { + this.conveyItemsVertical(true, false); + } + + public boolean isBellowABelt() { + TileEntity ent = this.worldObj.getTileEntity(this.xCoord, this.xCoord - 1, this.zCoord); + return ent instanceof TileEntityElevatorBelt; + } + + public void conveyItemsVertical(boolean extendLife, boolean preventPickUp) { + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/Command.java b/src/main/java/assemblyline/common/machine/command/Command.java new file mode 100644 index 0000000..63baf0d --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/Command.java @@ -0,0 +1,138 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.armbot.TileEntityArmbot; +import assemblyline.common.machine.command.CommandBreak; +import assemblyline.common.machine.command.CommandDrop; +import assemblyline.common.machine.command.CommandFire; +import assemblyline.common.machine.command.CommandGrab; +import assemblyline.common.machine.command.CommandHarvest; +import assemblyline.common.machine.command.CommandIdle; +import assemblyline.common.machine.command.CommandManager; +import assemblyline.common.machine.command.CommandPlace; +import assemblyline.common.machine.command.CommandPowerTo; +import assemblyline.common.machine.command.CommandRepeat; +import assemblyline.common.machine.command.CommandReturn; +import assemblyline.common.machine.command.CommandRotateBy; +import assemblyline.common.machine.command.CommandRotateTo; +import assemblyline.common.machine.command.CommandUse; +import java.util.HashMap; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +public abstract class Command { + private static final HashMap COMMANDS = new HashMap(); + private static final HashMap REVERSE_LOOKUP = new HashMap(); + protected int ticks = 0; + public World world; + public TileEntityArmbot tileEntity; + public CommandManager commandManager; + private String[] parameters; + + public static void registerCommand(String command, Class commandClass) { + COMMANDS.put(command, commandClass); + REVERSE_LOOKUP.put(commandClass, command); + } + + public static Class getCommand(String command) { + return (Class)COMMANDS.get(command.toLowerCase()); + } + + public static String getCommandName(Class command) { + return (String)REVERSE_LOOKUP.get(command); + } + + protected boolean doTask() { + ++this.ticks; + return false; + } + + public void onTaskStart() { + } + + public void onTaskEnd() { + } + + public int getTickInterval() { + return 1; + } + + public void setParameters(String[] strings) { + this.parameters = strings; + } + + public String[] getArgs() { + return this.parameters; + } + + protected String getArg(int i) { + if (i >= 0 && i < this.parameters.length) { + return this.parameters[i]; + } + return null; + } + + protected int getIntArg(int i) { + if (this.getArg(i) != null) { + try { + return Integer.parseInt(this.getArg(i)); + } + catch (Exception exception) { + // empty catch block + } + } + return 0; + } + + protected Double getDoubleArg(int i) { + if (this.getArg(i) != null) { + try { + return Double.parseDouble(this.getArg(i)); + } + catch (Exception exception) { + // empty catch block + } + } + return 0.0; + } + + protected Float getFloatArg(int i) { + if (this.getArg(i) != null) { + try { + return Float.valueOf(Float.parseFloat(this.getArg(i))); + } + catch (Exception exception) { + // empty catch block + } + } + return Float.valueOf(0.0f); + } + + public void readFromNBT(NBTTagCompound taskCompound) { + this.ticks = taskCompound.getInteger("ticks"); + } + + public void writeToNBT(NBTTagCompound taskCompound) { + taskCompound.setInteger("ticks", this.ticks); + } + + public String toString() { + return "COMMAND"; + } + + static { + Command.registerCommand("idle", CommandIdle.class); + Command.registerCommand("grab", CommandGrab.class); + Command.registerCommand("drop", CommandDrop.class); + Command.registerCommand("rotate", CommandRotateBy.class); + Command.registerCommand("rotateto", CommandRotateTo.class); + Command.registerCommand("return", CommandReturn.class); + Command.registerCommand("repeat", CommandRepeat.class); + Command.registerCommand("use", CommandUse.class); + Command.registerCommand("powerto", CommandPowerTo.class); + Command.registerCommand("fire", CommandFire.class); + Command.registerCommand("break", CommandBreak.class); + Command.registerCommand("place", CommandPlace.class); + Command.registerCommand("harvest", CommandHarvest.class); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandBreak.java b/src/main/java/assemblyline/common/machine/command/CommandBreak.java new file mode 100644 index 0000000..fcf731d --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandBreak.java @@ -0,0 +1,44 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.CommandRotateTo; +import dark.library.helpers.ItemFindingHelper; +import java.util.ArrayList; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import universalelectricity.core.vector.Vector3; + +public class CommandBreak +extends Command { + private CommandRotateTo rotateToCommand; + int BREAK_TIME = 30; + boolean keep = false; + + @Override + protected boolean doTask() { + super.doTask(); + Vector3 serachPosition = this.tileEntity.getHandPosition(); + Block block = serachPosition.getBlock(this.world); + if (block != null && this.BREAK_TIME <= this.ticks) { + ArrayList items = block.getDrops(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), serachPosition.getBlockMetadata((IBlockAccess)this.world), 0); + if (!this.keep || items.size() > 1) { + ItemFindingHelper.dropBlockAsItem(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); + } else { + this.tileEntity.grabEntity((Entity)new EntityItem(this.world, (double)serachPosition.intX() + 0.5, (double)serachPosition.intY() + 0.5, (double)serachPosition.intZ() + 0.5, (ItemStack)items.get(0))); + } + this.world.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), Blocks.air, 0, 3); + return false; + } + return true; + } + + @Override + public String toString() { + return "BREAK"; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandDrop.java b/src/main/java/assemblyline/common/machine/command/CommandDrop.java new file mode 100644 index 0000000..f4fe6f7 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandDrop.java @@ -0,0 +1,20 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; + +public class CommandDrop +extends Command { + @Override + protected boolean doTask() { + super.doTask(); + this.tileEntity.dropAll(); + this.world.playSound((double)this.tileEntity.xCoord, (double)this.tileEntity.yCoord, (double)this.tileEntity.zCoord, "random.pop", 0.2f, ((this.tileEntity.getWorldObj().rand.nextFloat() - this.tileEntity.getWorldObj().rand.nextFloat()) * 0.7f + 1.0f) * 1.0f, true); + return false; + } + + @Override + public String toString() { + return "DROP"; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandFire.java b/src/main/java/assemblyline/common/machine/command/CommandFire.java new file mode 100644 index 0000000..01eb1d2 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandFire.java @@ -0,0 +1,128 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.CommandDrop; +import java.util.Random; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.vector.Vector3; + +public class CommandFire +extends Command { + private static final float MIN_ACTUAL_PITCH = -80.0f; + private static final float MAX_ACTUAL_PITCH = 80.0f; + private float actualYaw; + private float actualPitch; + private float velocity; + private Vector3 finalVelocity; + + @Override + public void onTaskStart() { + super.onTaskStart(); + this.velocity = this.getFloatArg(0).floatValue(); + if (this.velocity > 2.5f) { + this.velocity = 2.5f; + } + if (this.velocity < 0.125f) { + this.velocity = 1.0f; + } + this.actualYaw = this.tileEntity.rotationYaw; + this.actualPitch = 160.0f * (this.tileEntity.rotationPitch / 60.0f) + -80.0f; + double yaw = Math.toRadians(this.actualYaw); + double pitch = Math.toRadians(this.actualPitch); + double x = -Math.sin(yaw) * Math.cos(pitch); + double y = Math.sin(pitch); + double z = Math.cos(yaw) * Math.cos(pitch); + this.finalVelocity = new Vector3(x, y, z); + Random random = new Random(System.currentTimeMillis()); + this.finalVelocity.x *= (double)(0.995f + random.nextFloat() * 0.01f); + this.finalVelocity.y *= (double)(0.995f + random.nextFloat() * 0.01f); + this.finalVelocity.z *= (double)(0.995f + random.nextFloat() * 0.01f); + this.finalVelocity.multiply(this.velocity); + } + + @Override + protected boolean doTask() { + Entity held; + if (this.finalVelocity == null) { + this.finalVelocity = new Vector3(0.0, 0.0, 0.0); + } + if (this.tileEntity.getGrabbedEntities().size() > 0 && (held = (Entity)this.tileEntity.getGrabbedEntities().get(0)) != null) { + this.world.playSound((double)this.tileEntity.xCoord, (double)this.tileEntity.yCoord, (double)this.tileEntity.zCoord, "random.bow", this.velocity, 2.0f - this.velocity / 4.0f, true); + if (held instanceof EntityItem) { + EntityItem item = (EntityItem)held; + ItemStack stack = item.getEntityItem(); + ItemStack thrown = stack.copy(); + thrown.stackSize = 1; + if (item.getEntityItem().stackSize > 0) { + --stack.stackSize; + item.setEntityItemStack(stack); + } else { + this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[0]).doTask(); + if (!this.world.isRemote) { + this.world.removeEntity(held); + } + } + if (item.getEntityItem().getItem() == Items.arrow) { + EntityArrow arrow = new EntityArrow(this.world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z); + arrow.motionX = this.finalVelocity.x; + arrow.motionY = this.finalVelocity.y; + arrow.motionZ = this.finalVelocity.z; + if (!this.world.isRemote) { + this.world.spawnEntityInWorld((Entity)arrow); + } + } else { + EntityItem item2 = new EntityItem(this.world, this.tileEntity.getHandPosition().x, this.tileEntity.getHandPosition().y, this.tileEntity.getHandPosition().z, thrown); + item2.motionX = this.finalVelocity.x; + item2.motionY = this.finalVelocity.y; + item2.motionZ = this.finalVelocity.z; + if (!this.world.isRemote) { + this.world.spawnEntityInWorld((Entity)item2); + } + } + } else { + this.commandManager.getNewCommand(this.tileEntity, CommandDrop.class, new String[0]).doTask(); + held.motionX = this.finalVelocity.x; + held.motionY = this.finalVelocity.y; + held.motionZ = this.finalVelocity.z; + } + } + return false; + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.actualYaw = taskCompound.getFloat("fireYaw"); + this.actualPitch = taskCompound.getFloat("firePitch"); + this.velocity = taskCompound.getFloat("fireVelocity"); + this.finalVelocity = new Vector3(); + this.finalVelocity.x = taskCompound.getDouble("fireVectorX"); + this.finalVelocity.y = taskCompound.getDouble("fireVectorY"); + this.finalVelocity.z = taskCompound.getDouble("fireVectorZ"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setFloat("fireYaw", this.actualYaw); + taskCompound.setFloat("firePitch", this.actualPitch); + taskCompound.setFloat("fireVelocity", this.velocity); + if (this.finalVelocity != null) { + taskCompound.setDouble("fireVectorX", this.finalVelocity.x); + taskCompound.setDouble("fireVectorY", this.finalVelocity.y); + taskCompound.setDouble("fireVectorZ", this.finalVelocity.z); + } + } + + @Override + public String toString() { + return "FIRE " + Float.toString(this.velocity); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandGrab.java b/src/main/java/assemblyline/common/machine/command/CommandGrab.java new file mode 100644 index 0000000..bbdc61e --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandGrab.java @@ -0,0 +1,100 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.belt.TileEntityConveyorBelt; +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.GrabDictionary; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityAgeable; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.projectile.EntityArrow; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import universalelectricity.core.vector.Vector3; + +public class CommandGrab +extends Command { + public static final float radius = 0.5f; + public boolean child = false; + private TileEntityConveyorBelt belt; + private Class entityToInclude; + + @Override + public void onTaskStart() { + super.onTaskStart(); + this.entityToInclude = Entity.class; + if (this.getArgs() != null && this.getArgs().length > 0 && this.getArgs()[0] != null) { + if (this.getArg(0).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child")) { + this.child = true; + if (this.getArgs().length > 1 && this.getArgs()[1] != null) { + this.entityToInclude = GrabDictionary.get(this.getArg(1)).getEntityClass(); + } + } else { + this.entityToInclude = GrabDictionary.get(this.getArg(0)).getEntityClass(); + if (this.getArgs().length > 1 && this.getArgs()[1] != null && (this.getArg(1).equalsIgnoreCase("baby") || this.getArg(0).equalsIgnoreCase("child"))) { + this.child = true; + } + } + } + } + + @Override + protected boolean doTask() { + super.doTask(); + if (this.tileEntity.getGrabbedEntities().size() > 0) { + return false; + } + Vector3 serachPosition = this.tileEntity.getHandPosition(); + List found = this.world.getEntitiesWithinAABB(this.entityToInclude, AxisAlignedBB.getBoundingBox((double)(serachPosition.x - 0.5), (double)(serachPosition.y - 0.5), (double)(serachPosition.z - 0.5), (double)(serachPosition.x + 0.5), (double)(serachPosition.y + 0.5), (double)(serachPosition.z + 0.5))); + TileEntity ent = serachPosition.getTileEntity((IBlockAccess)this.world); + Vector3 searchPostion2 = Vector3.add(serachPosition, new Vector3(0.0, -1.0, 0.0)); + TileEntity ent2 = searchPostion2.getTileEntity((IBlockAccess)this.world); + if (ent instanceof TileEntityConveyorBelt) { + this.belt = (TileEntityConveyorBelt)ent; + } else if (ent2 instanceof TileEntityConveyorBelt) { + this.belt = (TileEntityConveyorBelt)ent2; + } + if (found != null && found.size() > 0) { + for (int i = 0; i < found.size(); ++i) { + if (found.get(i) == null || found.get(i) instanceof EntityArrow || found.get(i) instanceof EntityPlayer || ((Entity)found.get((int)i)).ridingEntity != null || found.get(i) instanceof EntityAgeable && (!(found.get(i) instanceof EntityAgeable) || this.child != ((EntityAgeable)found.get(i)).isChild())) continue; + this.tileEntity.grabEntity((Entity)found.get(i)); + this.world.playSound((double)this.tileEntity.xCoord, (double)this.tileEntity.yCoord, (double)this.tileEntity.zCoord, "random.pop", 0.2f, ((this.tileEntity.getWorldObj().rand.nextFloat() - this.tileEntity.getWorldObj().rand.nextFloat()) * 0.7f + 1.0f) * 1.0f, true); + if (this.belt != null) { + this.belt.IgnoreEntity((Entity)found.get(i)); + } + return false; + } + } + return true; + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.child = taskCompound.getBoolean("child"); + this.entityToInclude = GrabDictionary.get(taskCompound.getString("name")).getEntityClass(); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setBoolean("child", this.child); + taskCompound.setString("name", this.entityToInclude != null ? GrabDictionary.get(this.entityToInclude).getName() : ""); + } + + @Override + public String toString() { + String baby = ""; + String entity = ""; + if (this.entityToInclude != null) { + entity = GrabDictionary.get(this.entityToInclude).getName(); + if (this.child) { + baby = "baby "; + } + } + return "GRAB " + baby + entity; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandHarvest.java b/src/main/java/assemblyline/common/machine/command/CommandHarvest.java new file mode 100644 index 0000000..9ea5612 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandHarvest.java @@ -0,0 +1,20 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.CommandBreak; +import assemblyline.common.machine.command.CommandRotateTo; + +public class CommandHarvest +extends CommandBreak { + private CommandRotateTo rotateToCommand; + + @Override + public void onTaskStart() { + this.keep = true; + } + + @Override + public String toString() { + return "HARVEST"; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandIdle.java b/src/main/java/assemblyline/common/machine/command/CommandIdle.java new file mode 100644 index 0000000..0510cd7 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandIdle.java @@ -0,0 +1,47 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import net.minecraft.nbt.NBTTagCompound; + +public class CommandIdle +extends Command { + public int idleTime = 80; + private int totalIdleTime = 80; + + @Override + public void onTaskStart() { + super.onTaskStart(); + if (this.getIntArg(0) > 0) { + this.totalIdleTime = this.idleTime = this.getIntArg(0); + } + } + + @Override + protected boolean doTask() { + if (this.idleTime > 0) { + --this.idleTime; + return true; + } + return false; + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.idleTime = taskCompound.getInteger("idleTime"); + this.totalIdleTime = taskCompound.getInteger("idleTotal"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setInteger("idleTime", this.idleTime); + taskCompound.setInteger("idleTotal", this.totalIdleTime); + } + + @Override + public String toString() { + return "IDLE " + Integer.toString(this.totalIdleTime); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandManager.java b/src/main/java/assemblyline/common/machine/command/CommandManager.java new file mode 100644 index 0000000..738651c --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandManager.java @@ -0,0 +1,162 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.armbot.TileEntityArmbot; +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.CommandRepeat; +import cpw.mods.fml.common.FMLLog; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; + +public class CommandManager { + private final List tasks = new ArrayList(); + private int ticks = 0; + private int currentTask = 0; + private int lastTask = -1; + + public void onUpdate() { + try { + if (this.tasks.size() > 0) { + if (this.currentTask < this.tasks.size()) { + if (this.currentTask < 0) { + this.currentTask = 0; + this.lastTask = -1; + } + Command task = (Command)this.tasks.get(this.currentTask); + if (this.currentTask != this.lastTask) { + this.lastTask = this.currentTask; + task.onTaskStart(); + } + if (!task.doTask()) { + int tempCurrentTask = this.currentTask++; + task.onTaskEnd(); + if (!(task instanceof CommandRepeat)) { + this.tasks.set(tempCurrentTask, this.getNewCommand(task.tileEntity, task.getClass(), task.getArgs())); + } + } + } else { + this.clear(); + } + } + } + catch (Exception e) { + FMLLog.severe((String)"Failed to execute task in Assembly Line.", (Object[])new Object[0]); + e.printStackTrace(); + } + ++this.ticks; + } + + public Command getNewCommand(TileEntityArmbot tileEntity, Class commandClass, String[] parameters) { + try { + Command newCommand = (Command)commandClass.newInstance(); + newCommand.world = tileEntity.getWorldObj(); + newCommand.tileEntity = tileEntity; + newCommand.commandManager = this; + newCommand.setParameters(parameters); + return newCommand; + } + catch (Exception e) { + FMLLog.severe((String)"Failed to add command", (Object[])new Object[0]); + e.printStackTrace(); + return null; + } + } + + public void addCommand(TileEntityArmbot tileEntity, Class commandClass, String[] parameters) { + Command newCommand = this.getNewCommand(tileEntity, commandClass, parameters); + if (newCommand != null) { + this.tasks.add(newCommand); + } + } + + public void addCommand(TileEntityArmbot tileEntity, Class task) { + this.addCommand(tileEntity, task, new String[0]); + } + + public boolean hasTasks() { + return this.tasks.size() > 0; + } + + public List getCommands() { + return this.tasks; + } + + public void clear() { + this.tasks.clear(); + this.currentTask = 0; + this.lastTask = -1; + this.ticks = 0; + } + + public void setCurrentTask(int i) { + this.currentTask = Math.min(i, this.tasks.size()); + } + + public int getCurrentTask() { + return this.currentTask; + } + + public void readFromNBT(TileEntityArmbot tileEntity, NBTTagCompound nbt) { + this.currentTask = nbt.getInteger("curTasks"); + this.lastTask = nbt.getInteger("lastTask"); + this.ticks = nbt.getInteger("ticks"); + if (nbt.getInteger("numTasks") > 0) { + NBTTagList taskList = nbt.getTagList("commands", 10); + for (int i = 0; i < taskList.tagCount(); ++i) { + NBTTagCompound cmdTag = (NBTTagCompound)taskList.getCompoundTagAt(i); + try { + Class cmdClass = Class.forName(cmdTag.getString("commandClass")); + ArrayList pars = new ArrayList(); + if (cmdTag.getInteger("numParameters") > 0) { + NBTTagList parameters = cmdTag.getTagList("parameters", 8); + for (int ii = 0; ii < parameters.tagCount(); ++ii) { + pars.add(parameters.getStringTagAt((int)ii)); + } + } + Command cmd = this.getNewCommand(tileEntity, cmdClass, pars.toArray(new String[0])); + cmd.readFromNBT((NBTTagCompound)cmdTag.getTag("customData")); + continue; + } + catch (ClassNotFoundException e) { + System.out.println("Error loading CommandManger: "); + e.printStackTrace(); + } + } + } + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("numTasks", this.tasks.size()); + if (this.tasks.size() > 0) { + NBTTagList taskList = new NBTTagList(); + for (int i = 0; i < this.tasks.size(); ++i) { + NBTTagCompound taskCompound = new NBTTagCompound(); + String cmdName = ((Command)this.tasks.get(i)).getClass().getName(); + if (cmdName != null && !cmdName.isEmpty()) { + taskCompound.setString("commandClass", cmdName); + } + if (((Command)this.tasks.get(i)).getArgs().length > 0) { + NBTTagList parameters = new NBTTagList(); + for (String par : ((Command)this.tasks.get(i)).getArgs()) { + if (par == null || par.isEmpty()) continue; + parameters.appendTag((NBTBase)new NBTTagString(par)); + } + taskCompound.setTag("parameters", (NBTBase)parameters); + } + taskCompound.setInteger("numParameters", ((Command)this.tasks.get(i)).getArgs().length); + NBTTagCompound customData = new NBTTagCompound(); + ((Command)this.tasks.get(i)).writeToNBT(customData); + taskCompound.setTag("customData", customData); + taskList.appendTag((NBTBase)taskCompound); + } + nbt.setTag("commands", (NBTBase)taskList); + } + nbt.setInteger("curTask", this.currentTask); + nbt.setInteger("lastTask", this.lastTask); + nbt.setInteger("ticks", this.ticks); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandPlace.java b/src/main/java/assemblyline/common/machine/command/CommandPlace.java new file mode 100644 index 0000000..820c67c --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandPlace.java @@ -0,0 +1,58 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.IPlantable; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; + +public class CommandPlace +extends Command { + int PLACE_TIME = 30; + + @Override + public void onTaskStart() { + super.onTaskStart(); + } + + @Override + protected boolean doTask() { + super.doTask(); + Vector3 serachPosition = this.tileEntity.getHandPosition(); + Block block = serachPosition.getBlock((IBlockAccess)this.world); + if (block == null && this.ticks >= this.PLACE_TIME) { + for (Entity entity : this.tileEntity.getGrabbedEntities()) { + ItemStack itemStack; + if (!(entity instanceof EntityItem) || (itemStack = ((EntityItem)entity).getEntityItem()) == null) continue; + if (itemStack.getItem() instanceof ItemBlock) { + ((ItemBlock)itemStack.getItem()).placeBlockAt(itemStack, null, this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), 0, 0.5f, 0.5f, 0.5f, itemStack.getItemDamage()); + this.tileEntity.dropEntity(entity); + return false; + } + if (!(itemStack.getItem() instanceof IPlantable)) continue; + IPlantable plantable = (IPlantable)itemStack.getItem(); + Block blockBelow = Vector3.add(serachPosition, new Vector3(0.0, -1.0, 0.0)).getBlock((IBlockAccess)this.world); + if (blockBelow == null || !blockBelow.canSustainPlant(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), ForgeDirection.UP, plantable)) continue; + Block plantBlock = plantable.getPlant(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); + int blockMetadata = plantable.getPlantMetadata(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()); + if (!this.world.setBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), plantBlock, blockMetadata, 3) || this.world.getBlock(serachPosition.intX(), serachPosition.intY(), serachPosition.intZ()) != plantBlock) continue; + plantBlock.onBlockPlacedBy(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), null, itemStack); + plantBlock.onPostBlockPlaced(this.world, serachPosition.intX(), serachPosition.intY(), serachPosition.intZ(), blockMetadata); + this.tileEntity.dropEntity(entity); + return false; + } + } + return false; + } + + @Override + public String toString() { + return "PLACE"; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandPowerTo.java b/src/main/java/assemblyline/common/machine/command/CommandPowerTo.java new file mode 100644 index 0000000..c659811 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandPowerTo.java @@ -0,0 +1,86 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import dark.library.helpers.ItemFindingHelper; +import java.util.ArrayList; +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.vector.Vector3; + +public class CommandPowerTo +extends Command { + private int duration; + private int ticksRan; + + @Override + public void onTaskStart() { + this.duration = 0; + this.ticksRan = 0; + if (this.getArgs().length > 0) { + this.duration = this.getIntArg(0); + } + if (this.duration <= 30) { + this.duration = 30; + } + } + + @Override + protected boolean doTask() { + super.doTask(); + if (this.tileEntity.isProvidingPower && this.ticksRan >= this.duration) { + this.powerBlock(false); + return false; + } + if (this.tileEntity.isProvidingPower) { + Vector3 loc = this.tileEntity.getHandPosition(); + this.world.spawnParticle("smoke", loc.x, loc.y, loc.z, 0.0, 0.0, 0.0); + this.world.spawnParticle("flame", loc.x, loc.y, loc.z, 0.0, 0.0, 0.0); + } + Block block = this.world.getBlock(this.tileEntity.getHandPosition().intX(), this.tileEntity.getHandPosition().intY(), this.tileEntity.getHandPosition().intZ()); + TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity((IBlockAccess)this.world); + if (this.tileEntity.getGrabbedItems().size() > 0) { + ArrayList stacks = new ArrayList(); + stacks.add(new ItemStack(Blocks.redstone_torch, 1, 0)); + stacks.add(new ItemStack(Blocks.unlit_redstone_torch, 1, 0)); + if (ItemFindingHelper.filterItems(this.tileEntity.getGrabbedItems(), stacks).size() > 0) { + this.powerBlock(true); + } + } + ++this.ticksRan; + return true; + } + + public void powerBlock(boolean on) { + this.tileEntity.isProvidingPower = on; + Block block = this.tileEntity.getWorldObj().getBlock(this.tileEntity.xCoord, this.tileEntity.yCoord, this.tileEntity.zCoord); + for (int i = 2; i < 6; ++i) { + ForgeDirection dir = ForgeDirection.getOrientation((int)i); + this.world.notifyBlockOfNeighborChange(this.tileEntity.xCoord + dir.offsetX, this.tileEntity.yCoord + dir.offsetY, this.tileEntity.zCoord + dir.offsetZ, block); + } + } + + @Override + public String toString() { + return "POWERTO " + Integer.toString(this.duration); + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.duration = taskCompound.getInteger("useTimes"); + this.ticksRan = taskCompound.getInteger("useCurTimes"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setInteger("useTimes", this.duration); + taskCompound.setInteger("useCurTimes", this.ticksRan); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandRepeat.java b/src/main/java/assemblyline/common/machine/command/CommandRepeat.java new file mode 100644 index 0000000..47706f2 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandRepeat.java @@ -0,0 +1,70 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import net.minecraft.nbt.NBTTagCompound; + +public class CommandRepeat +extends Command { + private int tasksToRepeat; + private int numReps; + private int curReps; + private boolean initialized = false; + + @Override + public void onTaskStart() { + this.tasksToRepeat = Math.max(this.getIntArg(0), 0); + this.numReps = this.getIntArg(1); + if (this.numReps == 0) { + this.numReps = -1; + } + if (!this.initialized) { + this.initialized = true; + this.curReps = 0; + } + } + + @Override + public void onTaskEnd() { + if (this.curReps < this.numReps || this.numReps == -1) { + ++this.curReps; + if (this.tasksToRepeat > 0) { + this.commandManager.setCurrentTask(this.commandManager.getCurrentTask() - this.tasksToRepeat - 1); + return; + } + this.commandManager.setCurrentTask(-2); + return; + } + this.initialized = false; + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.initialized = taskCompound.getBoolean("repInitialized"); + this.tasksToRepeat = taskCompound.getInteger("repTasks"); + this.curReps = taskCompound.getInteger("repCur"); + this.numReps = taskCompound.getInteger("repGoal"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setBoolean("repInitialized", this.initialized); + taskCompound.setInteger("repTasks", this.tasksToRepeat); + taskCompound.setInteger("repCur", this.curReps); + taskCompound.setInteger("repGoal", this.numReps); + } + + @Override + public String toString() { + int cmdToTest = 0; + if (this.tasksToRepeat > 0) { + cmdToTest = this.commandManager.getCurrentTask() - this.tasksToRepeat; + } + if (this.commandManager.hasTasks() && this.commandManager.getCurrentTask() >= 0 && this.commandManager.getCurrentTask() < this.commandManager.getCommands().size()) { + return ((Command)this.commandManager.getCommands().get(cmdToTest)).toString(); + } + return "REPEAT " + Integer.toString(this.tasksToRepeat) + " " + (this.numReps > 0 ? Integer.toString(this.numReps) : ""); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandReturn.java b/src/main/java/assemblyline/common/machine/command/CommandReturn.java new file mode 100644 index 0000000..1708dbb --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandReturn.java @@ -0,0 +1,36 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.command.CommandRotateTo; + +public class CommandReturn +extends Command { + public static final float IDLE_ROTATION_PITCH = 0.0f; + public static final float IDLE_ROTATION_YAW = 0.0f; + private CommandRotateTo rotateToCommand; + + @Override + public void onTaskStart() { + this.rotateToCommand = (CommandRotateTo)this.commandManager.getNewCommand(this.tileEntity, CommandRotateTo.class, new String[]{"0", "0"}); + this.rotateToCommand.onTaskStart(); + } + + @Override + protected boolean doTask() { + if (this.rotateToCommand == null) { + this.onTaskStart(); + } + return this.rotateToCommand.doTask(); + } + + @Override + public void onTaskEnd() { + this.rotateToCommand.onTaskEnd(); + } + + @Override + public String toString() { + return "RETURN"; + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandRotateBy.java b/src/main/java/assemblyline/common/machine/command/CommandRotateBy.java new file mode 100644 index 0000000..ec71ed1 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandRotateBy.java @@ -0,0 +1,85 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import net.minecraft.nbt.NBTTagCompound; + +public class CommandRotateBy +extends Command { + float targetRotationYaw = 0.0f; + float targetRotationPitch = 0.0f; + float deltaPitch = 0.0f; + float deltaYaw = 90.0f; + float totalTicks = 0.0f; + + @Override + public void onTaskStart() { + super.onTaskStart(); + this.ticks = 0; + if (this.getArg(0) != null) { + this.targetRotationYaw = this.tileEntity.rotationYaw + this.getFloatArg(0).floatValue(); + this.deltaYaw = this.getFloatArg(0).floatValue(); + } else { + this.targetRotationYaw = this.tileEntity.rotationYaw + 90.0f; + } + if (this.getArg(1) != null) { + this.targetRotationPitch = this.tileEntity.rotationPitch + this.getFloatArg(1).floatValue(); + this.deltaPitch = this.getFloatArg(1).floatValue(); + } else { + this.targetRotationPitch = this.tileEntity.rotationPitch; + } + while (this.targetRotationYaw < 0.0f) { + this.targetRotationYaw += 360.0f; + } + while (this.targetRotationYaw > 360.0f) { + this.targetRotationYaw -= 360.0f; + } + while (this.targetRotationPitch < 0.0f) { + this.targetRotationPitch += 60.0f; + } + while (this.targetRotationPitch > 60.0f) { + this.targetRotationPitch -= 60.0f; + } + float f = Math.abs(this.targetRotationYaw - this.tileEntity.rotationYaw); + this.tileEntity.getClass(); + float totalTicksYaw = f / 1.3f; + float f2 = Math.abs(this.targetRotationPitch - this.tileEntity.rotationPitch); + this.tileEntity.getClass(); + float totalTicksPitch = f2 / 1.3f; + this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch); + } + + @Override + protected boolean doTask() { + super.doTask(); + if (Math.abs(this.tileEntity.rotationYaw - this.targetRotationYaw) > 0.001f) { + this.tileEntity.rotationYaw = this.targetRotationYaw; + } + if (Math.abs(this.tileEntity.rotationPitch - this.targetRotationPitch) > 0.001f) { + this.tileEntity.rotationPitch = this.targetRotationPitch; + } + if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f) { + return true; + } + return Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f; + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.targetRotationPitch = taskCompound.getFloat("rotPitch"); + this.targetRotationYaw = taskCompound.getFloat("rotYaw"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setFloat("rotPitch", this.targetRotationPitch); + taskCompound.setFloat("rotYaw", this.targetRotationYaw); + } + + @Override + public String toString() { + return "ROTATE " + Float.toString(this.deltaYaw) + " " + Float.toString(this.deltaPitch); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandRotateTo.java b/src/main/java/assemblyline/common/machine/command/CommandRotateTo.java new file mode 100644 index 0000000..f7709d5 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandRotateTo.java @@ -0,0 +1,70 @@ +package assemblyline.common.machine.command; + +import assemblyline.common.machine.command.Command; +import net.minecraft.nbt.NBTTagCompound; + +public class CommandRotateTo +extends Command { + float targetRotationYaw = 0.0f; + float targetRotationPitch = 0.0f; + int totalTicks = 0; + + @Override + public void onTaskStart() { + super.onTaskStart(); + this.ticks = 0; + this.totalTicks = 0; + this.targetRotationYaw = this.getArg(0) != null ? this.getFloatArg(0).floatValue() : 0.0f; + this.targetRotationPitch = this.getArg(1) != null ? this.getFloatArg(1).floatValue() : 0.0f; + while (this.targetRotationYaw < 0.0f) { + this.targetRotationYaw += 360.0f; + } + while (this.targetRotationYaw > 360.0f) { + this.targetRotationYaw -= 360.0f; + } + while (this.targetRotationPitch < -60.0f) { + this.targetRotationPitch += 60.0f; + } + while (this.targetRotationPitch > 60.0f) { + this.targetRotationPitch -= 60.0f; + } + float f = Math.abs(this.targetRotationYaw - this.tileEntity.renderYaw); + this.tileEntity.getClass(); + int totalTicksYaw = (int)(f / 1.3f); + float f2 = Math.abs(this.targetRotationPitch - this.tileEntity.renderPitch); + this.tileEntity.getClass(); + int totalTicksPitch = (int)(f2 / 1.3f); + this.totalTicks = Math.max(totalTicksYaw, totalTicksPitch); + } + + @Override + protected boolean doTask() { + super.doTask(); + this.tileEntity.rotationYaw = this.targetRotationYaw; + this.tileEntity.rotationPitch = this.targetRotationPitch; + if (Math.abs(this.tileEntity.renderPitch - this.tileEntity.rotationPitch) > 0.001f) { + return true; + } + return Math.abs(this.tileEntity.renderYaw - this.tileEntity.rotationYaw) > 0.001f; + } + + @Override + public String toString() { + return "ROTATETO " + Float.toString(this.targetRotationYaw) + " " + Float.toString(this.targetRotationPitch); + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.targetRotationPitch = taskCompound.getFloat("rotPitch"); + this.targetRotationYaw = taskCompound.getFloat("rotYaw"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setFloat("rotPitch", this.targetRotationPitch); + taskCompound.setFloat("rotYaw", this.targetRotationYaw); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/CommandUse.java b/src/main/java/assemblyline/common/machine/command/CommandUse.java new file mode 100644 index 0000000..61a8905 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/CommandUse.java @@ -0,0 +1,69 @@ +package assemblyline.common.machine.command; + +import assemblyline.api.IArmbotUseable; +import assemblyline.common.machine.command.Command; +import net.minecraft.block.Block; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; + +public class CommandUse +extends Command { + private int times; + private int curTimes; + + @Override + public void onTaskStart() { + this.times = 0; + this.curTimes = 0; + if (this.getArgs().length > 0) { + this.times = this.getIntArg(0); + } + if (this.times <= 0) { + this.times = 1; + } + } + + @Override + protected boolean doTask() { + Block block = this.world.getBlock(this.tileEntity.getHandPosition().intX(), this.tileEntity.getHandPosition().intY(), this.tileEntity.getHandPosition().intZ()); + TileEntity targetTile = this.tileEntity.getHandPosition().getTileEntity((IBlockAccess)this.world); + if (targetTile != null) { + if (targetTile instanceof IArmbotUseable) { + ((IArmbotUseable)targetTile).onUse(this.tileEntity, this.getArgs()); + } else if (targetTile instanceof ISidedInventory && this.tileEntity.getGrabbedEntities().size() > 0) { + // empty if block + } + } else if (block != null) { + try { + boolean f = block.onBlockActivated(this.world, this.tileEntity.getHandPosition().intX(), this.tileEntity.getHandPosition().intY(), this.tileEntity.getHandPosition().intZ(), null, 0, 0.0f, 0.0f, 0.0f); + } + catch (Exception e) { + e.printStackTrace(); + } + } + ++this.curTimes; + return this.curTimes < this.times; + } + + @Override + public String toString() { + return "USE " + Integer.toString(this.times); + } + + @Override + public void readFromNBT(NBTTagCompound taskCompound) { + super.readFromNBT(taskCompound); + this.times = taskCompound.getInteger("useTimes"); + this.curTimes = taskCompound.getInteger("useCurTimes"); + } + + @Override + public void writeToNBT(NBTTagCompound taskCompound) { + super.writeToNBT(taskCompound); + taskCompound.setInteger("useTimes", this.times); + taskCompound.setInteger("useCurTimes", this.curTimes); + } +} + diff --git a/src/main/java/assemblyline/common/machine/command/GrabDictionary.java b/src/main/java/assemblyline/common/machine/command/GrabDictionary.java new file mode 100644 index 0000000..d26deeb --- /dev/null +++ b/src/main/java/assemblyline/common/machine/command/GrabDictionary.java @@ -0,0 +1,102 @@ +package assemblyline.common.machine.command; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityBoat; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntityMob; +import net.minecraft.entity.monster.EntitySkeleton; +import net.minecraft.entity.monster.EntitySlime; +import net.minecraft.entity.monster.EntitySpider; +import net.minecraft.entity.monster.EntityZombie; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.entity.passive.EntityChicken; +import net.minecraft.entity.passive.EntityCow; +import net.minecraft.entity.passive.EntityPig; +import net.minecraft.entity.passive.EntitySheep; +import net.minecraft.entity.player.EntityPlayer; + +public class GrabDictionary { + private static List grabList = new ArrayList<>(); + private Class entityClass; + private String name; + + public GrabDictionary(String name, Class Class2) { + this.entityClass = Class2; + this.name = name; + } + + public static List getList() { + return grabList; + } + + public static GrabDictionary get(Object ob) { + if (ob instanceof String) { + String name = (String)ob; + for (GrabDictionary ref : grabList) { + if (!ref.getName().equalsIgnoreCase(name)) continue; + return ref; + } + } + if (ob instanceof Class) { + Class cc = (Class)ob; + for (GrabDictionary ref : grabList) { + if (ref.getEntityClass() != cc) continue; + return ref; + } + } + return new GrabDictionary("Entity", Entity.class); + } + + public String getName() { + if (this.name != null) { + return this.name; + } + return ""; + } + + public Class getEntityClass() { + if (this.entityClass != null) { + return this.entityClass; + } + return Entity.class; + } + + public static void registerGrabableEntity(String name, Class eClass) { + GrabDictionary newGrab = new GrabDictionary(name, eClass); + if (!grabList.contains(newGrab)) { + for (GrabDictionary ref : grabList) { + if (!ref.getName().equalsIgnoreCase(name)) continue; + return; + } + GrabDictionary.getList().add(newGrab); + } + } + + public static void registerList() { + GrabDictionary.registerGrabableEntity("chicken", EntityChicken.class); + GrabDictionary.registerGrabableEntity("cow", EntityCow.class); + GrabDictionary.registerGrabableEntity("sheep", EntitySheep.class); + GrabDictionary.registerGrabableEntity("pig", EntityPig.class); + GrabDictionary.registerGrabableEntity("player", EntityPlayer.class); + GrabDictionary.registerGrabableEntity("zombie", EntityZombie.class); + GrabDictionary.registerGrabableEntity("zomb", EntityZombie.class); + GrabDictionary.registerGrabableEntity("skeleton", EntitySkeleton.class); + GrabDictionary.registerGrabableEntity("skel", EntitySkeleton.class); + GrabDictionary.registerGrabableEntity("animal", EntityAnimal.class); + GrabDictionary.registerGrabableEntity("monster", EntityMob.class); + GrabDictionary.registerGrabableEntity("mob", EntityMob.class); + GrabDictionary.registerGrabableEntity("creeper", EntityCreeper.class); + GrabDictionary.registerGrabableEntity("spider", EntitySpider.class); + GrabDictionary.registerGrabableEntity("slime", EntitySlime.class); + GrabDictionary.registerGrabableEntity("items", EntityItem.class); + GrabDictionary.registerGrabableEntity("all", Entity.class); + GrabDictionary.registerGrabableEntity("everything", Entity.class); + GrabDictionary.registerGrabableEntity("boat", EntityBoat.class); + GrabDictionary.registerGrabableEntity("cart", EntityMinecart.class); + } +} + diff --git a/src/main/java/assemblyline/common/machine/crane/BlockCraneController.java b/src/main/java/assemblyline/common/machine/crane/BlockCraneController.java new file mode 100644 index 0000000..3fc5bb4 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/crane/BlockCraneController.java @@ -0,0 +1,64 @@ +package assemblyline.common.machine.crane; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; + +public class BlockCraneController +extends BlockALMachine { + public BlockCraneController() { + super(UniversalElectricity.machine); + this.setBlockName("craneController"); + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { + int rot = (int)Math.min((entity.rotationYaw + 315.0f) % 360.0f / 90.0f, 3.0f); + switch (rot) { + case 0: { + world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal(), 3); + break; + } + case 1: { + world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal(), 3); + break; + } + case 2: { + world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal(), 3); + break; + } + default: { + world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal(), 3); + } + } + } + + @Override + @SideOnly(value=Side.CLIENT) + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } + + @Override + public TileEntity createNewTileEntity(World world, int metadata) { + return new TileEntityCraneController(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/crane/BlockCraneFrame.java b/src/main/java/assemblyline/common/machine/crane/BlockCraneFrame.java new file mode 100644 index 0000000..ec76ae6 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/crane/BlockCraneFrame.java @@ -0,0 +1,126 @@ +package assemblyline.common.machine.crane; + +import assemblyline.client.render.BlockRenderingHandler; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; + +public class BlockCraneFrame +extends BlockALMachine { + public BlockCraneFrame() { + super(UniversalElectricity.machine); + this.setBlockName("craneFrame"); + this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + } + + @Override + public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { + TileEntity tE = world.getTileEntity(x, y, z); + if (tE != null && tE instanceof TileEntityCraneRail) { + AxisAlignedBB middle = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.25, (double)0.75, (double)0.75, (double)0.75); + AxisAlignedBB up = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.75, (double)0.25, (double)0.75, (double)1.0, (double)0.75); + AxisAlignedBB down = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.0, (double)0.25, (double)0.75, (double)0.25, (double)0.75); + AxisAlignedBB left = AxisAlignedBB.getBoundingBox((double)0.0, (double)0.25, (double)0.25, (double)0.25, (double)0.75, (double)0.75); + AxisAlignedBB right = AxisAlignedBB.getBoundingBox((double)0.75, (double)0.25, (double)0.25, (double)1.0, (double)0.75, (double)0.75); + AxisAlignedBB front = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.0, (double)0.75, (double)0.75, (double)0.25); + AxisAlignedBB back = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.75, (double)0.75, (double)0.75, (double)1.0); + boolean connectUp = CraneHelper.canFrameConnectTo(tE, x, y + 1, z, ForgeDirection.DOWN); + boolean connectDown = CraneHelper.canFrameConnectTo(tE, x, y - 1, z, ForgeDirection.UP); + boolean connectLeft = CraneHelper.canFrameConnectTo(tE, x - 1, y, z, ForgeDirection.EAST); + boolean connectRight = CraneHelper.canFrameConnectTo(tE, x + 1, y, z, ForgeDirection.WEST); + boolean connectFront = CraneHelper.canFrameConnectTo(tE, x, y, z - 1, ForgeDirection.SOUTH); + boolean connectBack = CraneHelper.canFrameConnectTo(tE, x, y, z + 1, ForgeDirection.NORTH); + if (connectUp) { + middle.maxY = up.maxY; + } + if (connectDown) { + middle.minY = down.minY; + } + if (connectLeft) { + middle.minX = left.minX; + } + if (connectRight) { + middle.maxX = right.maxX; + } + if (connectFront) { + middle.minZ = front.minZ; + } + if (connectBack) { + middle.maxZ = back.maxZ; + } + this.setBlockBounds((float)middle.minX, (float)middle.minY, (float)middle.minZ, (float)middle.maxX, (float)middle.maxY, (float)middle.maxZ); + middle.offset((double)x, (double)y, (double)z); + return middle; + } + return super.getCollisionBoundingBoxFromPool(world, x, y, z); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { + TileEntity tE = world.getTileEntity(x, y, z); + if (tE != null && tE instanceof TileEntityCraneRail) { + AxisAlignedBB middle = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.25, (double)0.75, (double)0.75, (double)0.75); + AxisAlignedBB up = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.75, (double)0.25, (double)0.75, (double)1.0, (double)0.75); + AxisAlignedBB down = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.0, (double)0.25, (double)0.75, (double)0.25, (double)0.75); + AxisAlignedBB left = AxisAlignedBB.getBoundingBox((double)0.0, (double)0.25, (double)0.25, (double)0.25, (double)0.75, (double)0.75); + AxisAlignedBB right = AxisAlignedBB.getBoundingBox((double)0.75, (double)0.25, (double)0.25, (double)1.0, (double)0.75, (double)0.75); + AxisAlignedBB front = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.0, (double)0.75, (double)0.75, (double)0.25); + AxisAlignedBB back = AxisAlignedBB.getBoundingBox((double)0.25, (double)0.25, (double)0.75, (double)0.75, (double)0.75, (double)1.0); + boolean connectUp = CraneHelper.canFrameConnectTo(tE, x, y + 1, z, ForgeDirection.DOWN); + boolean connectDown = CraneHelper.canFrameConnectTo(tE, x, y - 1, z, ForgeDirection.UP); + boolean connectLeft = CraneHelper.canFrameConnectTo(tE, x - 1, y, z, ForgeDirection.EAST); + boolean connectRight = CraneHelper.canFrameConnectTo(tE, x + 1, y, z, ForgeDirection.WEST); + boolean connectFront = CraneHelper.canFrameConnectTo(tE, x, y, z - 1, ForgeDirection.SOUTH); + boolean connectBack = CraneHelper.canFrameConnectTo(tE, x, y, z + 1, ForgeDirection.NORTH); + if (connectUp) { + middle.maxY = up.maxY; + } + if (connectDown) { + middle.minY = down.minY; + } + if (connectLeft) { + middle.minX = left.minX; + } + if (connectRight) { + middle.maxX = right.maxX; + } + if (connectFront) { + middle.minZ = front.minZ; + } + if (connectBack) { + middle.maxZ = back.maxZ; + } + this.setBlockBounds((float)middle.minX, (float)middle.minY, (float)middle.minZ, (float)middle.maxX, (float)middle.maxY, (float)middle.maxZ); + return; + } + this.setBlockBounds(0.25f, 0.25f, 0.25f, 0.75f, 0.75f, 0.75f); + } + + @Override + public TileEntity createNewTileEntity(World world, int metadata) { + return new TileEntityCraneRail(); + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + @SideOnly(value=Side.CLIENT) + public int getRenderType() { + return BlockRenderingHandler.BLOCK_RENDER_ID; + } +} + diff --git a/src/main/java/assemblyline/common/machine/crane/CraneHelper.java b/src/main/java/assemblyline/common/machine/crane/CraneHelper.java new file mode 100644 index 0000000..586d620 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/crane/CraneHelper.java @@ -0,0 +1,59 @@ +package assemblyline.common.machine.crane; + +import assemblyline.api.ICraneConnectable; +import assemblyline.api.ICraneStructure; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +public class CraneHelper { + public static final int MAX_SIZE = 64; + + public static boolean isCraneBlock(World world, int x, int y, int z) { + return world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof ICraneConnectable; + } + + public static boolean isCraneStructureBlock(World world, int x, int y, int z) { + return world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof ICraneStructure; + } + + public static boolean canFrameConnectTo(TileEntity tileEntity, int x, int y, int z, ForgeDirection side) { + if (tileEntity.getWorldObj().getTileEntity(x, y, z) != null && tileEntity.getWorldObj().getTileEntity(x, y, z) instanceof ICraneConnectable) { + return ((ICraneConnectable)tileEntity.getWorldObj().getTileEntity(x, y, z)).canFrameConnectTo(side); + } + return false; + } + + public static ForgeDirection rotateClockwise(ForgeDirection direction) { + if (direction == ForgeDirection.NORTH) { + return ForgeDirection.EAST; + } + if (direction == ForgeDirection.EAST) { + return ForgeDirection.SOUTH; + } + if (direction == ForgeDirection.SOUTH) { + return ForgeDirection.WEST; + } + if (direction == ForgeDirection.WEST) { + return ForgeDirection.NORTH; + } + return ForgeDirection.UNKNOWN; + } + + public static ForgeDirection rotateCounterClockwise(ForgeDirection direction) { + if (direction == ForgeDirection.NORTH) { + return ForgeDirection.WEST; + } + if (direction == ForgeDirection.WEST) { + return ForgeDirection.SOUTH; + } + if (direction == ForgeDirection.SOUTH) { + return ForgeDirection.EAST; + } + if (direction == ForgeDirection.EAST) { + return ForgeDirection.NORTH; + } + return ForgeDirection.UNKNOWN; + } +} + diff --git a/src/main/java/assemblyline/common/machine/crane/TileEntityCraneController.java b/src/main/java/assemblyline/common/machine/crane/TileEntityCraneController.java new file mode 100644 index 0000000..d5d9d0d --- /dev/null +++ b/src/main/java/assemblyline/common/machine/crane/TileEntityCraneController.java @@ -0,0 +1,159 @@ +package assemblyline.common.machine.crane; + +import assemblyline.api.ICraneConnectable; +import assemblyline.common.machine.TileEntityAssemblyNetwork; +import assemblyline.common.machine.crane.CraneHelper; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityCraneController +extends TileEntityAssemblyNetwork +implements ICraneConnectable { + int width = 0; + int height = 0; + int depth = 0; + boolean isCraneValid = false; + long ticks = 0L; + + @Override + public void updateEntity() { + ++this.ticks; + if (this.ticks % 20L == 0L) { + this.validateCrane(); + } + } + + public boolean isCraneValid() { + return this.isCraneValid; + } + + private void validateCrane() { + this.isCraneValid = false; + this.depth = 0; + this.height = 0; + this.width = 0; + this.findCraneHeight(); + this.findCraneWidth(); + this.findCraneDepth(); + if (Math.abs(this.height) > 1 && Math.abs(this.width) > 1 && Math.abs(this.depth) > 1) { + this.isCraneValid = this.isFrameValid(); + } + } + + private boolean isFrameValid() { + int z; + int x; + for (x = Math.min(0, this.width); x <= Math.max(0, this.width); ++x) { + if (CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord + x, this.yCoord + this.height, this.zCoord)) continue; + return false; + } + for (x = Math.min(0, this.width); x <= Math.max(0, this.width); ++x) { + if (CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord + x, this.yCoord + this.height, this.zCoord + this.depth)) continue; + return false; + } + for (z = Math.min(0, this.depth); z <= Math.max(0, this.depth); ++z) { + if (CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord, this.yCoord + this.height, this.zCoord + z)) continue; + return false; + } + for (z = Math.min(0, this.depth); z <= Math.max(0, this.depth); ++z) { + if (CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord + this.width, this.yCoord + this.height, this.zCoord + z)) continue; + return false; + } + for (x = Math.min(this.width + 1, 1); x <= Math.max(-1, this.width - 1); ++x) { + for (int z2 = Math.min(this.depth + 1, 1); z2 <= Math.max(-1, this.depth - 1); ++z2) { + if (this.worldObj.isAirBlock(this.xCoord + x, this.yCoord + this.height, this.zCoord + z2)) continue; + return false; + } + } + return true; + } + + private void findCraneWidth() { + if (this.height == 0) { + this.width = 0; + return; + } + int x = 0; + ForgeDirection facing = ForgeDirection.getOrientation((int)this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + while (Math.abs(x) <= 64 && CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord + x, this.yCoord + this.height, this.zCoord)) { + if (facing == ForgeDirection.NORTH || facing == ForgeDirection.EAST) { + ++x; + continue; + } + --x; + } + this.width = x; + if (this.width < 0) { + ++this.width; + } + if (this.width > 0) { + --this.width; + } + } + + private void findCraneHeight() { + int y; + for (y = 1; this.yCoord + y < 256 && y <= 64 && CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord, this.yCoord + y, this.zCoord); ++y) { + } + this.height = y - 1; + } + + private void findCraneDepth() { + if (this.height == 0) { + this.width = 0; + return; + } + int z = 0; + ForgeDirection facing = ForgeDirection.getOrientation((int)this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + while (Math.abs(z) <= 64 && CraneHelper.isCraneStructureBlock(this.worldObj, this.xCoord, this.yCoord + this.height, this.zCoord + z)) { + if (facing == ForgeDirection.SOUTH || facing == ForgeDirection.EAST) { + ++z; + continue; + } + --z; + } + this.depth = z; + if (this.depth < 0) { + ++this.depth; + } + if (this.depth > 0) { + --this.depth; + } + } + + @Override + public boolean canFrameConnectTo(ForgeDirection side) { + ForgeDirection facing = ForgeDirection.getOrientation((int)this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); + if (side == facing) { + return true; + } + if (side == CraneHelper.rotateClockwise(facing)) { + return true; + } + return side == ForgeDirection.UP; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setInteger("width", this.width); + nbt.setInteger("height", this.height); + nbt.setInteger("depth", this.depth); + nbt.setBoolean("isValid", this.isCraneValid); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.width = nbt.getInteger("width"); + this.height = nbt.getInteger("height"); + this.depth = nbt.getInteger("depth"); + this.isCraneValid = nbt.getBoolean("isValid"); + } + + @Override + public boolean canConnect(ForgeDirection direction) { + return true; + } +} + diff --git a/src/main/java/assemblyline/common/machine/crane/TileEntityCraneRail.java b/src/main/java/assemblyline/common/machine/crane/TileEntityCraneRail.java new file mode 100644 index 0000000..9eb5bb5 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/crane/TileEntityCraneRail.java @@ -0,0 +1,20 @@ +package assemblyline.common.machine.crane; + +import assemblyline.api.ICraneStructure; +import assemblyline.common.machine.TileEntityAssemblyNetwork; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityCraneRail +extends TileEntityAssemblyNetwork +implements ICraneStructure { + @Override + public boolean canFrameConnectTo(ForgeDirection side) { + return true; + } + + @Override + public boolean canConnect(ForgeDirection direction) { + return false; + } +} + diff --git a/src/main/java/assemblyline/common/machine/detector/BlockDetector.java b/src/main/java/assemblyline/common/machine/detector/BlockDetector.java new file mode 100644 index 0000000..3f57baa --- /dev/null +++ b/src/main/java/assemblyline/common/machine/detector/BlockDetector.java @@ -0,0 +1,146 @@ +package assemblyline.common.machine.detector; + +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.machine.detector.TileEntityDetector; +import assemblyline.common.machine.imprinter.BlockImprintable; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.UniversalElectricity; + +public class BlockDetector +extends BlockImprintable { + IIcon eye_red; + IIcon eye_green; + + public BlockDetector() { + super("detector", UniversalElectricity.machine, TabAssemblyLine.INSTANCE); + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { + int angle = MathHelper.floor_double((double)((double)(entity.rotationYaw * 4.0f / 360.0f) + 0.5)) & 3; + int change = 2; + switch (angle) { + case 0: { + change = ForgeDirection.NORTH.ordinal(); + break; + } + case 1: { + change = ForgeDirection.EAST.ordinal(); + break; + } + case 2: { + change = ForgeDirection.SOUTH.ordinal(); + break; + } + case 3: { + change = ForgeDirection.WEST.ordinal(); + } + } + if (entity.rotationPitch < -70.0f) { + change = ForgeDirection.DOWN.ordinal(); + } + if (entity.rotationPitch > 70.0f) { + change = ForgeDirection.UP.ordinal(); + } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg) { + super.registerBlockIcons(iconReg); + this.eye_green = iconReg.registerIcon("assemblyline:detector_green"); + this.eye_red = iconReg.registerIcon("assemblyline:detector_red"); + } + + @Override + public IIcon getIcon(IBlockAccess iBlockAccess, int x, int y, int z, int side) { + TileEntity tileEntity = iBlockAccess.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityDetector && side == ForgeDirection.getOrientation((int)iBlockAccess.getBlockMetadata(x, y, z)).ordinal()) { + if (((TileEntityDetector)tileEntity).isInverted()) { + return this.eye_red; + } + return this.eye_green; + } + return this.machine_icon; + } + + @Override + public IIcon getIcon(int side, int metadata) { + if (side == ForgeDirection.SOUTH.ordinal()) { + return this.eye_green; + } + return this.machine_icon; + } + + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + world.setBlockMetadataWithNotify(x, y, z, side, 3); + return true; + } + + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block blockID) { + if (!this.canBlockStay(world, x, y, z)) { + this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0); + world.setBlock(x, y, z, Blocks.air, 0, 3); + } + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + public boolean isBlockNormalCube(World world, int x, int y, int z) { + return false; + } + + @Override + public boolean isBlockSolid(IBlockAccess par1iBlockAccess, int par2, int par3, int par4, int par5) { + return false; + } + + public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) { + return false; + } + + @Override + public boolean renderAsNormalBlock() { + return false; + } + + @Override + public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int direction) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityDetector) { + return ((TileEntityDetector)tileEntity).isPoweringTo(ForgeDirection.getOrientation((int)direction)); + } + return 0; + } + + @Override + public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int direction) { + return this.isProvidingStrongPower(world, x, y, z, direction); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileEntityDetector(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/detector/TileEntityDetector.java b/src/main/java/assemblyline/common/machine/detector/TileEntityDetector.java new file mode 100644 index 0000000..d3173ce --- /dev/null +++ b/src/main/java/assemblyline/common/machine/detector/TileEntityDetector.java @@ -0,0 +1,85 @@ +package assemblyline.common.machine.detector; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.imprinter.TileEntityFilterable; +import java.util.ArrayList; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityDetector +extends TileEntityFilterable { + private boolean powering = false; + + @Override + public void updateEntity() { + super.updateEntity(); + if (!this.worldObj.isRemote && this.ticks % 10L == 0L) { + int metadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); + AxisAlignedBB testArea = AxisAlignedBB.getBoundingBox((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)); + ForgeDirection dir = ForgeDirection.getOrientation((int)metadata); + testArea.offset((double)dir.offsetX, (double)dir.offsetY, (double)dir.offsetZ); + ArrayList entities = (ArrayList)this.worldObj.getEntitiesWithinAABB(EntityItem.class, testArea); + boolean powerCheck = false; + if (entities.size() > 0) { + if (this.getFilter() != null) { + for (int i = 0; i < entities.size(); ++i) { + EntityItem e = (EntityItem)entities.get(i); + ItemStack itemStack = e.getEntityItem(); + powerCheck = this.isFiltering(itemStack); + } + } else { + powerCheck = true; + } + } else { + powerCheck = false; + } + if (powerCheck != this.powering) { + this.powering = powerCheck; + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, AssemblyLine.blockDetector); + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector); + for (int x = this.xCoord - 1; x <= this.xCoord + 1; ++x) { + for (int z = this.zCoord - 1; z <= this.zCoord + 1; ++z) { + this.worldObj.notifyBlocksOfNeighborChange(x, this.yCoord + 1, z, AssemblyLine.blockDetector); + } + } + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + } + + @Override + public void invalidate() { + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, AssemblyLine.blockDetector); + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector); + super.invalidate(); + } + + @Override + public void readFromNBT(NBTTagCompound tag) { + super.readFromNBT(tag); + this.powering = tag.getBoolean("powering"); + } + + @Override + public void writeToNBT(NBTTagCompound tag) { + super.writeToNBT(tag); + tag.setBoolean("powering", this.powering); + } + + public int isPoweringTo(ForgeDirection side) { + return this.powering && this.getDirection() != side.getOpposite() ? 15 : 0; + } + + public boolean isIndirectlyPoweringTo(ForgeDirection side) { + return this.isPoweringTo(side) > 0; + } + + @Override + public boolean canConnect(ForgeDirection direction) { + return direction != this.getDirection(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/BlockEncoder.java b/src/main/java/assemblyline/common/machine/encoder/BlockEncoder.java new file mode 100644 index 0000000..c044f59 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/BlockEncoder.java @@ -0,0 +1,64 @@ +package assemblyline.common.machine.encoder; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class BlockEncoder +extends BlockALMachine { + IIcon encoder_side; + IIcon encoder_top; + IIcon encoder_bottom; + + public BlockEncoder() { + super(Material.wood); + this.setBlockName("encoder"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg) { + this.encoder_side = iconReg.registerIcon("assemblyline:encoder_side"); + this.encoder_top = iconReg.registerIcon("assemblyline:encoder_top"); + this.encoder_bottom = iconReg.registerIcon("assemblyline:encoder_bottom"); + } + + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + return this.getIcon(side, 0); + } + + @Override + public IIcon getIcon(int side, int meta) { + if (side == 1) { + return this.encoder_top; + } + if (side == 0) { + return this.encoder_bottom; + } + return this.encoder_side; + } + + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { + if (!world.isRemote) { + entityPlayer.openGui((Object)AssemblyLine.instance, 2, world, x, y, z); + } + return true; + } + + public TileEntity createNewTileEntity(World world, int metadata) { + return new TileEntityEncoder(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/ContainerEncoder.java b/src/main/java/assemblyline/common/machine/encoder/ContainerEncoder.java new file mode 100644 index 0000000..ff8b2b0 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/ContainerEncoder.java @@ -0,0 +1,60 @@ +package assemblyline.common.machine.encoder; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.imprinter.SlotCustom; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerEncoder +extends Container { + public static final int Y_OFFSET = 0; + private ItemStack[] containingItems = new ItemStack[1]; + private InventoryPlayer inventoryPlayer; + private TileEntityEncoder tileEntity; + + public ContainerEncoder(InventoryPlayer inventoryPlayer, TileEntityEncoder encoder) { + int var3; + this.inventoryPlayer = inventoryPlayer; + this.tileEntity = encoder; + this.addSlotToContainer(new SlotCustom((IInventory)encoder, 0, 80, 24, new ItemStack(AssemblyLine.itemDisk))); + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new Slot((IInventory)inventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 155 + var3 * 18 + 0)); + } + } + for (var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new Slot((IInventory)inventoryPlayer, var3, 8 + var3 * 18, 213)); + } + } + + public boolean canInteractWith(EntityPlayer player) { + return this.tileEntity.isUseableByPlayer(player); + } + + public ItemStack transferStackInSlot(EntityPlayer player, int slot) { + ItemStack copyStack = null; + Slot slotObj = (Slot)this.inventorySlots.get(slot); + if (slotObj != null && slotObj.getHasStack()) { + ItemStack slotStack = slotObj.getStack(); + copyStack = slotStack.copy(); + if (slot >= 1 ? this.getSlot(0).isItemValid(slotStack) && !this.mergeItemStack(slotStack, 0, 1, false) : !this.mergeItemStack(slotStack, this.containingItems.length, 37, false)) { + return null; + } + if (slotStack.stackSize == 0) { + slotObj.putStack((ItemStack)null); + } else { + slotObj.onSlotChanged(); + } + if (slotStack.stackSize == copyStack.stackSize) { + return null; + } + slotObj.onPickupFromSlot(player, slotStack); + } + return copyStack; + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/IInventoryWatcher.java b/src/main/java/assemblyline/common/machine/encoder/IInventoryWatcher.java new file mode 100644 index 0000000..c02ffbc --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/IInventoryWatcher.java @@ -0,0 +1,6 @@ +package assemblyline.common.machine.encoder; + +public interface IInventoryWatcher { + public void inventoryChanged(); +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/ItemDisk.java b/src/main/java/assemblyline/common/machine/encoder/ItemDisk.java new file mode 100644 index 0000000..6beee16 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/ItemDisk.java @@ -0,0 +1,79 @@ +package assemblyline.common.machine.encoder; + +import assemblyline.common.TabAssemblyLine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +public class ItemDisk +extends Item { + public ItemDisk() { + super(); + this.setUnlocalizedName("disk"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + this.setHasSubtypes(true); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + this.itemIcon = par1IconRegister.registerIcon("assemblyline:disk"); + } + + @Override + public int getItemStackLimit() { + return 1; + } + + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) { + ArrayList commands = ItemDisk.getCommands(itemStack); + if (commands.size() > 0) { + if (commands.size() == 1) { + list.add(commands.size() + " command"); + } else { + list.add(commands.size() + " commands"); + } + } else { + list.add("No commands"); + } + } + + public static void setCommands(ItemStack itemStack, ArrayList commands) { + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + NBTTagList nbt = new NBTTagList(); + for (int i = 0; i < commands.size(); ++i) { + if (commands.get(i) == null) continue; + NBTTagCompound newCompound = new NBTTagCompound(); + newCompound.setString("command", (String)commands.get(i)); + nbt.appendTag((NBTBase)newCompound); + } + itemStack.getTagCompound().setTag("Commands", (NBTBase)nbt); + } + + public static ArrayList getCommands(ItemStack itemStack) { + ArrayList commands = new ArrayList(); + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList tagList = nbt.getTagList("Commands", 10); + for (int i = 0; i < tagList.tagCount(); ++i) { + NBTTagCompound curTag = tagList.getCompoundTagAt(i); + String cmd = curTag.getString("command"); + commands.add(cmd); + } + return commands; + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/SlotDisk.java b/src/main/java/assemblyline/common/machine/encoder/SlotDisk.java new file mode 100644 index 0000000..3615bce --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/SlotDisk.java @@ -0,0 +1,18 @@ +package assemblyline.common.machine.encoder; + +import assemblyline.common.AssemblyLine; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotDisk +extends Slot { + public SlotDisk(IInventory par1iInventory, int par2, int par3, int par4) { + super(par1iInventory, par2, par3, par4); + } + + public boolean isItemValid(ItemStack itemStack) { + return itemStack.getItem() == AssemblyLine.itemDisk; + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/SlotDiskResult.java b/src/main/java/assemblyline/common/machine/encoder/SlotDiskResult.java new file mode 100644 index 0000000..3289f23 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/SlotDiskResult.java @@ -0,0 +1,28 @@ +package assemblyline.common.machine.encoder; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotDiskResult +extends Slot { + public SlotDiskResult(IInventory par1iInventory, int par2, int par3, int par4) { + super(par1iInventory, par2, par3, par4); + } + + public boolean isItemValid(ItemStack par1ItemStack) { + return false; + } + + public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) { + super.onPickupFromSlot(par1EntityPlayer, par2ItemStack); + if (this.inventory.getStackInSlot(0) != null) { + --this.inventory.getStackInSlot((int)0).stackSize; + if (this.inventory.getStackInSlot((int)0).stackSize <= 0) { + this.inventory.setInventorySlotContents(0, null); + } + } + } +} + diff --git a/src/main/java/assemblyline/common/machine/encoder/TileEntityEncoder.java b/src/main/java/assemblyline/common/machine/encoder/TileEntityEncoder.java new file mode 100644 index 0000000..99cd121 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/encoder/TileEntityEncoder.java @@ -0,0 +1,163 @@ +package assemblyline.common.machine.encoder; + +import assemblyline.common.machine.command.Command; +import assemblyline.common.machine.encoder.IInventoryWatcher; +import assemblyline.common.machine.encoder.ItemDisk; +import com.google.common.io.ByteArrayDataInput; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import java.util.ArrayList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.tile.TileEntityAdvanced; + +public class TileEntityEncoder +extends TileEntityAdvanced +implements ISidedInventory { + private ItemStack disk; + private IInventoryWatcher watcher; + + @Override + public int getSizeInventory() { + return 1; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (slot == 0) { + return this.disk; + } + return null; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + if (slot == 0 && amount >= 1) { + ItemStack ret = this.disk.copy(); + this.disk = null; + return ret; + } + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + return null; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack stack) { + if (slot == 0) { + if (stack != null && stack.stackSize > 1) { + stack.stackSize = 1; + } + this.disk = stack; + } + } + + @Override + public void markDirty() { + super.markDirty(); + if (this.watcher != null) { + this.watcher.inventoryChanged(); + } + } + + @Override + public String getInventoryName() { + return "Encoder"; + } + + @Override + public int getInventoryStackLimit() { + return 1; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + public void setWatcher(IInventoryWatcher watcher) { + this.watcher = watcher; + } + + public IInventoryWatcher getWatcher() { + return this.watcher; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + if (this.disk != null) { + NBTTagCompound diskNBT = new NBTTagCompound(); + this.disk.writeToNBT(diskNBT); + nbt.setTag("disk", diskNBT); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagCompound diskNBT = nbt.getCompoundTag("disk"); + if (diskNBT != null) { + this.disk = ItemStack.loadItemStackFromNBT((NBTTagCompound)diskNBT); + } + } + + public void handleMessage(NBTTagCompound nbt) { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER && this.disk != null) { + ArrayList tempCmds = ItemDisk.getCommands(this.disk); + if (nbt.getBoolean("create")) { + String newCommand = nbt.getString("newCommand"); + String commandName = newCommand.split(" ")[0]; + if (Command.getCommand(commandName) != null) { + tempCmds.add(newCommand); + } + } else { + int commandToRemove = nbt.getInteger("commandToRemove"); + tempCmds.remove(commandToRemove); + } + ItemDisk.setCommands(this.disk, tempCmds); + } + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return false; + } + + @Override + public boolean canExtractItem(int arg0, ItemStack arg1, int arg2) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean canInsertItem(int arg0, ItemStack arg1, int arg2) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(int side) { + return side == ForgeDirection.UP.ordinal() ? new int[] {0} : new int[0]; + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/BlockImprintable.java b/src/main/java/assemblyline/common/machine/imprinter/BlockImprintable.java new file mode 100644 index 0000000..e3b837f --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/BlockImprintable.java @@ -0,0 +1,123 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.api.IFilterable; +import assemblyline.common.block.BlockALMachine; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import universalelectricity.prefab.implement.IRedstoneReceptor; + +public abstract class BlockImprintable +extends BlockALMachine { + public BlockImprintable(String name, Material material, CreativeTabs creativeTab) { + super(material); + this.setBlockName(name); + this.setCreativeTab(creativeTab); + } + + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof IFilterable) { + ItemStack containingStack = ((IFilterable)tileEntity).getFilter(); + if (containingStack != null) { + if (!world.isRemote) { + EntityItem dropStack = new EntityItem(world, player.posX, player.posY, player.posZ, containingStack); + dropStack.delayBeforeCanPickup = 0; + world.spawnEntityInWorld((Entity)dropStack); + } + ((IFilterable)tileEntity).setFilter(null); + return true; + } + if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemImprinter) { + ((IFilterable)tileEntity).setFilter(player.getCurrentEquippedItem()); + player.inventory.setInventorySlotContents(player.inventory.currentItem, null); + return true; + } + } + return false; + } + + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof TileEntityFilterable) { + ((TileEntityFilterable)tileEntity).toggleInversion(); + world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); + world.markBlockForUpdate(x, y, z); + } + return true; + } + + @Override + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + return this.onMachineActivated(world, x, y, z, player, side, hitX, hitY, hitZ); + } + + @Override + public void onNeighborBlockChange(World par1World, int x, int y, int z, Block side) { + super.onNeighborBlockChange(par1World, x, y, z, side); + TileEntity tileEntity = par1World.getTileEntity(x, y, z); + if (tileEntity instanceof IRedstoneReceptor && par1World.isBlockIndirectlyGettingPowered(x, y, z)) { + ((IRedstoneReceptor)par1World.getTileEntity(x, y, z)).onPowerOn(); + } + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack stack) { + int angle = MathHelper.floor_double((double)((double)(par5EntityLiving.rotationYaw * 4.0f / 360.0f) + 0.5)) & 3; + int change = 2; + switch (angle) { + case 0: { + change = 2; + break; + } + case 1: { + change = 5; + break; + } + case 2: { + change = 3; + break; + } + case 3: { + change = 4; + } + } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + } + + @Override + public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + int original = world.getBlockMetadata(x, y, z); + int change = 2; + switch (original) { + case 2: { + change = 4; + break; + } + case 3: { + change = 5; + break; + } + case 4: { + change = 3; + break; + } + case 5: { + change = 2; + } + } + world.setBlockMetadataWithNotify(x, y, z, change, 3); + return true; + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/BlockImprinter.java b/src/main/java/assemblyline/common/machine/imprinter/BlockImprinter.java new file mode 100644 index 0000000..d64d029 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/BlockImprinter.java @@ -0,0 +1,117 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.TabAssemblyLine; +import assemblyline.common.block.BlockALMachine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class BlockImprinter +extends BlockALMachine { + IIcon imprinter_side; + IIcon imprinter_top; + IIcon imprinter_bottom; + + public BlockImprinter() { + super(Material.wood); + this.setBlockName("imprinter"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerBlockIcons(IIconRegister iconReg) { + this.imprinter_side = iconReg.registerIcon("assemblyline:imprinter_side"); + this.imprinter_top = iconReg.registerIcon("assemblyline:imprinter_top"); + this.imprinter_bottom = iconReg.registerIcon("assemblyline:imprinter_bottom"); + } + + @Override + @SideOnly(value=Side.CLIENT) + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + return this.getIcon(side, 0); + } + + @Override + public IIcon getIcon(int side, int meta) { + if (side == 1) { + return this.imprinter_top; + } + if (side == 0) { + return this.imprinter_bottom; + } + return this.imprinter_side; + } + + @Override + public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) { + if (!world.isRemote) { + entityPlayer.openGui((Object)AssemblyLine.instance, 1, world, x, y, z); + } + return true; + } + + @Override + public void dropEntireInventory(World par1World, int x, int y, int z, Block par5, int par6) { + TileEntity tileEntity = par1World.getTileEntity(x, y, z); + if (tileEntity != null && tileEntity instanceof TileEntityImprinter) { + TileEntityImprinter inventory = (TileEntityImprinter)tileEntity; + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + ItemStack itemStack = inventory.getStackInSlot(i); + if (itemStack == null) continue; + Random random = new Random(); + float var8 = random.nextFloat() * 0.8f + 0.1f; + float var9 = random.nextFloat() * 0.8f + 0.1f; + float var10 = random.nextFloat() * 0.8f + 0.1f; + while (itemStack.stackSize > 0) { + int var11 = random.nextInt(21) + 10; + if (var11 > itemStack.stackSize) { + var11 = itemStack.stackSize; + } + itemStack.stackSize -= var11; + if (i == inventory.imprinterMatrix.length + 9 - 1) continue; + EntityItem entityItem = new EntityItem(par1World, (double)((float)x + var8), (double)((float)y + var9), (double)((float)z + var10), new ItemStack(itemStack.getItem(), var11, itemStack.getItemDamage())); + if (itemStack.hasTagCompound()) { + entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy()); + } + float var13 = 0.05f; + entityItem.motionX = (float)random.nextGaussian() * var13; + entityItem.motionY = (float)random.nextGaussian() * var13 + 0.2f; + entityItem.motionZ = (float)random.nextGaussian() * var13; + par1World.spawnEntityInWorld((Entity)entityItem); + } + } + } + } + + @Override + public boolean onUseWrench(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ) { + TileEntity tileEntity = par1World.getTileEntity(x, y, z); + if (tileEntity instanceof TileEntityImprinter) { + ((TileEntityImprinter)tileEntity).searchInventories = !((TileEntityImprinter)tileEntity).searchInventories; + par1World.markBlockForUpdate(x, y, z); + return true; + } + return false; + } + + @Override + public TileEntity createNewTileEntity(World var1, int meta) { + return new TileEntityImprinter(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/ContainerImprinter.java b/src/main/java/assemblyline/common/machine/imprinter/ContainerImprinter.java new file mode 100644 index 0000000..f3c6ef3 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/ContainerImprinter.java @@ -0,0 +1,100 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.common.AssemblyLine; +import assemblyline.common.machine.imprinter.ISlotWatcher; +import assemblyline.common.machine.imprinter.SlotCraftingResult; +import assemblyline.common.machine.imprinter.SlotCustom; +import assemblyline.common.machine.imprinter.TileEntityImprinter; +import assemblyline.common.machine.imprinter.WatchedSlot; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerImprinter +extends Container +implements ISlotWatcher { + public InventoryPlayer inventoryPlayer; + public TileEntityImprinter tileEntity; + + public ContainerImprinter(InventoryPlayer inventoryPlayer, TileEntityImprinter tileEntity) { + int var3; + this.tileEntity = tileEntity; + this.tileEntity.container = this; + this.inventoryPlayer = inventoryPlayer; + for (int x = 0; x < 3; ++x) { + for (int y = 0; y < 3; ++y) { + this.addSlotToContainer(new WatchedSlot((IInventory)this.tileEntity, y + x * 3, 9 + y * 18, 16 + x * 18, this)); + } + } + this.addSlotToContainer(new SlotCustom((IInventory)this.tileEntity, 9, 68, 34, new ItemStack(AssemblyLine.itemImprint))); + this.addSlotToContainer(new WatchedSlot((IInventory)this.tileEntity, 10, 92, 34, this)); + this.addSlotToContainer(new SlotCraftingResult(this, (IInventory)this.tileEntity, 11, 148, 34)); + for (int ii = 0; ii < 2; ++ii) { + for (int i = 0; i < 9; ++i) { + this.addSlotToContainer(new WatchedSlot((IInventory)this.tileEntity, i + ii * 9 + 12, 8 + i * 18, 80 + ii * 18, this)); + } + } + for (var3 = 0; var3 < 3; ++var3) { + for (int var4 = 0; var4 < 9; ++var4) { + this.addSlotToContainer(new WatchedSlot((IInventory)inventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 120 + var3 * 18, this)); + } + } + for (var3 = 0; var3 < 9; ++var3) { + this.addSlotToContainer(new WatchedSlot((IInventory)inventoryPlayer, var3, 8 + var3 * 18, 178, this)); + } + this.tileEntity.openInventory(); + } + + public void onContainerClosed(EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + this.tileEntity.closeInventory(); + } + + public boolean canInteractWith(EntityPlayer player) { + return this.tileEntity.isUseableByPlayer(player); + } + + public ItemStack transferStackInSlot(EntityPlayer player, int slot) { + ItemStack copyStack = null; + Slot slotObj = (Slot)this.inventorySlots.get(slot); + if (slotObj != null && slotObj.getHasStack()) { + ItemStack slotStack = slotObj.getStack(); + copyStack = slotStack.copy(); + if (slot == 12 - 1) { + this.tileEntity.setInventorySlotContents(12 - 1, null); + } + if (slot > this.tileEntity.getSizeInventory() - 1) { + if (this.getSlot(9).isItemValid(slotStack)) { + if (!this.mergeItemStack(slotStack, 9, 9 + 1, true)) { + return null; + } + } else if (!this.mergeItemStack(slotStack, 12, this.tileEntity.getSizeInventory(), false)) { + return null; + } + } else if (!this.mergeItemStack(slotStack, this.tileEntity.getSizeInventory(), this.tileEntity.getSizeInventory() + 36, false)) { + return null; + } + if (slotStack.stackSize == 0) { + slotObj.putStack(null); + } else { + slotObj.onSlotChanged(); + } + if (slotStack.stackSize == copyStack.stackSize) { + return null; + } + slotObj.onPickupFromSlot(player, slotStack); + } + this.slotContentsChanged(); + return copyStack; + } + + @Override + public void slotContentsChanged() { + this.tileEntity.markDirty(); + this.detectAndSendChanges(); + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/ISlotWatcher.java b/src/main/java/assemblyline/common/machine/imprinter/ISlotWatcher.java new file mode 100644 index 0000000..ff3fbb1 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/ISlotWatcher.java @@ -0,0 +1,6 @@ +package assemblyline.common.machine.imprinter; + +public interface ISlotWatcher { + public void slotContentsChanged(); +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/ItemImprinter.java b/src/main/java/assemblyline/common/machine/imprinter/ItemImprinter.java new file mode 100644 index 0000000..3d52f83 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/ItemImprinter.java @@ -0,0 +1,92 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.common.TabAssemblyLine; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.IProjectile; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ChatComponentText; + +public class ItemImprinter +extends Item { + public ItemImprinter() { + super(); + this.setUnlocalizedName("imprint"); + this.setCreativeTab(TabAssemblyLine.INSTANCE); + this.setHasSubtypes(true); + } + + @Override + @SideOnly(value=Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + this.itemIcon = par1IconRegister.registerIcon("assemblyline:imprint"); + } + + @Override + public int getItemStackLimit() { + return 1; + } + + @Override + public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) { + if (entity != null && !(entity instanceof IProjectile) && !(entity instanceof EntityPlayer)) { + String stringName = EntityList.getEntityString((Entity)entity); + player.addChatMessage(new ChatComponentText("Target: " + stringName)); + return true; + } + return false; + } + + @Override + public void addInformation(ItemStack itemStack, EntityPlayer par2EntityPlayer, List list, boolean par4) { + List filterItems = ItemImprinter.getFilters(itemStack); + if (filterItems.size() > 0) { + for (ItemStack filterItem : filterItems) { + list.add(filterItem.getDisplayName()); + } + } else { + list.add("No filters"); + } + } + + public static void setFilters(ItemStack itemStack, ArrayList filterStacks) { + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + NBTTagList nbt = new NBTTagList(); + for (int i = 0; i < filterStacks.size(); ++i) { + if (filterStacks.get(i) == null) continue; + NBTTagCompound newCompound = new NBTTagCompound(); + newCompound.setByte("Slot", (byte)i); + ((ItemStack)filterStacks.get(i)).writeToNBT(newCompound); + nbt.appendTag((NBTBase)newCompound); + } + itemStack.getTagCompound().setTag("Items", (NBTBase)nbt); + } + + public static ArrayList getFilters(ItemStack itemStack) { + ArrayList filterStacks = new ArrayList(); + if (itemStack.getTagCompound() == null) { + itemStack.setTagCompound(new NBTTagCompound()); + } + NBTTagCompound nbt = itemStack.getTagCompound(); + NBTTagList tagList = nbt.getTagList("Items", 10); + for (int i = 0; i < tagList.tagCount(); ++i) { + NBTTagCompound var4 = (NBTTagCompound)tagList.getCompoundTagAt(i); + byte var5 = var4.getByte("Slot"); + filterStacks.add(ItemStack.loadItemStackFromNBT((NBTTagCompound)var4)); + } + return filterStacks; + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/SlotCraftingResult.java b/src/main/java/assemblyline/common/machine/imprinter/SlotCraftingResult.java new file mode 100644 index 0000000..0cd7c20 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/SlotCraftingResult.java @@ -0,0 +1,31 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.common.machine.imprinter.ContainerImprinter; +import assemblyline.common.machine.imprinter.WatchedSlot; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class SlotCraftingResult +extends WatchedSlot { + private ContainerImprinter container; + + public SlotCraftingResult(ContainerImprinter container, IInventory inventory, int par2, int par3, int par4) { + super(inventory, par2, par3, par4, container); + this.container = container; + } + + public boolean isItemValid(ItemStack itemStack) { + return false; + } + + public boolean canTakeStack(EntityPlayer player) { + return true; + } + + public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack) { + this.container.tileEntity.onPickUpFromResult(entityPlayer, itemStack); + super.onPickupFromSlot(entityPlayer, itemStack); + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/SlotCustom.java b/src/main/java/assemblyline/common/machine/imprinter/SlotCustom.java new file mode 100644 index 0000000..fcebeaa --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/SlotCustom.java @@ -0,0 +1,20 @@ +package assemblyline.common.machine.imprinter; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotCustom +extends Slot { + private ItemStack itemStack; + + public SlotCustom(IInventory par1iInventory, int par2, int par3, int par4, ItemStack itemStack) { + super(par1iInventory, par2, par3, par4); + this.itemStack = itemStack; + } + + public boolean isItemValid(ItemStack itemStack) { + return itemStack.isItemEqual(this.itemStack); + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/SlotImprintResult.java b/src/main/java/assemblyline/common/machine/imprinter/SlotImprintResult.java new file mode 100644 index 0000000..856170b --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/SlotImprintResult.java @@ -0,0 +1,28 @@ +package assemblyline.common.machine.imprinter; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class SlotImprintResult +extends Slot { + public SlotImprintResult(IInventory par1iInventory, int par2, int par3, int par4) { + super(par1iInventory, par2, par3, par4); + } + + public boolean isItemValid(ItemStack par1ItemStack) { + return false; + } + + public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack) { + super.onPickupFromSlot(par1EntityPlayer, par2ItemStack); + if (this.inventory.getStackInSlot(0) != null) { + --this.inventory.getStackInSlot((int)0).stackSize; + if (this.inventory.getStackInSlot((int)0).stackSize <= 0) { + this.inventory.setInventorySlotContents(0, null); + } + } + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/TileEntityFilterable.java b/src/main/java/assemblyline/common/machine/imprinter/TileEntityFilterable.java new file mode 100644 index 0000000..ae66eac --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/TileEntityFilterable.java @@ -0,0 +1,116 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.api.IFilterable; +import assemblyline.common.machine.TileEntityAssemblyNetwork; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import java.util.ArrayList; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.prefab.implement.IRotatable; + +public abstract class TileEntityFilterable +extends TileEntityAssemblyNetwork +implements IRotatable, +IFilterable { + private ItemStack filterItem; + private boolean inverted; + + public boolean isFiltering(ItemStack itemStack) { + ArrayList checkStacks; + if (this.getFilter() != null && itemStack != null && (checkStacks = ItemImprinter.getFilters(this.getFilter())) != null) { + for (int i = 0; i < checkStacks.size(); ++i) { + if (checkStacks.get(i) == null || !((ItemStack)checkStacks.get(i)).isItemEqual(itemStack)) continue; + return !this.inverted; + } + } + return this.inverted; + } + + @Override + public void setFilter(ItemStack filter) { + this.filterItem = filter; + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + @Override + public ItemStack getFilter() { + return this.filterItem; + } + + public void setInverted(boolean inverted) { + this.inverted = inverted; + if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + public boolean isInverted() { + return this.inverted; + } + + public void toggleInversion() { + this.setInverted(!this.isInverted()); + } + + @Override + public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z) { + return ForgeDirection.getOrientation((int)this.getBlockMetadata()); + } + + @Override + public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection) { + this.worldObj.setBlockMetadataWithNotify(this.xCoord, this.yCoord, this.zCoord, facingDirection.ordinal(), 3); + } + + public void setDirection(ForgeDirection facingDirection) { + this.setDirection(this.worldObj, this.xCoord, this.yCoord, this.zCoord, facingDirection); + } + + public ForgeDirection getDirection() { + return this.getDirection((IBlockAccess)this.worldObj, this.xCoord, this.yCoord, this.zCoord); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound tag = new NBTTagCompound(); + this.writeToNBT(tag); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), tag); + } + + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + this.readFromNBT(pkt.func_148857_g()); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagCompound filter = new NBTTagCompound(); + if (this.getFilter() != null) { + this.getFilter().writeToNBT(filter); + } + nbt.setTag("filter", (NBTBase)filter); + nbt.setBoolean("inverted", this.inverted); + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + this.inverted = nbt.getBoolean("inverted"); + NBTTagCompound filter = nbt.getCompoundTag("filter"); + this.filterItem = ItemStack.loadItemStackFromNBT((NBTTagCompound)filter); + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/TileEntityImprinter.java b/src/main/java/assemblyline/common/machine/imprinter/TileEntityImprinter.java new file mode 100644 index 0000000..12bf683 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/TileEntityImprinter.java @@ -0,0 +1,488 @@ +package assemblyline.common.machine.imprinter; + +import assemblyline.api.IArmbot; +import assemblyline.api.IArmbotUseable; +import assemblyline.common.Pair; + +import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent; +import cpw.mods.fml.relauncher.ReflectionHelper; +import cpw.mods.fml.relauncher.Side; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.ShapedRecipes; +import net.minecraft.item.crafting.ShapelessRecipes; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; +import universalelectricity.prefab.TranslationHelper; +import universalelectricity.prefab.multiblock.TileEntityMulti; +import universalelectricity.prefab.tile.TileEntityAdvanced; + +public class TileEntityImprinter +extends TileEntityAdvanced +implements ISidedInventory, IArmbotUseable { + public static final int IMPRINTER_MATRIX_START = 9; + public static final int INVENTORY_START = 12; + public ItemStack[] craftingMatrix = new ItemStack[9]; + public ItemStack[] imprinterMatrix = new ItemStack[3]; + public ItemStack[] containingItems = new ItemStack[18]; + public ContainerImprinter container; + private boolean isImprinting = false; + public boolean searchInventories = true; + + @Override + public boolean canUpdate() { + return false; + } + + @Override + public int getSizeInventory() { + return this.craftingMatrix.length + this.imprinterMatrix.length + this.containingItems.length; + } + + @Override + public void setInventorySlotContents(int slot, ItemStack itemStack) { + if (slot < this.getSizeInventory()) { + if (slot < 9) { + this.craftingMatrix[slot] = itemStack; + } else if (slot < 12) { + this.imprinterMatrix[slot - 9] = itemStack; + } else { + this.containingItems[slot - 12] = itemStack; + } + } + } + + @Override + public ItemStack decrStackSize(int i, int amount) { + if (this.getStackInSlot(i) != null) { + if (this.getStackInSlot((int)i).stackSize <= amount) { + ItemStack var3 = this.getStackInSlot(i); + this.setInventorySlotContents(i, null); + return var3; + } + ItemStack var3 = this.getStackInSlot(i).splitStack(amount); + if (this.getStackInSlot((int)i).stackSize == 0) { + this.setInventorySlotContents(i, null); + } + return var3; + } + return null; + } + + @Override + public ItemStack getStackInSlot(int slot) { + if (slot < 9) { + return this.craftingMatrix[slot]; + } + if (slot < 12) { + return this.imprinterMatrix[slot - 9]; + } + return this.containingItems[slot - 12]; + } + + @Override + public ItemStack getStackInSlotOnClosing(int slot) { + if (this.getStackInSlot(slot) != null) { + ItemStack var2 = this.getStackInSlot(slot); + this.setInventorySlotContents(slot, null); + return var2; + } + return null; + } + + @Override + public String getInventoryName() { + return TranslationHelper.getLocal("tile.imprinter.name"); + } + + @Override + public void openInventory() { + this.markDirty(); + } + + @Override + public void closeInventory() { + this.markDirty(); + } + + public InventoryCrafting getCraftingMatrix() { + if (this.container != null) { + InventoryCrafting inventoryCrafting = new InventoryCrafting((Container)this.container, 3, 3); + for (int i = 0; i < this.craftingMatrix.length; ++i) { + inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix[i]); + } + return inventoryCrafting; + } + return null; + } + + public void replaceCraftingMatrix(InventoryCrafting inventoryCrafting) { + for (int i = 0; i < this.craftingMatrix.length; ++i) { + this.craftingMatrix[i] = inventoryCrafting.getStackInSlot(i); + } + } + + public boolean isMatrixEmpty() { + for (int i = 0; i < 9; ++i) { + if (this.craftingMatrix[i] == null) continue; + return false; + } + return true; + } + + @Override + public void markDirty() { + if (!this.worldObj.isRemote) { + this.isImprinting = false; + if (this.isMatrixEmpty() && this.imprinterMatrix[0] != null && this.imprinterMatrix[1] != null && this.imprinterMatrix[0].getItem() instanceof ItemImprinter) { + ItemStack outputStack = this.imprinterMatrix[0].copy(); + outputStack.stackSize = 1; + ArrayList filters = ItemImprinter.getFilters(outputStack); + boolean filteringItemExists = false; + for (ItemStack filteredStack : filters) { + if (!filteredStack.isItemEqual(this.imprinterMatrix[1])) continue; + filters.remove(filteredStack); + filteringItemExists = true; + break; + } + if (!filteringItemExists) { + filters.add(this.imprinterMatrix[1]); + } + ItemImprinter.setFilters(outputStack, filters); + this.imprinterMatrix[2] = outputStack; + this.isImprinting = true; + } + if (!this.isImprinting) { + ItemStack matrixOutput; + System.out.println("Crafting"); + this.imprinterMatrix[2] = null; + boolean didCraft = false; + InventoryCrafting inventoryCrafting = this.getCraftingMatrix(); + if (inventoryCrafting != null && (matrixOutput = CraftingManager.getInstance().findMatchingRecipe(inventoryCrafting, this.worldObj)) != null) { + System.out.println("Using crafting grid"); + this.imprinterMatrix[2] = matrixOutput; + didCraft = true; + } + if (this.imprinterMatrix[0] != null && !didCraft && this.imprinterMatrix[0].getItem() instanceof ItemImprinter) { + System.out.println("Using imprint as grid"); + ArrayList filters = ItemImprinter.getFilters(this.imprinterMatrix[0]); + for (ItemStack outputStack : filters) { + Pair idealRecipe; + if (outputStack == null || (idealRecipe = this.getIdealRecipe(outputStack)) == null) continue; + ItemStack recipeOutput = (ItemStack)idealRecipe.getKey(); + System.out.println("Ideal R: " + recipeOutput.toString()); + if (!(recipeOutput != null & recipeOutput.stackSize > 0)) continue; + this.imprinterMatrix[2] = recipeOutput; + didCraft = true; + break; + } + } + if (!didCraft) { + this.imprinterMatrix[2] = null; + } + } + } + } + + public void onPickUpFromResult(EntityPlayer entityPlayer, ItemStack itemStack) { + block9: { + block11: { + block10: { + if (itemStack == null) break block9; + if (!this.isImprinting) break block10; + this.imprinterMatrix[0] = null; + break block9; + } + if (this.getIdealRecipe(itemStack) == null) break block11; + ItemStack[] requiredItems = (ItemStack[])((ItemStack[])this.getIdealRecipe(itemStack).getValue()).clone(); + if (requiredItems == null) break block9; + block2: for (ItemStack searchStack : requiredItems) { + if (searchStack == null) continue; + block3: for (IInventory inventory : this.getAvaliableInventories()) { + for (int i = 0; i < inventory.getSizeInventory(); ++i) { + ItemStack checkStack = inventory.getStackInSlot(i); + if (checkStack == null || !searchStack.isItemEqual(checkStack) && (searchStack.getItem() != checkStack.getItem() || searchStack.getItemDamage() >= 0)) continue; + inventory.decrStackSize(i, 1); + break block3; + } + } + for (int i = 0; i < this.containingItems.length; ++i) { + ItemStack checkStack = this.containingItems[i]; + if (checkStack == null || !searchStack.isItemEqual(checkStack) && (searchStack.getItem() != checkStack.getItem() || searchStack.getItemDamage() >= 0)) continue; + this.decrStackSize(i + 12, 1); + continue block2; + } + } + break block9; + } + try { + InventoryCrafting inventoryCrafting = this.getCraftingMatrix(); + MinecraftForge.EVENT_BUS.post(new ItemCraftedEvent(entityPlayer, itemStack, inventoryCrafting)); + for (int var3 = 0; var3 < inventoryCrafting.getSizeInventory(); ++var3) { + ItemStack var4 = inventoryCrafting.getStackInSlot(var3); + if (var4 == null) continue; + inventoryCrafting.decrStackSize(var3, 1); + if (!var4.getItem().hasContainerItem()) continue; + ItemStack var5 = var4.getItem().getContainerItem(var4); + if (var5.isItemStackDamageable() && var5.getItemDamage() > var5.getMaxDamage()) { + MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(entityPlayer, var5)); + var5 = null; + } + if (var5 == null || var4.getItem().doesContainerItemLeaveCraftingGrid(var4) && entityPlayer.inventory.addItemStackToInventory(var5)) continue; + if (inventoryCrafting.getStackInSlot(var3) == null) { + inventoryCrafting.setInventorySlotContents(var3, var5); + continue; + } + //entityPlayer.func_71021_b(var5); + //TODO: WTF + entityPlayer.dropPlayerItemWithRandomChoice(var5, false); + } + this.replaceCraftingMatrix(inventoryCrafting); + } + catch (Exception e) { + System.out.println("Imprinter: Failed to craft item: " + itemStack.getDisplayName()); + e.printStackTrace(); + } + } + } + + public Pair getIdealRecipe(ItemStack outputItem) { + for (Object object : CraftingManager.getInstance().getRecipeList()) { + ArrayList hasResources; + Object oreRecipeInput; + if (!(object instanceof IRecipe) || ((IRecipe)object).getRecipeOutput() == null || !outputItem.isItemEqual(((IRecipe)object).getRecipeOutput())) continue; + if (object instanceof ShapedRecipes) { + if (this.hasResource((Object[])((ShapedRecipes)object).recipeItems) == null) continue; + return new Pair(((IRecipe)object).getRecipeOutput().copy(), ((ShapedRecipes)object).recipeItems); + } + if (object instanceof ShapelessRecipes) { + if (this.hasResource((Object[])((ShapelessRecipes)object).recipeItems.toArray(new ItemStack[1])) == null) continue; + return new Pair(((IRecipe)object).getRecipeOutput().copy(), ((ShapelessRecipes)object).recipeItems.toArray(new ItemStack[1])); + } + if (object instanceof ShapedOreRecipe) { + ShapedOreRecipe oreRecipe = (ShapedOreRecipe)object; + oreRecipeInput = (Object[])ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, new String[]{"input"}); + hasResources = this.hasResource((Object[])oreRecipeInput); + if (hasResources == null) continue; + return new Pair(((IRecipe)object).getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1])); + } + if (!(object instanceof ShapelessOreRecipe)) continue; + ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe)object; + oreRecipeInput = (ArrayList)ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, new String[]{"input"}); + hasResources = this.hasResource(((ArrayList)oreRecipeInput).toArray()); + if (hasResources == null) continue; + return new Pair(((IRecipe)object).getRecipeOutput().copy(), hasResources.toArray(new ItemStack[1])); + } + return null; + } + + public ArrayList hasResource(Object[] recipeItems) { + try { + TileEntityImprinter dummyImprinter = new TileEntityImprinter(); + NBTTagCompound cloneData = new NBTTagCompound(); + this.writeToNBT(cloneData); + dummyImprinter.readFromNBT(cloneData); + ArrayList actualResources = new ArrayList(); + int itemMatch = 0; + block2: for (Object obj : recipeItems) { + if (obj instanceof ItemStack) { + ItemStack recipeItem = (ItemStack)obj; + actualResources.add(recipeItem.copy()); + if (recipeItem == null || !this.doesItemExist(recipeItem, dummyImprinter)) continue; + ++itemMatch; + continue; + } + if (!(obj instanceof ArrayList)) continue; + ArrayList ingredientsList = (ArrayList)obj; + Object[] ingredientsArray = ingredientsList.toArray(); + for (int x = 0; x < ingredientsArray.length; ++x) { + if (ingredientsArray[x] == null || !(ingredientsArray[x] instanceof ItemStack)) continue; + ItemStack recipeItem = (ItemStack)ingredientsArray[x]; + actualResources.add(recipeItem.copy()); + if (recipeItem == null || !this.doesItemExist(recipeItem, dummyImprinter)) continue; + ++itemMatch; + continue block2; + } + } + return itemMatch >= actualResources.size() ? actualResources : null; + } + catch (Exception e) { + System.out.println("Failed to find recipes in the imprinter."); + e.printStackTrace(); + return null; + } + } + + private boolean doesItemExist(ItemStack recipeItem, TileEntityImprinter dummyImprinter) { + for (int i = 0; i < dummyImprinter.containingItems.length; ++i) { + ItemStack checkStack = dummyImprinter.containingItems[i]; + if (checkStack == null || !recipeItem.isItemEqual(checkStack) && (recipeItem.getItem() != checkStack.getItem() || recipeItem.getItemDamage() >= 0)) continue; + dummyImprinter.decrStackSize(i + 12, 1); + return true; + } + return false; + } + + private List getAvaliableInventories() { + ArrayList inventories = new ArrayList<>(); + if (this.searchInventories) { + block0: for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), direction); + if (tileEntity == null) continue; + if (tileEntity instanceof TileEntityMulti) { + Vector3 mainBlockPosition = ((TileEntityMulti)tileEntity).mainBlockPosition; + if (mainBlockPosition == null || !(mainBlockPosition.getTileEntity(this.worldObj) instanceof IInventory)) continue; + inventories.add(((IInventory)mainBlockPosition.getTileEntity(this.worldObj))); + continue; + } + if (tileEntity instanceof TileEntityChest) { + inventories.add(((TileEntityChest)tileEntity)); + for (int i = 2; i < 6; ++i) { + TileEntity chest = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(tileEntity), ForgeDirection.getOrientation(2)); + if (chest == null || chest.getClass() != tileEntity.getClass()) continue; + inventories.add(((TileEntityChest)chest)); + continue block0; + } + continue; + } + if (!(tileEntity instanceof IInventory) || tileEntity instanceof TileEntityImprinter) continue; + inventories.add(((IInventory)tileEntity)); + } + } + return inventories; + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setBoolean("searchInventories", this.searchInventories); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, getBlockMetadata(), nbt); + } + + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { + if (this.worldObj.isRemote) { + NBTTagCompound nbt = pkt.func_148857_g(); + this.searchInventories = nbt.getBoolean("searchInventories"); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagList var2 = nbt.getTagList("Items", 10); + this.craftingMatrix = new ItemStack[9]; + this.imprinterMatrix = new ItemStack[3]; + this.containingItems = new ItemStack[18]; + for (int i = 0; i < var2.tagCount(); ++i) { + NBTTagCompound var4 = (NBTTagCompound)var2.getCompoundTagAt(i); + byte var5 = var4.getByte("Slot"); + if (var5 < 0 || var5 >= this.getSizeInventory()) continue; + this.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT((NBTTagCompound)var4)); + } + this.searchInventories = nbt.getBoolean("searchInventories"); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagList var2 = new NBTTagList(); + for (int i = 0; i < this.getSizeInventory(); ++i) { + if (this.getStackInSlot(i) == null) continue; + NBTTagCompound var4 = new NBTTagCompound(); + var4.setByte("Slot", (byte)i); + this.getStackInSlot(i).writeToNBT(var4); + var2.appendTag((NBTBase)var4); + } + nbt.setTag("Items", (NBTBase)var2); + nbt.setBoolean("searchInventories", this.searchInventories); + } + + @Override + public boolean onUse(IArmbot armbot, String[] args) { + this.markDirty(); + if (this.imprinterMatrix[2] != null) { + armbot.grabItem(this.imprinterMatrix[2].copy()); + this.onPickUpFromResult(null, this.imprinterMatrix[2]); + this.imprinterMatrix[2] = null; + } + return false; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemstack) { + return true; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer entityplayer) { + return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0; + } + + @Override + public int[] getAccessibleSlotsFromSide(int var1) { + int startIndex = getStartInventorySide(ForgeDirection.getOrientation(var1)); + int size = getSizeInventorySide(ForgeDirection.getOrientation(var1)); + int[] slots = new int[size]; + for (int i = 0; i < size; i++) { + slots[i] = startIndex + i; + } + return slots; + } + + @Override + public boolean canInsertItem(int i, ItemStack itemstack, int j) { + return this.isItemValidForSlot(i, itemstack); + } + + @Override + public boolean canExtractItem(int i, ItemStack itemstack, int j) { + return false; + } + + public int getStartInventorySide(ForgeDirection side) { + if (side == ForgeDirection.DOWN || side == ForgeDirection.UP) { + return this.craftingMatrix.length + this.imprinterMatrix.length; + } + return this.craftingMatrix.length + 1; + } + + public int getSizeInventorySide(ForgeDirection side) { + if (side == ForgeDirection.DOWN || side == ForgeDirection.UP) { + return this.containingItems.length - 1; + } + return 1; + } +} + diff --git a/src/main/java/assemblyline/common/machine/imprinter/WatchedSlot.java b/src/main/java/assemblyline/common/machine/imprinter/WatchedSlot.java new file mode 100644 index 0000000..d5582f8 --- /dev/null +++ b/src/main/java/assemblyline/common/machine/imprinter/WatchedSlot.java @@ -0,0 +1,21 @@ +package assemblyline.common.machine.imprinter; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class WatchedSlot +extends Slot { + private ISlotWatcher slotWatcher; + + public WatchedSlot(IInventory inventory, int id, int xPosition, int yPosition, ISlotWatcher slotWatcher) { + super(inventory, id, xPosition, yPosition); + this.slotWatcher = slotWatcher; + } + + public void onSlotChanged() { + if (this.slotWatcher != null) { + this.slotWatcher.slotContentsChanged(); + } + } +} + diff --git a/src/main/java/assemblyline/common/network/MessageEncoder.java b/src/main/java/assemblyline/common/network/MessageEncoder.java new file mode 100644 index 0000000..8d68bcd --- /dev/null +++ b/src/main/java/assemblyline/common/network/MessageEncoder.java @@ -0,0 +1,52 @@ +package assemblyline.common.network; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import universalelectricity.core.vector.Vector3; + +public class MessageEncoder implements IMessage { + + public NBTTagCompound nbt; + public Vector3 tileLocation; + + public MessageEncoder() {} + + public MessageEncoder(Vector3 pos, NBTTagCompound nbt) { + this.nbt = nbt; + this.tileLocation = pos; + } + + @Override + public void fromBytes(ByteBuf bytes) { + DataInputStream stream = new DataInputStream(new ByteBufInputStream(bytes)); + try { + NBTTagCompound recTag = CompressedStreamTools.read(stream); + tileLocation = Vector3.readFromNBT(recTag.getCompoundTag("tilePos")); + nbt = recTag.getCompoundTag("data"); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void toBytes(ByteBuf bytes) { + NBTTagCompound sendTag = new NBTTagCompound(); + sendTag.setTag("tilePos", tileLocation.writeToNBT(new NBTTagCompound())); + sendTag.setTag("data", nbt); + DataOutputStream stream = new DataOutputStream(new ByteBufOutputStream(bytes)); + try { + CompressedStreamTools.write(sendTag, stream); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/assemblyline/common/network/MessageEncoderHandler.java b/src/main/java/assemblyline/common/network/MessageEncoderHandler.java new file mode 100644 index 0000000..924ffbf --- /dev/null +++ b/src/main/java/assemblyline/common/network/MessageEncoderHandler.java @@ -0,0 +1,23 @@ +package assemblyline.common.network; + +import assemblyline.common.machine.encoder.TileEntityEncoder; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.tileentity.TileEntity; + +public class MessageEncoderHandler implements IMessageHandler { + + @Override + public IMessage onMessage(MessageEncoder msg, MessageContext ctx) { + if (ctx.side == Side.SERVER) { + TileEntity tile = msg.tileLocation.getTileEntity(ctx.getServerHandler().playerEntity.worldObj); + if (tile instanceof TileEntityEncoder) { + ((TileEntityEncoder)tile).handleMessage(msg.nbt); + } + } + return null; + } + +} diff --git a/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java new file mode 100755 index 0000000..4f84caa --- /dev/null +++ b/src/main/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -0,0 +1,315 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api; + +import dan200.computercraft.api.filesystem.IMount; +import dan200.computercraft.api.filesystem.IWritableMount; +import dan200.computercraft.api.media.IMediaProvider; +import dan200.computercraft.api.peripheral.IPeripheralProvider; +import dan200.computercraft.api.permissions.ITurtlePermissionProvider; +import dan200.computercraft.api.redstone.IBundledRedstoneProvider; +import dan200.computercraft.api.turtle.ITurtleUpgrade; +import net.minecraft.world.World; + +import java.lang.reflect.Method; + +/** + * The static entry point to the ComputerCraft API. + * Members in this class must be called after mod_ComputerCraft has been initialised, + * but may be called before it is fully loaded. + */ +public final class ComputerCraftAPI +{ + public static boolean isInstalled() + { + findCC(); + return computerCraft != null; + } + + public static String getInstalledVersion() + { + findCC(); + if( computerCraft_getVersion != null ) + { + try { + return (String)computerCraft_getVersion.invoke( null ); + } catch (Exception e) { + // It failed + } + } + return ""; + } + + public static String getAPIVersion() + { + return "1.75"; + } + + /** + * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
+ * Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
+ * @param world The world for which the save dir should be created. This should be the serverside world object. + * @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk" + * @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
+ * eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing. + * @see #createSaveDirMount(World, String, long) + */ + public static int createUniqueNumberedSaveDir( World world, String parentSubPath ) + { + findCC(); + if( computerCraft_createUniqueNumberedSaveDir != null ) + { + try { + return (Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath ); + } catch (Exception e) { + // It failed + } + } + return -1; + } + + /** + * Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the + * users save directory onto a computers file system.
+ * @param world The world for which the save dir can be found. This should be the serverside world object. + * @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
+ * Use createUniqueNumberedSaveDir() to create a new numbered folder to use. + * @param capacity The ammount of data that can be stored in the directory before it fills up, in bytes. + * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() + * to mount this on a Computers' file system. + * @see #createUniqueNumberedSaveDir(World, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) + * @see dan200.computercraft.api.filesystem.IMount + * @see IWritableMount + */ + public static IWritableMount createSaveDirMount( World world, String subPath, long capacity ) + { + findCC(); + if( computerCraft_createSaveDirMount != null ) + { + try { + return (IWritableMount)computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity ); + } catch (Exception e){ + // It failed + } + } + return null; + } + + /** + * Creates a file system mount to a resource folder, and returns it.
+ * Use in conjuction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder onto a computers file system.
+ * The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain resources with the same domain and path.
+ * @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class + * @param domain The domain under which to look for resources. eg: "mymod" + * @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles" + * @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() + * to mount this on a Computers' file system. + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, IWritableMount) + * @see dan200.computercraft.api.filesystem.IMount + */ + public static IMount createResourceMount( Class modClass, String domain, String subPath ) + { + findCC(); + if( computerCraft_createResourceMount != null ) + { + try { + return (IMount)computerCraft_createResourceMount.invoke( null, modClass, domain, subPath ); + } catch (Exception e){ + // It failed + } + } + return null; + } + + /** + * Registers a peripheral handler to convert blocks into IPeripheral implementations. + * @see dan200.computercraft.api.peripheral.IPeripheral + * @see dan200.computercraft.api.peripheral.IPeripheralProvider + */ + public static void registerPeripheralProvider( IPeripheralProvider handler ) + { + findCC(); + if ( computerCraft_registerPeripheralProvider != null) + { + try { + computerCraft_registerPeripheralProvider.invoke( null, handler ); + } catch (Exception e){ + // It failed + } + } + } + + /** + * Registers a new turtle turtle for use in ComputerCraft. After calling this, + * users should be able to craft Turtles with your new turtle. It is recommended to call + * this during the load() method of your mod. + * @see dan200.computercraft.api.turtle.ITurtleUpgrade + */ + public static void registerTurtleUpgrade( ITurtleUpgrade upgrade ) + { + if( upgrade != null ) + { + findCC(); + if( computerCraft_registerTurtleUpgrade != null ) + { + try { + computerCraft_registerTurtleUpgrade.invoke( null, upgrade ); + } catch( Exception e ) { + // It failed + } + } + } + } + + /** + * Registers a bundled redstone handler to provide bundled redstone output for blocks + * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider + */ + public static void registerBundledRedstoneProvider( IBundledRedstoneProvider handler ) + { + findCC(); + if( computerCraft_registerBundledRedstoneProvider != null ) + { + try { + computerCraft_registerBundledRedstoneProvider.invoke( null, handler ); + } catch (Exception e) { + // It failed + } + } + } + + /** + * If there is a Computer or Turtle at a certain position in the world, get it's bundled redstone output. + * @see dan200.computercraft.api.redstone.IBundledRedstoneProvider + * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. + * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. + */ + public static int getBundledRedstoneOutput( World world, int x, int y, int z, int side ) + { + findCC(); + if( computerCraft_getDefaultBundledRedstoneOutput != null ) + { + try { + return (Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, x, y, z, side ); + } catch (Exception e){ + // It failed + } + } + return -1; + } + + /** + * Registers a media handler to provide IMedia implementations for Items + * @see dan200.computercraft.api.media.IMediaProvider + */ + public static void registerMediaProvider( IMediaProvider handler ) + { + findCC(); + if( computerCraft_registerMediaProvider != null ) + { + try { + computerCraft_registerMediaProvider.invoke( null, handler ); + } catch (Exception e){ + // It failed + } + } + } + + /** + * Registers a permission handler to restrict where turtles can move or build + * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider + */ + public static void registerPermissionProvider( ITurtlePermissionProvider handler ) + { + findCC(); + if( computerCraft_registerPermissionProvider != null ) + { + try { + computerCraft_registerPermissionProvider.invoke( null, handler ); + } catch (Exception e) { + // It failed + } + } + } + + // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. + // Reflection is used here so you can develop your mod without decompiling ComputerCraft and including + // it in your solution, and so your mod won't crash if ComputerCraft is installed. + + private static void findCC() + { + if( !ccSearched ) { + try { + computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" ); + computerCraft_getVersion = findCCMethod( "getVersion", new Class[]{ + } ); + computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{ + World.class, String.class + } ); + computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class[] { + World.class, String.class, Long.TYPE + } ); + computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class[] { + Class.class, String.class, String.class + } ); + computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class[] { + IPeripheralProvider.class + } ); + computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class[] { + ITurtleUpgrade.class + } ); + computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class[] { + IBundledRedstoneProvider.class + } ); + computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] { + World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE + } ); + computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] { + IMediaProvider.class + } ); + computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class[] { + ITurtlePermissionProvider.class + } ); + } catch( Exception e ) { + System.out.println( "ComputerCraftAPI: ComputerCraft not found." ); + } finally { + ccSearched = true; + } + } + } + + private static Method findCCMethod( String name, Class[] args ) + { + try { + if( computerCraft != null ) + { + return computerCraft.getMethod( name, args ); + } + return null; + } catch( NoSuchMethodException e ) { + System.out.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." ); + return null; + } + } + + private static boolean ccSearched = false; + private static Class computerCraft = null; + private static Method computerCraft_getVersion = null; + private static Method computerCraft_createUniqueNumberedSaveDir = null; + private static Method computerCraft_createSaveDirMount = null; + private static Method computerCraft_createResourceMount = null; + private static Method computerCraft_registerPeripheralProvider = null; + private static Method computerCraft_registerTurtleUpgrade = null; + private static Method computerCraft_registerBundledRedstoneProvider = null; + private static Method computerCraft_getDefaultBundledRedstoneOutput = null; + private static Method computerCraft_registerMediaProvider = null; + private static Method computerCraft_registerPermissionProvider = null; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/IMount.java b/src/main/java/dan200/computercraft/api/filesystem/IMount.java new file mode 100755 index 0000000..cf884d9 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/IMount.java @@ -0,0 +1,57 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.filesystem; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * Represents a read only part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount(). + * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount() or ComputerCraftAPI.createResourceMount(), or you're free to implement it yourselves! + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mount(String, IMount) + * @see IWritableMount + */ +public interface IMount +{ + /** + * Returns whether a file with a given path exists or not. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * @return true if the file exists, false otherwise + */ + public boolean exists( String path ) throws IOException; + + /** + * Returns whether a file with a given path is a directory or not. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" + * @return true if the file exists and is a directory, false otherwise + */ + public boolean isDirectory( String path ) throws IOException; + + /** + * Returns the file names of all the files in a directory. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms" + * @param contents A list of strings. Add all the file names to this list + */ + public void list( String path, List contents ) throws IOException; + + /** + * Returns the size of a file with a given path, in bytes + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * @return the size of the file, in bytes + */ + public long getSize( String path ) throws IOException; + + /** + * Opens a file with a given path, and returns an inputstream representing it's contents. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * @return a stream representing the contents of the file + */ + public InputStream openForRead( String path ) throws IOException; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java new file mode 100755 index 0000000..ffe3290 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -0,0 +1,52 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.filesystem; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * Represents a part of a virtual filesystem that can be mounted onto a computercraft using IComputerAccess.mount() or IComputerAccess.mountWritable(), that can also be written to. + * Ready made implementations of this interface can be created using ComputerCraftAPI.createSaveDirMount(), or you're free to implement it yourselves! + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.peripheral.IComputerAccess#mountWritable(String, dan200.computercraft.api.filesystem.IMount) + * @see dan200.computercraft.api.filesystem.IMount + */ +public interface IWritableMount extends IMount +{ + /** + * Creates a directory at a given path inside the virtual file system. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/mynewprograms" + */ + public void makeDirectory( String path ) throws IOException; + + /** + * Deletes a directory at a given path inside the virtual file system. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myoldprograms" + */ + public void delete( String path ) throws IOException; + + /** + * Opens a file with a given path, and returns an outputstream for writing to it. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * @return a stream for writing to + */ + public OutputStream openForWrite( String path ) throws IOException; + + /** + * Opens a file with a given path, and returns an outputstream for appending to it. + * @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram" + * @return a stream for writing to + */ + public OutputStream openForAppend( String path ) throws IOException; + + /** + * Get the ammount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail once it reaches zero. + * @return The ammount of free space, in bytes. + */ + public long getRemainingSpace() throws IOException; +} diff --git a/src/main/java/dan200/computercraft/api/filesystem/package-info.java b/src/main/java/dan200/computercraft/api/filesystem/package-info.java new file mode 100755 index 0000000..d7a2d59 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/filesystem/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="1.75" ) +package dan200.computercraft.api.filesystem; + +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaContext.java b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java new file mode 100755 index 0000000..1ffbeea --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaContext.java @@ -0,0 +1,58 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.lua; + +/** + * An interface passed to peripherals and ILuaObjects' by computers or turtles, providing methods + * that allow the peripheral call to wait for events before returning, just like in lua. + * This is very useful if you need to signal work to be performed on the main thread, and don't want to return + * until the work has been completed. + */ +public interface ILuaContext +{ + /** + * Wait for an event to occur on the computercraft, suspending the thread until it arises. This method is exactly equivalent to os.pullEvent() in lua. + * @param filter A specific event to wait for, or null to wait for any event + * @return An object array containing the name of the event that occurred, and any event parameters + * @throws Exception If the user presses CTRL+T to terminate the current program while pullEvent() is waiting for an event, a "Terminated" exception will be thrown here. + * Do not attempt to common this exception, unless you wish to prevent termination, which is not recommended. + * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEvent() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + */ + public Object[] pullEvent( String filter ) throws LuaException, InterruptedException; + + /** + * The same as pullEvent(), except "terminated" events are ignored. Only use this if you want to prevent program termination, which is not recommended. This method is exactly equivalent to os.pullEventRaw() in lua. + * @param filter A specific event to wait for, or null to wait for any event + * @return An object array containing the name of the event that occurred, and any event parameters + * @throws InterruptedException If the user shuts down or reboots the computercraft while pullEventRaw() is waiting for an event, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + * @see #pullEvent(String) + */ + public Object[] pullEventRaw( String filter ) throws InterruptedException; + + /** + * Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to coroutine.yield() in lua. Use pullEvent() if you wish to wait for events. + * @param arguments An object array containing the arguments to pass to coroutine.yield() + * @return An object array containing the return values from coroutine.yield() + * @throws InterruptedException If the user shuts down or reboots the computercraft the coroutine is suspended, InterruptedException will be thrown. This exception must not be caught or intercepted, or the computercraft will leak memory and end up in a broken state. + * @see #pullEvent(String) + */ + public Object[] yield( Object[] arguments ) throws InterruptedException; + + /** + * TODO: Document me + * @param task + * @return + */ + public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException; + + /** + * TODO: Document me + * @param task + * @return + */ + public long issueMainThreadTask( ILuaTask task ) throws LuaException; +} diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaObject.java b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java new file mode 100755 index 0000000..abd8b40 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaObject.java @@ -0,0 +1,26 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.lua; + +/** + * An interface for representing custom objects returned by IPeripheral.callMethod() calls. + * Return objects implementing this interface to expose objects with methods to lua. + */ +public interface ILuaObject +{ + /** + * Get the names of the methods that this object implements. This works the same as IPeripheral.getMethodNames(). See that method for detailed documentation. + * @see dan200.computercraft.api.peripheral.IPeripheral#getMethodNames() + */ + public String[] getMethodNames(); + + /** + * Called when a user calls one of the methods that this object implements. This works the same as IPeripheral.callMethod(). See that method for detailed documentation. + * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod(dan200.computercraft.api.peripheral.IComputerAccess, ILuaContext, int, Object[]) + */ + public Object[] callMethod( ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; +} diff --git a/src/main/java/dan200/computercraft/api/lua/ILuaTask.java b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java new file mode 100755 index 0000000..45feead --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/ILuaTask.java @@ -0,0 +1,12 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.lua; + +public interface ILuaTask +{ + public Object[] execute() throws LuaException; +} diff --git a/src/main/java/dan200/computercraft/api/lua/LuaException.java b/src/main/java/dan200/computercraft/api/lua/LuaException.java new file mode 100755 index 0000000..6683c4b --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/LuaException.java @@ -0,0 +1,36 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.lua; + +/** + * An exception representing an error in Lua, like that raised by the error() function + */ +public class LuaException extends Exception +{ + private final int m_level; + + public LuaException() + { + this( "error", 1 ); + } + + public LuaException( String message ) + { + this( message, 1 ); + } + + public LuaException( String message, int level ) + { + super( message ); + m_level = level; + } + + public int getLevel() + { + return m_level; + } +} diff --git a/src/main/java/dan200/computercraft/api/lua/package-info.java b/src/main/java/dan200/computercraft/api/lua/package-info.java new file mode 100755 index 0000000..3ea3d91 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/lua/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="1.75" ) +package dan200.computercraft.api.lua; + +import cpw.mods.fml.common.API; diff --git a/src/main/java/dan200/computercraft/api/media/IMedia.java b/src/main/java/dan200/computercraft/api/media/IMedia.java new file mode 100755 index 0000000..57ebc08 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/IMedia.java @@ -0,0 +1,59 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.media; + +import dan200.computercraft.api.filesystem.IMount; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +/** + * Represents an item that can be placed in a disk drive and used by a Computer. + * Implement this interface on your Item class to allow it to be used in the drive. + */ +public interface IMedia +{ + /** + * Get a string representing the label of this item. Will be called vi disk.getLabel() in lua. + * @param stack The itemstack to inspect + * @return The label. ie: "Dan's Programs" + */ + public String getLabel( ItemStack stack ); + + /** + * Set a string representing the label of this item. Will be called vi disk.setLabel() in lua. + * @param stack The itemstack to modify. + * @param label The string to set the label to. + * @return true if the label was updated, false if the label may not be modified. + */ + public boolean setLabel( ItemStack stack, String label ); + + /** + * If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathon Coulton - Still Alive" + * @param stack The itemstack to inspect. + * @return The name, or null if this item does not represent an item with audio. + */ + public String getAudioTitle( ItemStack stack ); + + /** + * If this disk represents an item with audio (like a record), get the resource name of the audio track to play. + * @param stack The itemstack to inspect. + * @return The name, or null if this item does not represent an item with audio. + */ + public String getAudioRecordName( ItemStack stack ); + + /** + * If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of the computercraft while the media is in the disk drive. + * @param stack The itemstack to inspect. + * @param world The world in which the item and disk drive reside. + * @return The mount, or null if this item does not represent an item with data. If the IMount returned also implements IWritableMount, it will mounted using mountWritable() + * @see dan200.computercraft.api.filesystem.IMount + * @see dan200.computercraft.api.filesystem.IWritableMount + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + */ + public IMount createDataMount( ItemStack stack, World world ); +} diff --git a/src/main/java/dan200/computercraft/api/media/IMediaProvider.java b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java new file mode 100755 index 0000000..c0aabd5 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/IMediaProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.media; + +import net.minecraft.item.ItemStack; + +/** + * This interface is used to provide IMedia implementations for ItemStack + * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) + */ +public interface IMediaProvider +{ + /** + * Produce an IMedia implementation from an ItemStack. + * @see dan200.computercraft.api.ComputerCraftAPI#registerMediaProvider(IMediaProvider) + * @return an IMedia implementation, or null if the item is not something you wish to handle + */ + public IMedia getMedia( ItemStack stack ); +} diff --git a/src/main/java/dan200/computercraft/api/media/package-info.java b/src/main/java/dan200/computercraft/api/media/package-info.java new file mode 100755 index 0000000..9e2f507 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/media/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="1.75" ) +package dan200.computercraft.api.media; + +import cpw.mods.fml.common.API; diff --git a/src/main/java/dan200/computercraft/api/package-info.java b/src/main/java/dan200/computercraft/api/package-info.java new file mode 100755 index 0000000..f3a706a --- /dev/null +++ b/src/main/java/dan200/computercraft/api/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="1.75" ) +package dan200.computercraft.api; + +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java new file mode 100755 index 0000000..2458c06 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -0,0 +1,102 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.peripheral; + +import dan200.computercraft.api.filesystem.IMount; +import dan200.computercraft.api.filesystem.IWritableMount; + +/** + * The interface passed to peripherals by computers or turtles, providing methods + * that they can call. This should not be implemented by your classes. Do not interact + * with computers except via this interface. + */ +public interface IComputerAccess +{ + /** + * Mount a mount onto the computers' file system in a read only mode.
+ * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount(), ComputerCraftAPI.createResourceMount() or by creating your own objects that implement the IMount interface. + * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mountWritable(String, dan200.computercraft.api.filesystem.IWritableMount) + * @see #unmount(String) + * @see dan200.computercraft.api.filesystem.IMount + */ + public String mount( String desiredLocation, IMount mount ); + + /** + * TODO: Document me + */ + public String mount( String desiredLocation, IMount mount, String driveName ); + + /** + * Mount a mount onto the computers' file system in a writable mode.
+ * @param desiredLocation The location on the computercraft's file system where you would like the mount to be mounted. + * @param mount The mount object to mount on the computercraft. These can be obtained by calling ComputerCraftAPI.createSaveDirMount() or by creating your own objects that implement the IWritableMount interface. + * @return The location on the computercraft's file system where you the mount mounted, or null if there was already a file in the desired location. Store this value if you wish to unmount the mount later. + * @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String) + * @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(Class, String, String) + * @see #mount(String, IMount) + * @see #unmount(String) + * @see IMount + */ + public String mountWritable( String desiredLocation, IWritableMount mount ); + + /** + * TODO: Document me + */ + public String mountWritable( String desiredLocation, IWritableMount mount, String driveName ); + + /** + * Unmounts a directory previously mounted onto the computers file system by mount() or mountWritable().
+ * When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to + * access it. All directories mounted by a mount or mountWritable are automatically unmounted when the peripheral + * is attached if they have not been explicitly unmounted. + * @param location The desired location in the computers file system of the directory to unmount. + * This must be the location of a directory previously mounted by mount() or mountWritable(), as + * indicated by their return value. + * @see #mount(String, IMount) + * @see #mountWritable(String, IWritableMount) + */ + public void unmount( String location ); + + /** + * Returns the numerical ID of this computercraft.
+ * This is the same number obtained by calling os.getComputerID() or running the "id" program from lua, + * and is guarunteed unique. This number will be positive. + * @return The identifier. + */ + public int getID(); + + /** + * Causes an event to be raised on this computercraft, which the computercraft can respond to by calling + * os.pullEvent(). This can be used to notify the computercraft when things happen in the world or to + * this peripheral. + * @param event A string identifying the type of event that has occurred, this will be + * returned as the first value from os.pullEvent(). It is recommended that you + * you choose a name that is unique, and recognisable as originating from your + * peripheral. eg: If your peripheral type is "button", a suitable event would be + * "button_pressed". + * @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will + * be supplied as extra return values to os.pullEvent(). Objects in the array will be converted + * to lua data types in the same fashion as the return values of IPeripheral.callMethod().
+ * You may supply null to indicate that no arguments are to be supplied. + * @see dan200.computercraft.api.peripheral.IPeripheral#callMethod + */ + public void queueEvent( String event, Object[] arguments ); + + /** + * Get a string, unique to the computercraft, by which the computercraft refers to this peripheral. + * For directly attached peripherals this will be "left","right","front","back",etc, but + * for peripherals attached remotely it will be different. It is good practice to supply + * this string when raising events to the computercraft, so that the computercraft knows from + * which peripheral the event came. + * @return A string unique to the computercraft, but not globally. + */ + public String getAttachmentName(); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java new file mode 100755 index 0000000..a28d656 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -0,0 +1,100 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.peripheral; + +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; + +/** + * The interface that defines a peripheral. This should be implemented by the + * TileEntity of any common that you wish to be interacted with by + * computercraft or turtle. + */ +public interface IPeripheral +{ + /** + * Should return a string that uniquely identifies this type of peripheral. + * This can be queried from lua by calling peripheral.getType() + * @return A string identifying the type of peripheral. + */ + public String getType(); + + /** + * Should return an array of strings that identify the methods that this + * peripheral exposes to Lua. This will be called once before each attachment, + * and should not change when called multiple times. + * @return An array of strings representing method names. + * @see #callMethod + */ + public String[] getMethodNames(); + + /** + * This is called when a lua program on an attached computercraft calls peripheral.call() with + * one of the methods exposed by getMethodNames().
+ *
+ * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe + * when interacting with minecraft objects. + * @param computer The interface to the computercraft that is making the call. Remember that multiple + * computers can be attached to a peripheral at once. + * @param context The context of the currently running lua thread. This can be used to wait for events + * or otherwise yield. + * @param method An integer identifying which of the methods from getMethodNames() the computercraft + * wishes to call. The integer indicates the index into the getMethodNames() table + * that corresponds to the string passed into peripheral.call() + * @param arguments An array of objects, representing the arguments passed into peripheral.call().
+ * Lua values of type "string" will be represented by Object type String.
+ * Lua values of type "number" will be represented by Object type Double.
+ * Lua values of type "boolean" will be represented by Object type Boolean.
+ * Lua values of any other type will be represented by a null object.
+ * This array will be empty if no arguments are passed. + * @return An array of objects, representing values you wish to return to the lua program.
+ * Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.
+ * All other types will be converted to nil.
+ * You may return null to indicate no values should be returned. + * @throws Exception If you throw any exception from this function, a lua error will be raised with the + * same message as your exception. Use this to throw appropriate errors if the wrong + * arguments are supplied to your method. + * @see #getMethodNames + */ + public Object[] callMethod( IComputerAccess computer, ILuaContext context, int method, Object[] arguments ) throws LuaException, InterruptedException; + + /** + * Is called when canAttachToSide has returned true, and a computercraft is attaching to the peripheral. + * This will occur when a peripheral is placed next to an active computercraft, when a computercraft is turned on next to a peripheral, + * or when a turtle travels into a square next to a peripheral. + * Between calls to attach() and detach(), the attached computercraft can make method calls on the peripheral using peripheral.call(). + * This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment + * occurs.
+ *
+ * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe + * when interacting with minecraft objects. + * @param computer The interface to the computercraft that is being attached. Remember that multiple + * computers can be attached to a peripheral at once. + * @see #detach + */ + public void attach( IComputerAccess computer ); + + /** + * Is called when a computercraft is detaching from the peripheral. + * This will occur when a computercraft shuts down, when the peripheral is removed while attached to computers, + * or when a turtle moves away from a square attached to a peripheral. + * This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment + * occurs.
+ *
+ * Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe + * when interacting with minecraft objects. + * @param computer The interface to the computercraft that is being detached. Remember that multiple + * computers can be attached to a peripheral at once. + * @see #detach + */ + public void detach( IComputerAccess computer ); + + /** + * TODO: Document me + */ + public boolean equals( IPeripheral other ); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java new file mode 100755 index 0000000..a2775f9 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.peripheral; + +import net.minecraft.world.World; + +/** + * This interface is used to create peripheral implementations for blocks + * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) + */ +public interface IPeripheralProvider +{ + /** + * Produce an peripheral implementation from a block location. + * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) + * @return a peripheral, or null if there is not a peripheral here you'd like to handle. + */ + public IPeripheral getPeripheral( World world, int x, int y, int z, int side ); +} diff --git a/src/main/java/dan200/computercraft/api/peripheral/package-info.java b/src/main/java/dan200/computercraft/api/peripheral/package-info.java new file mode 100755 index 0000000..10ea4da --- /dev/null +++ b/src/main/java/dan200/computercraft/api/peripheral/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="1.75" ) +package dan200.computercraft.api.peripheral; + +import cpw.mods.fml.common.API; diff --git a/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java new file mode 100644 index 0000000..476b4fc --- /dev/null +++ b/src/main/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -0,0 +1,19 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.permissions; + +import net.minecraft.world.World; + +/** + * This interface is used to restrict where turtles can move or build + * @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider) + */ +public interface ITurtlePermissionProvider +{ + public boolean isBlockEnterable( World world, int x, int y, int z ); + public boolean isBlockEditable( World world, int x, int y, int z ); +} diff --git a/src/main/java/dan200/computercraft/api/permissions/package-info.java b/src/main/java/dan200/computercraft/api/permissions/package-info.java new file mode 100644 index 0000000..a51e7ec --- /dev/null +++ b/src/main/java/dan200/computercraft/api/permissions/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Permissions", apiVersion="1.75" ) +package dan200.computercraft.api.permissions; + +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java new file mode 100755 index 0000000..b85f2ef --- /dev/null +++ b/src/main/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.redstone; + +import net.minecraft.world.World; + +/** + * This interface is used to provide bundled redstone output for blocks + * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) + */ +public interface IBundledRedstoneProvider +{ + /** + * Produce an bundled redstone output from a block location. + * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) + * @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block + */ + public int getBundledRedstoneOutput( World world, int x, int y, int z, int side ); +} diff --git a/src/main/java/dan200/computercraft/api/redstone/package-info.java b/src/main/java/dan200/computercraft/api/redstone/package-info.java new file mode 100755 index 0000000..e01c623 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/redstone/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="1.75" ) +package dan200.computercraft.api.redstone; + +import cpw.mods.fml.common.API; diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java new file mode 100755 index 0000000..96c6159 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -0,0 +1,168 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +import dan200.computercraft.api.lua.ILuaContext; +import dan200.computercraft.api.lua.LuaException; +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +/** + * The interface passed to turtle by turtles, providing methods that they can call. + * This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade. + */ +public interface ITurtleAccess +{ + /** + * Returns the world in which the turtle resides. + * @return the world in which the turtle resides. + */ + public World getWorld(); + + /** + * Returns a vector containing the integer co-ordinates at which the turtle resides. + * @return a vector containing the integer co-ordinates at which the turtle resides. + */ + public ChunkCoordinates getPosition(); + + /** + * TODO: Document me + */ + public boolean teleportTo( World world, int x, int y, int z ); + + /** + * Returns a vector containing the floating point co-ordinates at which the turtle is rendered. + * This will shift when the turtle is moving. + * @param f The subframe fraction + * @return a vector containing the floating point co-ordinates at which the turtle resides. + */ + public Vec3 getVisualPosition( float f ); + + /** + * TODO: Document me + */ + public float getVisualYaw( float f ); + + /** + * Returns the world direction the turtle is currently facing. + * @return the world direction the turtle is currently facing. + */ + public int getDirection(); + + /** + * TODO: Document me + */ + public void setDirection( int dir ); + + /** + * TODO: Document me + */ + public int getSelectedSlot(); + + /** + * TODO: Document me + */ + public void setSelectedSlot( int slot ); + + /** + * Sets the colour of the turtle, as if the player had dyed it with a dye item. + * @param dyeColour 0-15 to dye the turtle one of the 16 standard minecraft colours, or -1 to remove the dye from the turtle. + */ + public void setDyeColour( int dyeColour ); + + /** + * Gets the colour the turtle has been dyed. + * @return 0-15 if the turtle has been dyed one of the 16 standard minecraft colours, -1 if the turtle is clean. + */ + public int getDyeColour(); + + /** + * TODO: Document me + */ + public IInventory getInventory(); + + /** + * TODO: Document me + */ + public boolean isFuelNeeded(); + + /** + * TODO: Document me + */ + public int getFuelLevel(); + + /** + * TODO: Document me + */ + public void setFuelLevel( int fuel ); + + /** + * TODO: Document me + */ + public int getFuelLimit(); + + /** + * Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle. + * @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number + * greater than the current fuel level of the turtle. + */ + public boolean consumeFuel( int fuel ); + + /** + * TODO: Document me + */ + public void addFuel( int fuel ); + + /** + * Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed + * on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up + * with the turtles standard movement and tool commands. An issued command will return an unique integer, which will + * be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the + * lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality. + * @param command an object which will execute the custom command when its point in the queue is reached + * @return the objects the command returned when executed. you should probably return these to the player + * unchanged if called from a peripheral method. + * @see ITurtleCommand + */ + public Object[] executeCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException; + + /** + * TODO: Document me + */ + public void playAnimation( TurtleAnimation animation ); + + /** + * Returns the turtle on the specified side of the turtle, if there is one. + * @return the turtle on the specified side of the turtle, if there is one. + */ + public ITurtleUpgrade getUpgrade( TurtleSide side ); + + /** + * TODO: Document me + */ + public void setUpgrade( TurtleSide side, ITurtleUpgrade upgrade ); + + /** + * Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one. + * @return the peripheral created by the upgrade on the specified side of the turtle, if there is one. + */ + public IPeripheral getPeripheral( TurtleSide side ); + + /** + * TODO: Document me + */ + public NBTTagCompound getUpgradeNBTData( TurtleSide side ); + + /** + * TODO: Document me + */ + public void updateUpgradeNBTData( TurtleSide side ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java new file mode 100755 index 0000000..17d113e --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -0,0 +1,25 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +/** + * An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand + * @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) + */ +public interface ITurtleCommand +{ + /** + * Will be called by the turtle on the main thread when it is time to execute the custom command. + * The handler should either perform the work of the command, and return success, or return + * failure with an error message to indicate the command cannot be executed at this time. + * @param turtle access to the turtle for whom the command was issued + * @return TurtleCommandResult.success() or TurtleCommandResult.failure( errorMessage ) + * @see ITurtleAccess#executeCommand(dan200.computercraft.api.lua.ILuaContext,ITurtleCommand) + * @see dan200.computercraft.api.turtle.TurtleCommandResult + */ + public TurtleCommandResult execute( ITurtleAccess turtle ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java new file mode 100755 index 0000000..0dcc6e6 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -0,0 +1,94 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +import dan200.computercraft.api.peripheral.IPeripheral; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +/** + * The primary interface for defining an turtle for Turtles. A turtle turtle + * can either be a new tool, or a new peripheral. + * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + */ +public interface ITurtleUpgrade +{ + /** + * Gets a unique numerical identifier representing this type of turtle turtle. + * Like Minecraft common and item IDs, you should strive to make this number unique + * among all turtle turtle that have been released for ComputerCraft. + * The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value, + * and 0-64 is reserved for future use by ComputerCraft. The turtle will + * fail registration if an already used ID is specified. + * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + */ + public int getUpgradeID(); + + /** + * Return a String to describe this type of turtle in turtle item names. + * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". + */ + public String getUnlocalisedAdjective(); + + /** + * Return whether this turtle adds a tool or a peripheral to the turtle. + * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. + * @see TurtleUpgradeType for the differences between the two. + */ + public TurtleUpgradeType getType(); + + /** + * Return an item stack representing the type of item that a turtle must be crafted + * with to create a turtle which holds this turtle. + * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. + */ + public ItemStack getCraftingItem(); + + /** + * Will only be called for Peripheral turtle. Creates a peripheral for a turtle + * being placed using this turtle. The peripheral created will be stored + * for the lifetime of the turtle, will have update() called once-per-tick, and will be + * attach'd detach'd and have methods called in the same manner as a Computer peripheral. + * + * @param turtle Access to the turtle that the peripheral is being created for. + * @param side Which side of the turtle (left or right) that the turtle resides on. + * @return The newly created peripheral. You may return null if this turtle is a Tool + * and this method is not expected to be called. + */ + public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); + + /** + * Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called + * by the turtle, and the tool is required to do some work. + * @param turtle Access to the turtle that the tool resides on. + * @param side Which side of the turtle (left or right) the tool resides on. + * @param verb Which action (dig or attack) the turtle is being called on to perform. + * @param direction Which world direction the action should be performed in, relative to the turtles + * position. This will either be up, down, or the direction the turtle is facing, depending on + * whether dig, digUp or digDown was called. + * @return Whether the turtle was able to perform the action, and hence whether the turtle.dig() + * or turtle.attack() lua method should return true. If true is returned, the tool will perform + * a swinging animation. You may return null if this turtle is a Peripheral + * and this method is not expected to be called. + */ + public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction ); + + /** + * Called to obtain the IIcon to be used when rendering a turtle peripheral. Needs to be a "common" + * type IIcon for now, as there is no way to determine which texture sheet an IIcon is from by the + * IIcon itself. + * @param turtle Access to the turtle that the peripheral resides on. + * @param side Which side of the turtle (left or right) the peripheral resides on. + * @return The IIcon that you wish to be used to render your turtle peripheral. + */ + public IIcon getIcon( ITurtleAccess turtle, TurtleSide side ); + + /** + * TODO: Document me + */ + public void update( ITurtleAccess turtle, TurtleSide side ); +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java new file mode 100755 index 0000000..abb4134 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -0,0 +1,22 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +public enum TurtleAnimation +{ + None, + MoveForward, + MoveBack, + MoveUp, + MoveDown, + TurnLeft, + TurnRight, + SwingLeftTool, + SwingRightTool, + Wait, + ShortWait, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java new file mode 100755 index 0000000..67046bd --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -0,0 +1,73 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +public final class TurtleCommandResult +{ + private static final TurtleCommandResult s_success = new TurtleCommandResult( true, null, null ); + private static final TurtleCommandResult s_emptyFailure = new TurtleCommandResult( false, null, null ); + + public static TurtleCommandResult success() + { + return success( null ); + } + + public static TurtleCommandResult success( Object[] results ) + { + if( results == null || results.length == 0 ) + { + return s_success; + } + else + { + return new TurtleCommandResult( true, null, results ); + } + } + + public static TurtleCommandResult failure() + { + return failure( null ); + } + + public static TurtleCommandResult failure( String errorMessage ) + { + if( errorMessage == null ) + { + return s_emptyFailure; + } + else + { + return new TurtleCommandResult( false, errorMessage, null ); + } + } + + private final boolean m_success; + private final String m_errorMessage; + private final Object[] m_results; + + private TurtleCommandResult( boolean success, String errorMessage, Object[] results ) + { + m_success = success; + m_errorMessage = errorMessage; + m_results = results; + } + + public boolean isSuccess() + { + return m_success; + } + + public String getErrorMessage() + { + return m_errorMessage; + } + + public Object[] getResults() + { + return m_results; + } +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java new file mode 100755 index 0000000..5fc7c61 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleSide.java @@ -0,0 +1,23 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +/** + * An enum representing the two sides of the turtle that a turtle turtle might reside. + */ +public enum TurtleSide +{ + /** + * The turtles left side (where the pickaxe usually is on a Wireless Mining Turtle) + */ + Left, + + /** + * The turtles right side (where the modem usually is on a Wireless Mining Turtle) + */ + Right, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java new file mode 100755 index 0000000..e5fd1af --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -0,0 +1,27 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +/** + * An enum representing the two different types of turtle that an ITurtleUpgrade + * implementation can add to a turtle. + * @see ITurtleUpgrade + */ +public enum TurtleUpgradeType +{ + /** + * A tool is rendered as an item on the side of the turtle, and responds to the turtle.dig() + * and turtle.attack() methods (Such as pickaxe or sword on Mining and Melee turtles). + */ + Tool, + + /** + * A peripheral adds a special peripheral which is attached to the side of the turtle, + * and can be interacted with the peripheral API (Such as the modem on Wireless Turtles). + */ + Peripheral, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java new file mode 100755 index 0000000..566fa48 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -0,0 +1,26 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.turtle; + +/** + * An enum representing the two different actions that an ITurtleUpgrade of type + * Tool may be called on to perform by a turtle. + * @see ITurtleUpgrade + * @see ITurtleUpgrade#useTool + */ +public enum TurtleVerb +{ + /** + * The turtle called turtle.dig(), turtle.digUp() or turtle.digDown() + */ + Dig, + + /** + * The turtle called turtle.attack(), turtle.attackUp() or turtle.attackDown() + */ + Attack, +} diff --git a/src/main/java/dan200/computercraft/api/turtle/package-info.java b/src/main/java/dan200/computercraft/api/turtle/package-info.java new file mode 100755 index 0000000..7825971 --- /dev/null +++ b/src/main/java/dan200/computercraft/api/turtle/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2015. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="1.75" ) +package dan200.computercraft.api.turtle; + +import cpw.mods.fml.common.API; diff --git a/src/main/java/dark/library/helpers/ItemFindingHelper.java b/src/main/java/dark/library/helpers/ItemFindingHelper.java new file mode 100644 index 0000000..c7a4139 --- /dev/null +++ b/src/main/java/dark/library/helpers/ItemFindingHelper.java @@ -0,0 +1,76 @@ +package dark.library.helpers; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemFindingHelper { + public static List findAllItemIn(World world, Vector3 start, Vector3 end) { + return world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox((double)start.x, (double)start.y, (double)start.z, (double)end.x, (double)end.y, (double)end.z)); + } + + public static List findSelectItems(World world, Vector3 start, Vector3 end, List disiredItems) { + List entityItems = ItemFindingHelper.findAllItemIn(world, start, end); + return ItemFindingHelper.filterEntityItemsList(entityItems, disiredItems); + } + + public static List filterEntityItemsList(List entityItems, List disiredItems) { + ArrayList newItemList = new ArrayList(); + block0: for (EntityItem entityItem : entityItems) { + for (ItemStack itemStack : disiredItems) { + if (entityItem.getEntityItem().getItem() != itemStack.getItem() || entityItem.getEntityItem().getItemDamage() != itemStack.getItemDamage() || newItemList.contains((Object)entityItem)) continue; + newItemList.add(entityItem); + continue block0; + } + } + return newItemList; + } + + public static List filterOutEntityItems(List entities) { + ArrayList newEntityList = new ArrayList(); + for (Entity entity : entities) { + if (!(entity instanceof EntityItem)) continue; + newEntityList.add((EntityItem)entity); + } + return newEntityList; + } + + public static List filterItems(List totalItems, List desiredItems) { + ArrayList newItemList = new ArrayList(); + block0: for (ItemStack entityItem : totalItems) { + for (ItemStack itemStack : desiredItems) { + if (entityItem.getItem() != itemStack.getItem() || entityItem.getItemDamage() != itemStack.getItemDamage() || newItemList.contains((Object)entityItem)) continue; + newItemList.add(entityItem); + continue block0; + } + } + return newItemList; + } + + public static boolean dropItemStackExact(World world, double x, double y, double z, ItemStack stack) { + if (!world.isRemote && stack != null) { + EntityItem entity = new EntityItem(world, x, y, z, stack); + entity.delayBeforeCanPickup = 10; + return world.spawnEntityInWorld((Entity)entity); + } + return false; + } + + public static void dropBlockAsItem(World world, int x, int y, int z) { + if (!world.isRemote) { + int meta = world.getBlockMetadata(x, y, z); + Block block = world.getBlock(x, y, z); + ArrayList items = block.getDrops(world, x, y, z, meta, 0); + for (ItemStack item : items) { + ItemFindingHelper.dropItemStackExact(world, (double)x + 0.5, (double)y + 0.5, (double)z + 0.5, item); + } + } + } +} + diff --git a/src/main/resources/al_logo.png b/src/main/resources/al_logo.png new file mode 100644 index 0000000..b4f9877 Binary files /dev/null and b/src/main/resources/al_logo.png differ diff --git a/src/main/resources/assets/assemblyline/languages/en_US.properties b/src/main/resources/assets/assemblyline/languages/en_US.properties new file mode 100644 index 0000000..e104d0a --- /dev/null +++ b/src/main/resources/assets/assemblyline/languages/en_US.properties @@ -0,0 +1,27 @@ +# Assembly Line Language Properties +# @author Calclavia + +# Gui +itemGroup.assemblyline=Assembly Line +assemblyline.gui.crafting=Crafting + +# Blocks +tile.crate.name=Crate +tile.crate.0.name=Basic Crate +tile.crate.1.name=Advanced Crate +tile.crate.2.name=Elite Crate +tile.conveyorBelt.name=Conveyor Belt +tile.imprinter.name=Imprinter +tile.encoder.name=Encoder +tile.detector.name=Detector +tile.armbot.name=Armbot +tile.craneController.name=Crane Controller +tile.craneFrame.name=Crane Frame +tile.manipulator.name=Manipulator +tile.rejector.name=Rejector +tile.turntable.name=Turntable + +# Items +item.imprint.name=Imprint +item.disk.name=Disk +item.blueprint.name=Blueprint \ No newline at end of file diff --git a/src/main/resources/assets/assemblyline/sounds.json b/src/main/resources/assets/assemblyline/sounds.json new file mode 100644 index 0000000..079ccd6 --- /dev/null +++ b/src/main/resources/assets/assemblyline/sounds.json @@ -0,0 +1,11 @@ +{ + "conveyor": { + "category": "master", + "sounds": [ + { + "name": "conveyor", + "stream": false + } + ] + } +} \ No newline at end of file diff --git a/src/main/resources/assets/assemblyline/sounds/conveyor.ogg b/src/main/resources/assets/assemblyline/sounds/conveyor.ogg new file mode 100644 index 0000000..2b2bc86 Binary files /dev/null and b/src/main/resources/assets/assemblyline/sounds/conveyor.ogg differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/crate.png b/src/main/resources/assets/assemblyline/textures/blocks/crate.png new file mode 100644 index 0000000..d234dac Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/crate.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/detector_green.png b/src/main/resources/assets/assemblyline/textures/blocks/detector_green.png new file mode 100644 index 0000000..6f05dcd Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/detector_green.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/detector_red.png b/src/main/resources/assets/assemblyline/textures/blocks/detector_red.png new file mode 100644 index 0000000..9484a2c Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/detector_red.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/encoder_bottom.png b/src/main/resources/assets/assemblyline/textures/blocks/encoder_bottom.png new file mode 100644 index 0000000..2c325a8 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/encoder_bottom.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/encoder_side.png b/src/main/resources/assets/assemblyline/textures/blocks/encoder_side.png new file mode 100644 index 0000000..5277333 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/encoder_side.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/encoder_top.png b/src/main/resources/assets/assemblyline/textures/blocks/encoder_top.png new file mode 100644 index 0000000..99f6860 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/encoder_top.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/imprinter_bottom.png b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_bottom.png new file mode 100644 index 0000000..68e2ab0 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_bottom.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/imprinter_side.png b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_side.png new file mode 100644 index 0000000..10b1978 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_side.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/imprinter_top.png b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_top.png new file mode 100644 index 0000000..8c3cab6 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/imprinter_top.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/machine.png b/src/main/resources/assets/assemblyline/textures/blocks/machine.png new file mode 100644 index 0000000..4f40a63 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/machine.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/turntable.png b/src/main/resources/assets/assemblyline/textures/blocks/turntable.png new file mode 100644 index 0000000..f22edc3 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/turntable.png differ diff --git a/src/main/resources/assets/assemblyline/textures/blocks/turntable_side.png b/src/main/resources/assets/assemblyline/textures/blocks/turntable_side.png new file mode 100644 index 0000000..1704176 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/blocks/turntable_side.png differ diff --git a/src/main/resources/assets/assemblyline/textures/gui/gui_empty.png b/src/main/resources/assets/assemblyline/textures/gui/gui_empty.png new file mode 100644 index 0000000..0673937 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/gui/gui_empty.png differ diff --git a/src/main/resources/assets/assemblyline/textures/gui/gui_encoder.png b/src/main/resources/assets/assemblyline/textures/gui/gui_encoder.png new file mode 100644 index 0000000..a71a962 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/gui/gui_encoder.png differ diff --git a/src/main/resources/assets/assemblyline/textures/gui/gui_imprinter.png b/src/main/resources/assets/assemblyline/textures/gui/gui_imprinter.png new file mode 100644 index 0000000..12a3985 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/gui/gui_imprinter.png differ diff --git a/src/main/resources/assets/assemblyline/textures/items/disk.png b/src/main/resources/assets/assemblyline/textures/items/disk.png new file mode 100644 index 0000000..192f60b Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/items/disk.png differ diff --git a/src/main/resources/assets/assemblyline/textures/items/imprint.png b/src/main/resources/assets/assemblyline/textures/items/imprint.png new file mode 100644 index 0000000..e7cedc8 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/items/imprint.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/armbot.png b/src/main/resources/assets/assemblyline/textures/models/armbot.png new file mode 100644 index 0000000..1374293 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/armbot.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/armbot_old.png b/src/main/resources/assets/assemblyline/textures/models/armbot_old.png new file mode 100644 index 0000000..a1a44b2 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/armbot_old.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame0.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame0.png new file mode 100644 index 0000000..bf35614 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame0.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame1.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame1.png new file mode 100644 index 0000000..4fc0f8d Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame1.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame10.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame10.png new file mode 100644 index 0000000..54d8f85 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame10.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame11.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame11.png new file mode 100644 index 0000000..72b4321 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame11.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame12.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame12.png new file mode 100644 index 0000000..8a79348 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame12.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame13.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame13.png new file mode 100644 index 0000000..a0e80d8 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame13.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame2.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame2.png new file mode 100644 index 0000000..e04c487 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame2.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame3.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame3.png new file mode 100644 index 0000000..39bc392 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame3.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame4.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame4.png new file mode 100644 index 0000000..bdce668 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame4.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame5.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame5.png new file mode 100644 index 0000000..9e9b3e5 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame5.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame6.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame6.png new file mode 100644 index 0000000..58c3eda Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame6.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame7.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame7.png new file mode 100644 index 0000000..c195a32 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame7.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame8.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame8.png new file mode 100644 index 0000000..01741c1 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame8.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/belt/frame9.png b/src/main/resources/assets/assemblyline/textures/models/belt/frame9.png new file mode 100644 index 0000000..67af3dd Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/belt/frame9.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/crane_controller_off.png b/src/main/resources/assets/assemblyline/textures/models/crane_controller_off.png new file mode 100644 index 0000000..08e15bf Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/crane_controller_off.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/crane_controller_on.png b/src/main/resources/assets/assemblyline/textures/models/crane_controller_on.png new file mode 100644 index 0000000..1634f50 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/crane_controller_on.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/crane_frame.png b/src/main/resources/assets/assemblyline/textures/models/crane_frame.png new file mode 100644 index 0000000..280107a Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/crane_frame.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/injector.png b/src/main/resources/assets/assemblyline/textures/models/injector.png new file mode 100644 index 0000000..f63471e Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/injector.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/laser_drill.png b/src/main/resources/assets/assemblyline/textures/models/laser_drill.png new file mode 100644 index 0000000..5ebaa7b Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/laser_drill.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/manipulator1.png b/src/main/resources/assets/assemblyline/textures/models/manipulator1.png new file mode 100644 index 0000000..f63471e Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/manipulator1.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/manipulator2.png b/src/main/resources/assets/assemblyline/textures/models/manipulator2.png new file mode 100644 index 0000000..f14fe55 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/manipulator2.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/quarryControllerOn.png b/src/main/resources/assets/assemblyline/textures/models/quarryControllerOn.png new file mode 100644 index 0000000..f36357a Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/quarryControllerOn.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/rejector.png b/src/main/resources/assets/assemblyline/textures/models/rejector.png new file mode 100644 index 0000000..4683119 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/rejector.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame0.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame0.png new file mode 100644 index 0000000..4e2551b Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame0.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame1.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame1.png new file mode 100644 index 0000000..7cd4912 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame1.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame10.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame10.png new file mode 100644 index 0000000..5d86d39 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame10.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame11.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame11.png new file mode 100644 index 0000000..15d2474 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame11.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame12.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame12.png new file mode 100644 index 0000000..c50a1d1 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame12.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame13.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame13.png new file mode 100644 index 0000000..3823f45 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame13.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame14.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame14.png new file mode 100644 index 0000000..b95e428 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame14.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame15.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame15.png new file mode 100644 index 0000000..b5319b4 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame15.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame16.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame16.png new file mode 100644 index 0000000..afd7537 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame16.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame17.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame17.png new file mode 100644 index 0000000..8bd8a32 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame17.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame18.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame18.png new file mode 100644 index 0000000..0803cab Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame18.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame19.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame19.png new file mode 100644 index 0000000..ef94c7b Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame19.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame2.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame2.png new file mode 100644 index 0000000..bc80768 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame2.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame20.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame20.png new file mode 100644 index 0000000..300b6d8 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame20.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame21.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame21.png new file mode 100644 index 0000000..b819185 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame21.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame22.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame22.png new file mode 100644 index 0000000..c89d9ce Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame22.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame23.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame23.png new file mode 100644 index 0000000..254a973 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame23.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame3.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame3.png new file mode 100644 index 0000000..5ef2228 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame3.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame4.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame4.png new file mode 100644 index 0000000..5e25ae6 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame4.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame5.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame5.png new file mode 100644 index 0000000..bc6bc6d Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame5.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame6.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame6.png new file mode 100644 index 0000000..9081ae0 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame6.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame7.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame7.png new file mode 100644 index 0000000..9072ddd Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame7.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame8.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame8.png new file mode 100644 index 0000000..92c018c Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame8.png differ diff --git a/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame9.png b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame9.png new file mode 100644 index 0000000..541e193 Binary files /dev/null and b/src/main/resources/assets/assemblyline/textures/models/slantedbelt/frame9.png differ diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..8ee8890 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,20 @@ +[ +{ + "modid" : "AssemblyLine", + "name" : "Assembly Line", + "version" : "0.2.8", + "url" : "http://calclavia.com/universalelectricity/?m=18", + "credits" : "", + "authors": [ + "Calclavia", + "Darkguardsman", + "Briman" + ], + "description": "A mod that brings conveyor belt transporting systems to Minecraft.", + "logoFile" : "/al_logo.png", + "updateUrl" : "http://universalelectricity.com/?m=assembly_line", + "parent" : "", + "screenshots": [ + ] +} +] \ No newline at end of file