mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-10-25 20:32:32 +00:00
Dump button, dumps the grid to linked inventory (#228)
This commit is contained in:
1 parent
3548fcb9a9
commit
611d84923d
6 files changed
+114
No files matched your search
@@ -4,6 +4,8 @@ import java.awt.Rectangle;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
@@ -21,12 +23,14 @@ import codechicken.nei.VisiblityData;
|
||||
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 {
|
||||
@@ -121,6 +125,45 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
|
||||
|
||||
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 + 161, this.guiTop + 5));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0 && logic.chest != null) {
|
||||
TConstruct.packetPipeline.sendToServer(new CraftingStationDumpPacket());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
drawDumpButtonTooltip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawDumpButtonTooltip(int mouseX, int mouseY) {
|
||||
for (Object obj : this.buttonList) {
|
||||
if (obj instanceof GuiButtonDump) {
|
||||
GuiButtonDump button = (GuiButtonDump) obj;
|
||||
if (button.func_146115_a()) {
|
||||
this.drawHoveringText(
|
||||
Collections.singletonList(
|
||||
StatCollector.translateToLocal("craftingstation.dump_button.tooltip")),
|
||||
mouseX,
|
||||
mouseY,
|
||||
this.fontRendererObj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -523,6 +566,27 @@ public class CraftingStationGui extends GuiContainer implements INEIGuiHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static class GuiButtonDump extends GuiButton {
|
||||
|
||||
private GuiButtonDump(int id, int x, int y) {
|
||||
super(id, x, y, 10, 10, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (this.visible) {
|
||||
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);
|
||||
mc.getTextureManager().bindTexture(CraftingStationGui.icons);
|
||||
int v = this.field_146123_n ? 213 : 223;
|
||||
drawTexturedModalRect(this.xPosition, this.yPosition, 0, v, this.width, this.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hide the deprecated stuff at the bottom
|
||||
*/
|
||||
|
||||
@@ -434,4 +434,21 @@ public class CraftingStationContainer extends Container {
|
||||
|
||||
return didSomething;
|
||||
}
|
||||
|
||||
// Dump crafting grid to connected chests
|
||||
public void dumpCraftingGrid() {
|
||||
if (logic.slotCount == 0) return;
|
||||
|
||||
// 46 is the first slot index of the attached inventory
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack stack = craftMatrix.getStackInSlot(i);
|
||||
if (stack != null && stack.stackSize > 0) {
|
||||
if (mergeItemStack(stack, 46, 46 + logic.slotCount, false)) {
|
||||
craftMatrix.setInventorySlotContents(i, stack.stackSize > 0 ? stack : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.onCraftMatrixChanged(this.craftMatrix);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,8 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
registerPacket(MovementUpdatePacket.class);
|
||||
|
||||
registerPacket(ArmourGuiSyncPacket.class);
|
||||
|
||||
registerPacket(CraftingStationDumpPacket.class);
|
||||
}
|
||||
|
||||
// Method to call from FMLPostInitializationEvent
|
||||
|
||||
@@ -859,6 +859,7 @@ smeltery.brick.tooltip2=(Safe for decoration)
|
||||
smeltery.castingtable.tooltip=Basic Smeltery equipment
|
||||
smeltery.castingfaucet.tooltip=This Smeltery is leaking
|
||||
smeltery.castingbasin.tooltip=For the ambitious Smeltery
|
||||
craftingstation.dump_button.tooltip=Dump grid content to linked inventory
|
||||
#Dear translators, only translate these lines if the jokes are applicable in your language.
|
||||
grout.tooltip=I am Grout!
|
||||
frypankill.tooltip=This poor animal met its demise with a loud *bang*
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.1 KiB |
Reference in new issue
Block a user