Add copy / pasting of slot configs.
This commit is contained in:
parent
9b23945670
commit
65695b86c1
2 changed files with 60 additions and 0 deletions
|
@ -32,6 +32,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
import reborncore.api.tile.IUpgradeable;
|
import reborncore.api.tile.IUpgradeable;
|
||||||
import reborncore.common.tile.TileLegacyMachineBase;
|
import reborncore.common.tile.TileLegacyMachineBase;
|
||||||
import techreborn.client.container.builder.BuiltContainer;
|
import techreborn.client.container.builder.BuiltContainer;
|
||||||
|
@ -247,6 +248,20 @@ public class GuiBase extends GuiContainer {
|
||||||
super.mouseReleased(mouseX, mouseY, state);
|
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
|
@Override
|
||||||
public void onGuiClosed() {
|
public void onGuiClosed() {
|
||||||
showSlotConfig = false;
|
showSlotConfig = false;
|
||||||
|
|
|
@ -25,18 +25,25 @@
|
||||||
package techreborn.client.gui.slot;
|
package techreborn.client.gui.slot;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
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.client.renderer.GlStateManager;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import reborncore.client.gui.GuiUtil;
|
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.container.builder.BuiltContainer;
|
||||||
import techreborn.client.gui.GuiBase;
|
import techreborn.client.gui.GuiBase;
|
||||||
import techreborn.client.gui.slot.elements.ConfigSlotElement;
|
import techreborn.client.gui.slot.elements.ConfigSlotElement;
|
||||||
import techreborn.client.gui.slot.elements.ElementBase;
|
import techreborn.client.gui.slot.elements.ElementBase;
|
||||||
import techreborn.client.gui.slot.elements.SlotType;
|
import techreborn.client.gui.slot.elements.SlotType;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
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 {
|
public static boolean mouseClicked(int mouseX, int mouseY, int mouseButton, GuiBase guiBase) throws IOException {
|
||||||
if (mouseButton == 0) {
|
if (mouseButton == 0) {
|
||||||
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
for (ConfigSlotElement configSlotElement : getVisibleElements()) {
|
||||||
|
|
Loading…
Reference in a new issue