A load of work on the system, seams a lot is broken.

This commit is contained in:
modmuss50 2015-06-17 17:01:26 +01:00
parent d8e6e88797
commit 598badc375
17 changed files with 268 additions and 53 deletions

View file

@ -18,7 +18,7 @@ import techreborn.init.ModRecipes;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketHandler;
import techreborn.proxies.CommonProxy;
import techreborn.tiles.iesu.IDSUManager;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.util.LogHelper;
import techreborn.world.TROreGen;
import cpw.mods.fml.client.event.ConfigChangedEvent;

View file

@ -1,10 +1,10 @@
package techreborn.blocks.storage;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import techreborn.Core;
@ -12,8 +12,9 @@ import techreborn.blocks.BlockMachineBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import techreborn.client.GuiHandler;
import techreborn.tiles.iesu.IDSUManager;
import techreborn.tiles.iesu.TileIDSU;
import techreborn.packets.PacketHandler;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.tiles.idsu.TileIDSU;
public class BlockIDSU extends BlockMachineBase {
@ -62,6 +63,9 @@ public class BlockIDSU extends BlockMachineBase {
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
PacketHandler.sendPacketToPlayer(IDSUManager.INSTANCE.getPacket(world, player), player);
}
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.idsuID, world, x, y,
z);

View file

