Add copy / pasting of slot configs.

This commit is contained in:
modmuss50 2018-04-12 19:27:11 +01:00
parent 9b23945670
commit 65695b86c1
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
2 changed files with 60 additions and 0 deletions

View file

@ -32,6 +32,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import reborncore.api.tile.IUpgradeable;
import reborncore.common.tile.TileLegacyMachineBase;
import techreborn.client.container.builder.BuiltContainer;
@ -247,6 +248,20 @@ public class GuiBase extends GuiContainer {
super.mouseReleased(mouseX, mouseY, state);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(showSlotConfig){
if(isCtrlKeyDown() && keyCode == Keyboard.KEY_C){
GuiSlotConfiguration.copyToClipboard();
return;
} else if(isCtrlKeyDown() && keyCode == Keyboard.KEY_V){
GuiSlotConfiguration.pasteFromClipboard();
return;
}
}
super.keyTyped(typedChar, keyCode);
}
@Override
public void onGuiClosed() {
showSlotConfig = false;

View file

@ -25,18 +25,25 @@
package techreborn.client.gui.slot;
import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.inventory.Slot;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.lwjgl.input.Keyboard;
import reborncore.client.gui.GuiUtil;
import reborncore.common.network.NetworkManager;
import reborncore.common.network.packet.PacketConfigSave;
import reborncore.common.tile.TileLegacyMachineBase;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.gui.GuiBase;
import techreborn.client.gui.slot.elements.ConfigSlotElement;
import techreborn.client.gui.slot.elements.ElementBase;
import techreborn.client.gui.slot.elements.SlotType;
import javax.annotation.Nullable;
import java.awt.*;
import java.io.IOException;
import java.util.ArrayList;
@ -105,6 +112,44 @@ public class GuiSlotConfiguration {
}
}
public static void copyToClipboard(){
TileLegacyMachineBase machine = getMachine();
if(machine == null || machine.slotConfiguration == null){
return;
}
String json = machine.slotConfiguration.toJson(machine.getClass().getCanonicalName());
GuiScreen.setClipboardString(json);
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Slot configuration copyied to clipboard"));
}
public static void pasteFromClipboard(){
TileLegacyMachineBase machine = getMachine();
if(machine == null || machine.slotConfiguration == null){
return;
}
String json = GuiScreen.getClipboardString();
try {
machine.slotConfiguration.readJson(json, machine.getClass().getCanonicalName());
NetworkManager.sendToServer(new PacketConfigSave(machine.getPos(), machine.slotConfiguration));
Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Slot configuration loaded from clipboard"));
} catch (UnsupportedOperationException e) {
Minecraft.getMinecraft().player.sendMessage(new TextComponentString(e.getMessage()));
}
}
@Nullable
private static TileLegacyMachineBase getMachine(){
if(!(Minecraft.getMinecraft().currentScreen instanceof GuiBase)){
return null;
}
GuiBase base = (GuiBase) Minecraft.getMinecraft().currentScreen;
if(!(base.tile instanceof TileLegacyMachineBase)){
return null;
}
TileLegacyMachineBase machineBase = (TileLegacyMachineBase) base.tile;
return machineBase;
}
public static boolean mouseClicked(int mouseX, int mouseY, int mouseButton, GuiBase guiBase) throws IOException {
if (mouseButton == 0) {
for (ConfigSlotElement configSlotElement : getVisibleElements()) {