Some clean up of some code
This commit is contained in:
parent
9e4151f5fa
commit
43da219936
7 changed files with 171 additions and 169 deletions
|
@ -1,6 +1,9 @@
|
||||||
package techreborn.client.container;
|
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.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.ICrafting;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import techreborn.tiles.idsu.TileIDSU;
|
import techreborn.tiles.idsu.TileIDSU;
|
||||||
|
|
||||||
|
@ -12,74 +15,76 @@ public class ContainerIDSU extends TechRebornContainer {
|
||||||
TileIDSU tile;
|
TileIDSU tile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer player)
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int euOut;
|
public int euOut;
|
||||||
public int storedEu;
|
public int storedEu;
|
||||||
public int euChange;
|
public int euChange;
|
||||||
|
public int channel;
|
||||||
|
|
||||||
public ContainerIDSU(TileIDSU tileIDSU,
|
public ContainerIDSU(TileIDSU tileIDSU,
|
||||||
EntityPlayer player)
|
EntityPlayer player) {
|
||||||
{
|
|
||||||
tile = tileIDSU;
|
tile = tileIDSU;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < 3; ++i)
|
for (i = 0; i < 3; ++i) {
|
||||||
{
|
for (int j = 0; j < 9; ++j) {
|
||||||
for (int j = 0; j < 9; ++j)
|
|
||||||
{
|
|
||||||
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
|
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
|
||||||
+ 9, 7 + j * 16, 84 + i * 18 + 30));
|
+ 9, 7 + j * 16, 84 + i * 18 + 30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 9; ++i)
|
for (i = 0; i < 9; ++i) {
|
||||||
{
|
|
||||||
this.addSlotToContainer(new Slot(player.inventory, i, 7 + i * 16,
|
this.addSlotToContainer(new Slot(player.inventory, i, 7 + i * 16,
|
||||||
142 + 30));
|
142 + 30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void detectAndSendChanges() {
|
public void detectAndSendChanges() {
|
||||||
// super.detectAndSendChanges();
|
super.detectAndSendChanges();
|
||||||
// for (int i = 0; i < this.crafters.size(); i++) {
|
for (int i = 0; i < this.crafters.size(); i++) {
|
||||||
// ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
ICrafting icrafting = (ICrafting) this.crafters.get(i);
|
||||||
// if(this.euOut != tile.output){
|
if (this.euOut != tile.output) {
|
||||||
// icrafting.sendProgressBarUpdate(this, 0, tile.output);
|
icrafting.sendProgressBarUpdate(this, 0, tile.output);
|
||||||
// }
|
}
|
||||||
// if(this.storedEu != tile.energy){
|
if (this.storedEu != (int) tile.getEnergy()) {
|
||||||
// icrafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
|
icrafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
|
||||||
// }
|
}
|
||||||
// if(this.euChange != tile.getEuChange() && tile.getEuChange() != -1){
|
if (this.euChange != tile.getEuChange() && tile.getEuChange() != -1) {
|
||||||
// icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
|
icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
|
||||||
// }
|
}
|
||||||
// }
|
if (this.channel != tile.channelID) {
|
||||||
// }
|
icrafting.sendProgressBarUpdate(this, 3, tile.channelID);
|
||||||
//
|
}
|
||||||
// @Override
|
}
|
||||||
// public void addCraftingToCrafters(ICrafting crafting) {
|
}
|
||||||
// super.addCraftingToCrafters(crafting);
|
|
||||||
// crafting.sendProgressBarUpdate(this, 0, tile.output);
|
@Override
|
||||||
// crafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
|
public void addCraftingToCrafters(ICrafting crafting) {
|
||||||
// crafting.sendProgressBarUpdate(this, 2 , (int) tile.getEuChange());
|
super.addCraftingToCrafters(crafting);
|
||||||
// }
|
crafting.sendProgressBarUpdate(this, 0, tile.output);
|
||||||
//
|
crafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
|
||||||
// @SideOnly(Side.CLIENT)
|
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
|
||||||
// @Override
|
crafting.sendProgressBarUpdate(this, 3, tile.channelID);
|
||||||
// public void updateProgressBar(int id, int value) {
|
}
|
||||||
// if(id == 0){
|
|
||||||
// this.euOut = value;
|
@SideOnly(Side.CLIENT)
|
||||||
// } else if(id == 1){
|
@Override
|
||||||
// this.storedEu = value;
|
public void updateProgressBar(int id, int value) {
|
||||||
// } else if(id == 2){
|
if (id == 0) {
|
||||||
// this.euChange = value;
|
this.euOut = value;
|
||||||
// }
|
} else if (id == 1) {
|
||||||
// }
|
this.storedEu = value;
|
||||||
|
} else if (id == 2) {
|
||||||
|
this.euChange = value;
|
||||||
|
} else if (id == 3) {
|
||||||
|
this.channel = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,25 +4,16 @@ import net.minecraft.client.gui.GuiButton;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import techreborn.client.container.ContainerIDSU;
|
import techreborn.client.container.ContainerIDSU;
|
||||||
import techreborn.client.gui.componets.TabIDConfig;
|
|
||||||
import techreborn.cofhLib.gui.GuiBase;
|
import techreborn.cofhLib.gui.GuiBase;
|
||||||
import techreborn.cofhLib.gui.element.ElementListBox;
|
import techreborn.cofhLib.gui.element.ElementListBox;
|
||||||
import techreborn.cofhLib.gui.element.ElementTextField;
|
import techreborn.cofhLib.gui.element.ElementTextField;
|
||||||
import techreborn.cofhLib.gui.element.ElementTextFieldLimited;
|
import techreborn.cofhLib.gui.element.ElementTextFieldLimited;
|
||||||
import techreborn.cofhLib.gui.element.listbox.IListBoxElement;
|
|
||||||
import techreborn.cofhLib.gui.element.listbox.ListBoxElementText;
|
|
||||||
import techreborn.packets.PacketHandler;
|
import techreborn.packets.PacketHandler;
|
||||||
import techreborn.packets.PacketIdsu;
|
import techreborn.packets.PacketIdsu;
|
||||||
import techreborn.tiles.idsu.ClientSideIDSUManager;
|
|
||||||
import techreborn.tiles.idsu.IDSUManager;
|
|
||||||
import techreborn.tiles.idsu.TileIDSU;
|
import techreborn.tiles.idsu.TileIDSU;
|
||||||
import techreborn.util.LogHelper;
|
import techreborn.util.LogHelper;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class GuiIDSU extends GuiBase {
|
public class GuiIDSU extends GuiBase {
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,10 +27,8 @@ public class GuiIDSU extends GuiBase {
|
||||||
ElementTextField nameFeild;
|
ElementTextField nameFeild;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public GuiIDSU(EntityPlayer player,
|
public GuiIDSU(EntityPlayer player,
|
||||||
TileIDSU tileIDSU)
|
TileIDSU tileIDSU) {
|
||||||
{
|
|
||||||
super(new ContainerIDSU(tileIDSU, player));
|
super(new ContainerIDSU(tileIDSU, player));
|
||||||
this.xSize = 156;
|
this.xSize = 156;
|
||||||
this.ySize = 200;
|
this.ySize = 200;
|
||||||
|
@ -65,6 +54,7 @@ public class GuiIDSU extends GuiBase {
|
||||||
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
|
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
|
||||||
|
|
||||||
listBox.gui = this;
|
listBox.gui = this;
|
||||||
|
listBox.setSelectedIndex(containerIDSU.channel);
|
||||||
|
|
||||||
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
|
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
|
||||||
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
|
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class TechRebornDevCommand extends CommandBase {
|
||||||
@Override
|
@Override
|
||||||
public void processCommand(ICommandSender sender, String[] args) {
|
public void processCommand(ICommandSender sender, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.addChatMessage(new ChatComponentText("You need to use arguments"));
|
sender.addChatMessage(new ChatComponentText("You need to use arguments, see /trdev help"));
|
||||||
} else if ("help".equals(args[0])) {
|
} else if ("help".equals(args[0])) {
|
||||||
sender.addChatMessage(new ChatComponentText("recipes - Shows size of the recipe array"));
|
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"));
|
sender.addChatMessage(new ChatComponentText("idsu - Resyncs the idsu server instance to the senders client"));
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class PacketSendIDSUManager extends SimplePacket {
|
||||||
@Override
|
@Override
|
||||||
public void readData(ByteBuf in) throws IOException {
|
public void readData(ByteBuf in) throws IOException {
|
||||||
PacketBuffer buffer = new PacketBuffer(in);
|
PacketBuffer buffer = new PacketBuffer(in);
|
||||||
json = buffer.readStringFromBuffer(99999999);
|
json = buffer.readStringFromBuffer(Integer.MAX_VALUE / 4);
|
||||||
player = readPlayer(in);
|
player = readPlayer(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,18 +44,16 @@ public class PacketSendIDSUManager extends SimplePacket {
|
||||||
if(player.worldObj != null){
|
if(player.worldObj != null){
|
||||||
GuiIDSU.listBox._elements.clear();
|
GuiIDSU.listBox._elements.clear();
|
||||||
for(World world : ClientSideIDSUManager.CLIENT.worldData.keySet()){
|
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);
|
IDSUManager.IDSUWorldSaveData saveData = ClientSideIDSUManager.CLIENT.getWorldDataFormWorld(world);
|
||||||
for(Integer id : saveData.idsuValues.keySet()){
|
for(Integer id : saveData.idsuValues.keySet()){
|
||||||
IDSUManager.IDSUValueSaveData valueSaveData = saveData.idsuValues.get(id);
|
IDSUManager.IDSUValueSaveData valueSaveData = saveData.idsuValues.get(id);
|
||||||
|
System.out.println("added " + valueSaveData.name + " - " + id);
|
||||||
if(!valueSaveData.name.isEmpty()){
|
if(!valueSaveData.name.isEmpty()){
|
||||||
GuiIDSU.listBox._elements.add(new ListBoxElementText(valueSaveData.name + " - " + id));
|
GuiIDSU.listBox._elements.add(new ListBoxElementText(valueSaveData.name + " - " + id));
|
||||||
} else {
|
} else {
|
||||||
GuiIDSU.listBox._elements.add(new ListBoxElementText(id.toString()));
|
GuiIDSU.listBox._elements.add(new ListBoxElementText(id.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
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.entity.player.EntityPlayer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.storage.ISaveHandler;
|
import net.minecraft.world.storage.ISaveHandler;
|
||||||
|
@ -25,12 +23,12 @@ import java.util.TreeMap;
|
||||||
|
|
||||||
public class IDSUManager {
|
public class IDSUManager {
|
||||||
|
|
||||||
|
|
||||||
public static IDSUManager INSTANCE;
|
public static IDSUManager INSTANCE;
|
||||||
|
|
||||||
|
public static final String savename = "idsu.json";
|
||||||
|
|
||||||
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
|
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
public void worldSave(WorldEvent.Save event) {
|
public void worldSave(WorldEvent.Save event) {
|
||||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||||
|
@ -40,7 +38,6 @@ public class IDSUManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
public void worldLoad(WorldEvent.Load event) {
|
public void worldLoad(WorldEvent.Load event) {
|
||||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||||
|
@ -54,7 +51,6 @@ public class IDSUManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||||
public void worldClosed(WorldEvent.Unload event) {
|
public void worldClosed(WorldEvent.Unload event) {
|
||||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||||
|
@ -75,13 +71,10 @@ public class IDSUManager {
|
||||||
worldSaveData.load();
|
worldSaveData.load();
|
||||||
return worldSaveData.getSaves(channel);
|
return worldSaveData.getSaves(channel);
|
||||||
}
|
}
|
||||||
//LogHelper.fatal("FAILED TO GET SAVEDATA!!! This should NEVER have been called, report to TechReborn DEV!");
|
|
||||||
//return new IDSUValueSaveData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
|
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
|
||||||
//System.out.println(world);
|
|
||||||
if (worldData.containsKey(world)) {
|
if (worldData.containsKey(world)) {
|
||||||
return worldData.get(world);
|
return worldData.get(world);
|
||||||
} else {
|
} else {
|
||||||
|
@ -92,7 +85,6 @@ public class IDSUManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
public PacketSendIDSUManager getPacket(World world, EntityPlayer player) {
|
public PacketSendIDSUManager getPacket(World world, EntityPlayer player) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
|
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
|
||||||
|
@ -102,7 +94,6 @@ public class IDSUManager {
|
||||||
return new PacketSendIDSUManager(json, player);
|
return new PacketSendIDSUManager(json, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.CLIENT)
|
|
||||||
public void loadFromString(String json, World world) {
|
public void loadFromString(String json, World world) {
|
||||||
if (json.equals("EMPTY")) {
|
if (json.equals("EMPTY")) {
|
||||||
return;
|
return;
|
||||||
|
@ -115,10 +106,10 @@ public class IDSUManager {
|
||||||
worldData.put(world, worldSaveData);
|
worldData.put(world, worldSaveData);
|
||||||
}
|
}
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() { }.getType();
|
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() {
|
||||||
|
}.getType();
|
||||||
worldSaveData.idsuValues.clear();
|
worldSaveData.idsuValues.clear();
|
||||||
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
|
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
|
||||||
//System.out.println(world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +129,7 @@ public class IDSUManager {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.saveHandler = world.getSaveHandler();
|
this.saveHandler = world.getSaveHandler();
|
||||||
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
|
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
|
||||||
file = new File(folder,"idsu.json");
|
file = new File(folder, savename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDSUValueSaveData getSaves(int i) {
|
public IDSUValueSaveData getSaves(int i) {
|
||||||
|
@ -151,7 +142,6 @@ public class IDSUManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
public void load() {
|
public void load() {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
|
@ -159,7 +149,8 @@ public class IDSUManager {
|
||||||
try {
|
try {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() { }.getType();
|
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() {
|
||||||
|
}.getType();
|
||||||
idsuValues.clear();
|
idsuValues.clear();
|
||||||
idsuValues = gson.fromJson(reader, typeOfHashMap);
|
idsuValues = gson.fromJson(reader, typeOfHashMap);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -167,7 +158,6 @@ public class IDSUManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//@SideOnly(Side.SERVER)
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (idsuValues.isEmpty()) {
|
if (idsuValues.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package techreborn.tiles.idsu;
|
package techreborn.tiles.idsu;
|
||||||
|
|
||||||
import ic2.api.energy.EnergyNet;
|
|
||||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||||
import ic2.api.energy.tile.IEnergySink;
|
import ic2.api.energy.tile.IEnergySink;
|
||||||
|
@ -9,10 +8,6 @@ import ic2.api.network.INetworkClientTileEntityEventListener;
|
||||||
import ic2.api.tile.IEnergyStorage;
|
import ic2.api.tile.IEnergyStorage;
|
||||||
import ic2.core.IC2;
|
import ic2.core.IC2;
|
||||||
import ic2.core.block.TileEntityBlock;
|
import ic2.core.block.TileEntityBlock;
|
||||||
import ic2.core.init.MainConfig;
|
|
||||||
import ic2.core.util.ConfigUtil;
|
|
||||||
import ic2.core.util.StackUtil;
|
|
||||||
import ic2.core.util.Util;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -20,6 +15,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
import techreborn.config.ConfigTechReborn;
|
||||||
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.packets.PacketHandler;
|
import techreborn.packets.PacketHandler;
|
||||||
|
|
||||||
public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySource, INetworkClientTileEntityEventListener, IEnergyStorage {
|
public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySource, INetworkClientTileEntityEventListener, IEnergyStorage {
|
||||||
|
@ -54,6 +51,9 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
private boolean isEmittingRedstone = false;
|
private boolean isEmittingRedstone = false;
|
||||||
private int redstoneUpdateInhibit = 5;
|
private int redstoneUpdateInhibit = 5;
|
||||||
public boolean addedToEnergyNet = false;
|
public boolean addedToEnergyNet = false;
|
||||||
|
private double euLastTick = 0;
|
||||||
|
private double euChange;
|
||||||
|
private int ticks;
|
||||||
|
|
||||||
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
||||||
this.tier = tier1;
|
this.tier = tier1;
|
||||||
|
@ -72,14 +72,14 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.readFromNBT(nbttagcompound);
|
super.readFromNBT(nbttagcompound);
|
||||||
setEnergy(Util.limit(nbttagcompound.getDouble("energy"), 0.0D, (double) this.maxStorage + EnergyNet.instance.getPowerFromTier(this.tier)));
|
|
||||||
this.redstoneMode = nbttagcompound.getByte("redstoneMode");
|
this.redstoneMode = nbttagcompound.getByte("redstoneMode");
|
||||||
|
this.channelID = nbttagcompound.getInteger("channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||||
super.writeToNBT(nbttagcompound);
|
super.writeToNBT(nbttagcompound);
|
||||||
nbttagcompound.setDouble("energy", this.getEnergy());
|
|
||||||
nbttagcompound.setByte("redstoneMode", this.redstoneMode);
|
nbttagcompound.setByte("redstoneMode", this.redstoneMode);
|
||||||
|
nbttagcompound.setInteger("channel", this.channelID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoaded() {
|
public void onLoaded() {
|
||||||
|
@ -106,6 +106,21 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
|
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
|
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
|
||||||
|
euChange = -1;
|
||||||
|
ticks = 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ticks++;
|
||||||
|
euChange += getStored() - euLastTick;
|
||||||
|
if (euLastTick == getStored()) {
|
||||||
|
euChange = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
euLastTick = getStored();
|
||||||
|
|
||||||
boolean needsInvUpdate = false;
|
boolean needsInvUpdate = false;
|
||||||
|
|
||||||
if (this.redstoneMode == 5 || this.redstoneMode == 6) {
|
if (this.redstoneMode == 5 || this.redstoneMode == 6) {
|
||||||
|
@ -167,7 +182,6 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void onGuiClosed(EntityPlayer entityPlayer) {
|
public void onGuiClosed(EntityPlayer entityPlayer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,14 +242,12 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
||||||
ItemStack ret = super.getWrenchDrop(entityPlayer);
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||||
float energyRetainedInStorageBlockDrops = ConfigUtil.getFloat(MainConfig.get(), "balance/energyRetainedInStorageBlockDrops");
|
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
|
||||||
if(energyRetainedInStorageBlockDrops > 0.0F) {
|
writeToNBT(tileEntity);
|
||||||
NBTTagCompound nbttagcompound = StackUtil.getOrCreateNbtData(ret);
|
dropStack.setTagCompound(new NBTTagCompound());
|
||||||
nbttagcompound.setDouble("energy", this.getEnergy() * (double)energyRetainedInStorageBlockDrops);
|
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
|
||||||
}
|
return dropStack;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStored() {
|
public int getStored() {
|
||||||
|
@ -266,4 +278,11 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
||||||
public boolean isTeleporterCompatible(ForgeDirection side) {
|
public boolean isTeleporterCompatible(ForgeDirection side) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getEuChange() {
|
||||||
|
if (euChange == -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (euChange / ticks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue