Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/tconstruct/tools/gui/CraftingStationGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
Expand All @@ -21,12 +22,14 @@
import codechicken.nei.api.INEIGuiHandler;
import codechicken.nei.api.TaggedInventoryArea;
import cpw.mods.fml.common.Optional;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.HarvestLevels;
import tconstruct.tools.logic.CraftingStationLogic;
import tconstruct.util.network.CraftingStationDumpPacket;

@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
Expand Down Expand Up @@ -121,6 +124,22 @@ public void initGui() {

this.craftingTextLeft = this.craftingLeft - this.guiLeft;
this.descTextLeft = this.descLeft - this.guiLeft;

// Add dump button if chest is connected
this.buttonList.clear();
if (logic.chest != null) {
int bothOffset = 0;
if (logic.slotCount > 54) bothOffset += 12;
bothOffset += 122;
this.buttonList.add(new GuiButtonDump(0, this.guiLeft + bothOffset + 159, this.guiTop + 5));
}
}

@Override
protected void actionPerformed(GuiButton button) {
if (button.id == 0 && logic.chest != null) {
TConstruct.packetPipeline.sendToServer(new CraftingStationDumpPacket());
}
}

@Override
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/tconstruct/tools/gui/GuiButtonDump.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tconstruct.tools.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;

import org.lwjgl.opengl.GL11;

public class GuiButtonDump extends GuiButton {

public GuiButtonDump(int id, int x, int y) {
super(id, x, y, 12, 12, "D");
}

@Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.visible) {
FontRenderer fontrenderer = mc.fontRenderer;
this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition
&& mouseX < this.xPosition + this.width
&& mouseY < this.yPosition + this.height;

GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

int color = this.enabled ? (this.field_146123_n ? 0xFFAAAAAA : 0xFF555555) : 0xFF333333;
drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + this.height, color);

drawRect(this.xPosition, this.yPosition, this.xPosition + this.width, this.yPosition + 1, 0xFF000000); // Top
drawRect(this.xPosition, this.yPosition, this.xPosition + 1, this.yPosition + this.height, 0xFF000000); // Left
drawRect(
this.xPosition + this.width - 1,
this.yPosition,
this.xPosition + this.width,
this.yPosition + this.height,
0xFF000000); // Right
drawRect(
this.xPosition,
this.yPosition + this.height - 1,
this.xPosition + this.width,
this.yPosition + this.height,
0xFF000000); // Bottom

int textColor = this.enabled ? 0xFFFFFF : 0x666666;
this.drawCenteredString(
fontrenderer,
this.displayString,
this.xPosition + this.width / 2,
this.yPosition + (this.height - 8) / 2,
textColor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,20 @@ protected boolean mergeItemStackMove(@Nonnull ItemStack stack, int startIndex, i

return didSomething;
}

// Dump crafting grid to connected chests
public void dumpCraftingGrid() {
if (logic.slotCount == 0) return;

for (int i = 1; i < 10; i++) {
ItemStack stack = craftMatrix.getStackInSlot(i - 1);
if (stack != null && stack.stackSize > 0) {
if (mergeItemStack(stack, 46, 46 + logic.slotCount, false)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it's done a bit in this file, but this use of 46 as a magic number is hard to follow. I don't think this file warrants a refactor, but you should comment here that 46 is the index corresponding to the first slot in an attached inventory.

craftMatrix.setInventorySlotContents(i - 1, stack.stackSize > 0 ? stack : null);
}
}
Comment on lines +442 to +448
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ranging i from 1 to 9 to then only ever reference it as i - 1 is silly. It should iterate 0 to 8 and just be referenced as i.

}

this.onCraftMatrixChanged(this.craftMatrix);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tconstruct.util.network;

import net.minecraft.entity.player.EntityPlayer;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import mantle.common.network.AbstractPacket;
import tconstruct.tools.inventory.CraftingStationContainer;

public class CraftingStationDumpPacket extends AbstractPacket {

public CraftingStationDumpPacket() {}

@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {}

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {}

@Override
public void handleClientSide(EntityPlayer player) {}

@Override
public void handleServerSide(EntityPlayer player) {
if (player.openContainer instanceof CraftingStationContainer) {
CraftingStationContainer container = (CraftingStationContainer) player.openContainer;
container.dumpCraftingGrid();
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/tconstruct/util/network/PacketPipeline.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public void registerPackets() {
registerPacket(MovementUpdatePacket.class);

registerPacket(ArmourGuiSyncPacket.class);

registerPacket(CraftingStationDumpPacket.class);
}

// Method to call from FMLPostInitializationEvent
Expand Down