@ -1,14 +1,13 @@
package techreborn.client;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.client.container.*;
import techreborn.client.gui.*;
import techreborn.pda.GuiPda;
import techreborn.tiles.*;
import cpw.mods.fml.common.network.IGuiHandler;
import techreborn.tiles.iesu.TileIDSU;
import techreborn.tiles.idsu.TileIDSU;
import techreborn.tiles.lesu.TileLesu;
public class GuiHandler implements IGuiHandler {

View file

@ -1,12 +1,8 @@
package techreborn.client.container;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import techreborn.tiles.TileAesu;
import techreborn.tiles.iesu.TileIDSU;
import techreborn.tiles.idsu.TileIDSU;
public class ContainerIDSU extends TechRebornContainer {

View file

@ -1,22 +1,20 @@
package techreborn.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import net.minecraft.world.World;
import techreborn.client.container.ContainerIDSU;
import techreborn.cofhLib.gui.GuiBase;
import techreborn.cofhLib.gui.element.ElementListBox;
import techreborn.cofhLib.gui.element.ElementTextFieldLimited;
import techreborn.cofhLib.gui.element.listbox.ListBoxElementText;
import techreborn.tiles.iesu.TileIDSU;
import java.awt.*;
import java.util.ArrayList;
import techreborn.packets.PacketHandler;
import techreborn.packets.PacketIdsu;
import techreborn.tiles.idsu.ClientSideIDSUManager;
import techreborn.tiles.idsu.IDSUManager;
import techreborn.tiles.idsu.TileIDSU;
public class GuiIDSU extends GuiBase {
@ -40,32 +38,59 @@ public class GuiIDSU extends GuiBase {
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
texture = new ResourceLocation(
"techreborn", "textures/gui/aesu.png");
drawTitle = true;
drawInventory = true;
drawTitle = false;
drawInventory = false;
name = StatCollector.translateToLocal("tile.techreborn.aesu.name");
}
@Override
public void initGui() {
super.initGui();
// this.buttonList.clear();
// int k = (this.width - this.xSize) / 2;
// int l = (this.height - this.ySize) / 2;
// this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
// this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
// this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-"));
// this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--"));
listBox = new ElementListBox(this, 20, 20, 60, 60);
for (int i = 0; i < 15; i++) {
listBox.add(new ListBoxElementText("Name " + i));
this.buttonList.clear();
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-"));
this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--"));
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
listBox = new ElementListBox(this, 10, 28, 80, 60);
if(idsu.getWorldObj() != null){
for(World world : ClientSideIDSUManager.CLIENT.worldData.keySet()){
// System.out.println(world.n + ":" + idsu.getWorldObj().getProviderName());
//if(world.getProviderName().equals(idsu.getWorldObj().getProviderName())){
IDSUManager.IDSUWorldSaveData saveData = ClientSideIDSUManager.CLIENT.getWorldDataFormWorld(world);
for(Integer id : saveData.idsuValues.keySet()){
IDSUManager.IDSUValueSaveData valueSaveData = saveData.idsuValues.get(id);
if(valueSaveData.name != ""){
listBox.add(new ListBoxElementText(valueSaveData.name + " - " + id));
} else {
listBox.add(new ListBoxElementText(id.toString()));
}
}
// }
}
}
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
addElement(listBox);
idFeild = new ElementTextFieldLimited(this, 20, 10, 20, 10);
idFeild = new ElementTextFieldLimited(this, 10, 10, 30, 10, (short) 4);
idFeild.setFilter("1234567890", false);
addElement(idFeild);
}
@Override
protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
PacketHandler.sendPacketToServer(new PacketIdsu(button.id, idsu, Integer.parseInt(idFeild.getText()), "TestName"));
}
}

View file

@ -151,11 +151,11 @@ public class ElementListBox extends ElementBase {
int nextElement = _firstIndexDisplayed;
glPushMatrix();
glDisable(GL_LIGHTING);
//glDisable(GL_LIGHTING);
glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
//glEnable(GL_STENCIL_TEST);
//glClear(GL_STENCIL_BUFFER_BIT);
//drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
glTranslated(-scrollHoriz, 0, 0);
@ -169,7 +169,7 @@ public class ElementListBox extends ElementBase {
heightDrawn += _elements.get(nextElement).getHeight();
nextElement++;
}
glDisable(GL_STENCIL_TEST);
//glDisable(GL_STENCIL_TEST);
glPopMatrix();
}

View file

@ -39,7 +39,7 @@ public class ElementTextField extends ElementBase
protected boolean smartCaret = true;
protected boolean smartCaretCase = true;
protected boolean enableStencil = true;
protected boolean enableStencil = false;
public ElementTextField(GuiBase gui, int posX, int posY, int width, int height)
{

View file

@ -3,8 +3,11 @@ package techreborn.command;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import techreborn.api.recipe.RecipeHandler;
import techreborn.packets.PacketHandler;
import techreborn.tiles.idsu.IDSUManager;
public class TechRebornDevCommand extends CommandBase {
@ -28,11 +31,13 @@ public class TechRebornDevCommand extends CommandBase {
if (args.length == 0) {
sender.addChatMessage(new ChatComponentText("You need to use arguments"));
} else if ("help".equals(args[0])) {
sender.addChatMessage(new ChatComponentText("recipes - Reloads all of the machine recipes"));
sender.addChatMessage(new ChatComponentText("recipes - Shows size of the recipe array"));
sender.addChatMessage(new ChatComponentText("idsu - Resyncs the idsu server instance to the senders client"));
} else if ("recipes".equals(args[0])) {
sender.addChatMessage(new ChatComponentText(RecipeHandler.recipeList.size() + " recipes loaded"));
} else if ("idsu".equals(args[0])){
PacketHandler.sendPacketToPlayer(IDSUManager.INSTANCE.getPacket(sender.getEntityWorld(), (EntityPlayer) sender), (EntityPlayer) sender);
}
}
}

View file

@ -38,7 +38,7 @@ import techreborn.blocks.storage.BlockLesu;
import techreborn.blocks.storage.BlockLesuStorage;
import techreborn.itemblocks.*;
import techreborn.tiles.*;
import techreborn.tiles.iesu.TileIDSU;
import techreborn.tiles.idsu.TileIDSU;
import techreborn.tiles.lesu.TileLesu;
import techreborn.tiles.lesu.TileLesuStorage;
import techreborn.util.LogHelper;

View file

@ -22,6 +22,8 @@ public class PacketHandler extends
public PacketHandler() {
addDiscriminator(0, PacketAesu.class);
addDiscriminator(1, PacketIdsu.class);
addDiscriminator(2, PacketSendIDSUManager.class);
}
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()

View file

@ -0,0 +1,58 @@
package techreborn.packets;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.PacketBuffer;
import techreborn.tiles.idsu.TileIDSU;
import java.io.IOException;
/**
* Created by mark on 17/06/15.
*/
public class PacketIdsu extends SimplePacket {
public PacketIdsu() {
}
int buttonID, channel;
String newName;
TileIDSU idsu;
public PacketIdsu(int buttonID, TileIDSU idsu, int channel, String newName) {
this.idsu = idsu;
this.buttonID = buttonID;
this.channel = channel;
this.newName = newName;
if(this.newName.equals("")){
this.newName = "BLANK!!!";
}
}
@Override
public void writeData(ByteBuf out) throws IOException {
SimplePacket.writeTileEntity(idsu, out);
out.writeInt(buttonID);
out.writeInt(channel);
PacketBuffer buffer = new PacketBuffer(out);
buffer.writeStringToBuffer(newName);
}
@Override
public void readData(ByteBuf in) throws IOException {
this.idsu = (TileIDSU) SimplePacket.readTileEntity(in);
buttonID = in.readInt();
channel = in.readInt();
PacketBuffer buffer = new PacketBuffer(in);
newName = buffer.readStringFromBuffer(9);
}
@Override
public void execute() {
if(!idsu.getWorldObj().isRemote){
idsu.handleGuiInputFromClient(buttonID, channel, player, newName);
}
}
}

View file

@ -0,0 +1,40 @@
package techreborn.packets;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.PacketBuffer;
import techreborn.tiles.idsu.ClientSideIDSUManager;
import java.io.IOException;
public class PacketSendIDSUManager extends SimplePacket {
String json;
public PacketSendIDSUManager() {
}
public PacketSendIDSUManager(String json, EntityPlayer player) {
this.json = json;
this.player = player;
}
@Override
public void writeData(ByteBuf out) throws IOException {
PacketBuffer buffer = new PacketBuffer(out);
buffer.writeStringToBuffer(json);
writePlayer(player, out);
}
@Override
public void readData(ByteBuf in) throws IOException {
PacketBuffer buffer = new PacketBuffer(in);
json = buffer.readStringFromBuffer(99999999);
player = readPlayer(in);
}
@Override
public void execute() {
ClientSideIDSUManager.CLIENT.loadFromString(json, player.worldObj);
}
}

View file

@ -5,6 +5,8 @@ import net.minecraftforge.common.MinecraftForge;
import techreborn.client.IconSupplier;
import techreborn.client.hud.ChargeHud;
import techreborn.client.keybindings.KeyBindings;
import techreborn.tiles.idsu.ClientSideIDSUManager;
import techreborn.tiles.idsu.IDSUManager;
public class ClientProxy extends CommonProxy {
@ -15,5 +17,6 @@ public class ClientProxy extends CommonProxy {
MinecraftForge.EVENT_BUS.register(new IconSupplier());
MinecraftForge.EVENT_BUS.register(new ChargeHud());
ClientRegistry.registerKeyBinding(KeyBindings.config);
MinecraftForge.EVENT_BUS.register(new ClientSideIDSUManager());
}
}

View file

@ -0,0 +1,19 @@
package techreborn.tiles.idsu;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.event.world.WorldEvent;
@SideOnly(Side.CLIENT)
public class ClientSideIDSUManager {
public static IDSUManager CLIENT = new IDSUManager();
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event){
CLIENT = new IDSUManager();
}
}

View file

@ -1,14 +1,17 @@
package techreborn.tiles.iesu;
package techreborn.tiles.idsu;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraftforge.event.world.WorldEvent;
import techreborn.util.LogHelper;
import techreborn.packets.PacketSendIDSUManager;
import java.io.BufferedReader;
import java.io.File;
@ -16,9 +19,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@ -29,6 +30,7 @@ public class IDSUManager {
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
//@SideOnly(Side.SERVER)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldSave(WorldEvent.Save event){
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
@ -38,6 +40,7 @@ public class IDSUManager {
}
}
//@SideOnly(Side.SERVER)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event){
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
@ -51,6 +54,7 @@ public class IDSUManager {
}
}
//@SideOnly(Side.SERVER)
@SubscribeEvent(priority = EventPriority.LOWEST)
public void worldClosed(WorldEvent.Unload event){
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
@ -76,6 +80,48 @@ public class IDSUManager {
}
public IDSUWorldSaveData getWorldDataFormWorld(World world){
//System.out.println(world);
if(worldData.containsKey(world)){
return worldData.get(world);
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world ,worldSaveData);
worldSaveData.load();
return worldSaveData;
}
}
//@SideOnly(Side.SERVER)
public PacketSendIDSUManager getPacket(World world, EntityPlayer player){
Gson gson = new Gson();
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
if(getWorldDataFormWorld(world).idsuValues.isEmpty()){
json = "EMPTY";
}
return new PacketSendIDSUManager(json, player);
}
//@SideOnly(Side.CLIENT)
public void loadFromString(String json, World world){
if(json.equals("EMPTY")){
return;
}
IDSUWorldSaveData worldSaveData;
if(worldData.containsKey(world)){
worldSaveData = worldData.get(world);
} else {
worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world ,worldSaveData);
}
Gson gson = new Gson();
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() { }.getType();
worldSaveData.idsuValues.clear();
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
//System.out.println(world);
}
public class IDSUWorldSaveData {
public TreeMap<Integer, IDSUValueSaveData> idsuValues = new TreeMap<Integer, IDSUValueSaveData>();
@ -105,6 +151,7 @@ public class IDSUManager {
}
}
//@SideOnly(Side.SERVER)
public void load(){
if(!file.exists()){
return;
@ -120,6 +167,7 @@ public class IDSUManager {
}
}
//@SideOnly(Side.SERVER)
public void save(){
if(idsuValues.isEmpty()){
return;

View file

@ -0,0 +1,23 @@
package techreborn.tiles.idsu;
import net.minecraft.entity.player.EntityPlayer;
import techreborn.packets.PacketHandler;
import techreborn.tiles.TileMachineBase;
public class TileIDSU extends TileMachineBase {
public int channelID = 0;
public void handleGuiInputFromClient(int buttonID, int channel, EntityPlayer player, String name) {
if(buttonID == 4){
channelID = channel;
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel);//Do this to init the save data :)
if(name != "BLANK!!!"){
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel).name = name;
}
if(worldObj.isRemote){
PacketHandler.sendPacketToPlayer(IDSUManager.INSTANCE.getPacket(worldObj, player), player);
}
}
}
}

View file

@ -1,7 +0,0 @@
package techreborn.tiles.iesu;
import techreborn.tiles.TileMachineBase;
public class TileIDSU extends TileMachineBase {
}