diff --git a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/PComp.class b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/PComp.class index 681c53e..b8ded63 100644 Binary files a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/PComp.class and b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/PComp.class differ diff --git a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIComputer.class b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIComputer.class index ce89434..e5543c2 100644 Binary files a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIComputer.class and b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIComputer.class differ diff --git a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIHandler.class b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIHandler.class index fe584fb..2b9d453 100644 Binary files a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIHandler.class and b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/gui/GUIHandler.class differ diff --git a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/tile/TileEntityComputer.class b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/tile/TileEntityComputer.class index daef8b5..ac6e499 100644 Binary files a/classes/production/Programmable_Computers_main/org/teamavion/pcomp/tile/TileEntityComputer.class and b/classes/production/Programmable_Computers_main/org/teamavion/pcomp/tile/TileEntityComputer.class differ diff --git a/src/main/java/org/teamavion/pcomp/PComp.java b/src/main/java/org/teamavion/pcomp/PComp.java index daf4d13..9eeb53f 100644 --- a/src/main/java/org/teamavion/pcomp/PComp.java +++ b/src/main/java/org/teamavion/pcomp/PComp.java @@ -1,5 +1,12 @@ package org.teamavion.pcomp; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.WorldProvider; +import net.minecraftforge.common.DimensionManager; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; @@ -11,6 +18,10 @@ import org.teamavion.pcomp.tile.TileEntityComputer; import org.teamavion.util.automation.BlockRegister; import org.teamavion.util.automation.SetupHelper; import org.teamavion.util.support.NetworkChannel; +import org.teamavion.util.support.Reflection; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Mod(modid = PComp.MODID, version = PComp.VERSION) public class PComp @@ -30,6 +41,26 @@ public class PComp SetupHelper.setup(PComp.class); SetupHelper.registerRenders(PComp.class); channel = new NetworkChannel(MODID); + channel.registerWorldHandler((side, worldEvent) -> { + World w = (World) Reflection.getValue("world", DimensionManager.getProvider((Integer) Reflection.getValue("id", worldEvent, worldEvent.getClass())), WorldProvider.class); // Get World + TileEntity t = w.getTileEntity(worldEvent.getPos()); + try { + if (t != null) { + Matcher m = Pattern.compile("(\\d+):(\\d+):(\\d+);(\\d+);(.+)").matcher(worldEvent.getData()); + if(!m.matches()) throw new RuntimeException(); + String s1; + NBTTagCompound n = JsonToNBT.getTagFromJson((s1=m.group(5)).substring(8, s1.length()-1) + .replace("&rbr;", "}") + .replace("&lbr;", "{") + .replace(""", "\"") + .replace("&", "&")); + t.readFromNBT(n); + } + } catch (NBTException e) { + e.printStackTrace(); + } + return null; + }); NetworkRegistry.INSTANCE.registerGuiHandler(this, new GUIHandler()); GameRegistry.registerTileEntity(TileEntityComputer.class, "computer"); } diff --git a/src/main/java/org/teamavion/pcomp/gui/GUIComputer.java b/src/main/java/org/teamavion/pcomp/gui/GUIComputer.java index 79ebf7e..179df3e 100644 --- a/src/main/java/org/teamavion/pcomp/gui/GUIComputer.java +++ b/src/main/java/org/teamavion/pcomp/gui/GUIComputer.java @@ -1,11 +1,16 @@ package org.teamavion.pcomp.gui; +import com.google.gson.JsonObject; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; +import net.minecraft.nbt.NBTTagCompound; import org.lwjgl.input.Keyboard; +import org.teamavion.pcomp.PComp; +import org.teamavion.pcomp.net.DataListener; import org.teamavion.pcomp.tile.TileEntityComputer; +import org.teamavion.util.support.NetworkChannel; import org.teamavion.util.support.Reflection; import org.teamavion.util.support.Result; @@ -17,9 +22,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; @SuppressWarnings({"unchecked", "WeakerAccess"}) -public class GUIComputer extends GuiScreen{ +public class GUIComputer extends GuiScreen implements DataListener>{ protected final int viewportMin = -90, viewportMax = 45, maxInputLines = 128, textFieldLen = 240, textColor = 0xFFFFFF; protected final long keyPressTimeout = 0; // timeout period between keypresses to minimize spam @@ -49,6 +55,7 @@ public class GUIComputer extends GuiScreen{ button = new GuiButton(-1, this.width / 2 - textFieldLen / 2, this.height / 2 + viewportMax + 30, "Execute"); button.width = textFieldLen; inputLines[selected].setFocused(true); + computer.registerDataListener(this); } @Override @@ -235,9 +242,27 @@ public class GUIComputer extends GuiScreen{ } } + @Override + public void onGuiClosed() { + computer.unregisterDataListener(this); + for(int i = 0; i data) { + for(int i = 0; i { + void getData(T data); +} diff --git a/src/main/java/org/teamavion/pcomp/tile/TileEntityComputer.java b/src/main/java/org/teamavion/pcomp/tile/TileEntityComputer.java index c7d2051..526b225 100644 --- a/src/main/java/org/teamavion/pcomp/tile/TileEntityComputer.java +++ b/src/main/java/org/teamavion/pcomp/tile/TileEntityComputer.java @@ -1,10 +1,48 @@ package org.teamavion.pcomp.tile; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import org.teamavion.pcomp.net.DataListener; + +import java.util.ArrayList; +import java.util.HashMap; public class TileEntityComputer extends TileEntity{ + + protected final HashMap lines = new HashMap<>(); + protected final ArrayList>> dataListeners = new ArrayList<>(); + public boolean isUsableByPlayer(EntityPlayer player) { return world.getTileEntity(getPos()) == this && player.getDistanceSq(getPos().getX() + 0.5, getPos().getY() + 0.5,getPos().getZ() + 0.5) < 64; } + + public String readLine(int line){ return lines.keySet().contains(line)?lines.get(line):""; } + public void writeLine(int line, String data){ lines.put(line, data); } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + int j = 0, k = 0; + String s; + for(Integer i : lines.keySet()) if(i>j) j = i; + for(Integer i : lines.keySet()) if(i> d : dataListeners) d.getData(lines); + } + + public void registerDataListener(DataListener> listener){ dataListeners.add(listener); listener.getData(lines); } + public void unregisterDataListener(DataListener> listener){ dataListeners.remove(listener); } + } diff --git a/src/main/lib/minecrafthelper-1.0-sources.jar b/src/main/lib/minecrafthelper-1.0-sources.jar index e545ec2..eddc14c 100644 Binary files a/src/main/lib/minecrafthelper-1.0-sources.jar and b/src/main/lib/minecrafthelper-1.0-sources.jar differ diff --git a/src/main/lib/minecrafthelper-1.0.jar b/src/main/lib/minecrafthelper-1.0.jar index 0359e53..ebbfef8 100644 Binary files a/src/main/lib/minecrafthelper-1.0.jar and b/src/main/lib/minecrafthelper-1.0.jar differ