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;
|
||||
|
||||
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.idsu.TileIDSU;
|
||||
|
||||
|
@ -12,74 +15,76 @@ public class ContainerIDSU extends TechRebornContainer {
|
|||
TileIDSU tile;
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player)
|
||||
{
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int euOut;
|
||||
public int storedEu;
|
||||
public int euChange;
|
||||
public int channel;
|
||||
|
||||
public ContainerIDSU(TileIDSU tileIDSU,
|
||||
EntityPlayer player)
|
||||
{
|
||||
EntityPlayer player) {
|
||||
tile = tileIDSU;
|
||||
this.player = player;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 9; ++j)
|
||||
{
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
|
||||
+ 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,
|
||||
142 + 30));
|
||||
}
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// public void detectAndSendChanges() {
|
||||
// super.detectAndSendChanges();
|
||||
// for (int i = 0; i < this.crafters.size(); i++) {
|
||||
// ICrafting icrafting = (ICrafting)this.crafters.get(i);
|
||||
// if(this.euOut != tile.output){
|
||||
// icrafting.sendProgressBarUpdate(this, 0, tile.output);
|
||||
// }
|
||||
// if(this.storedEu != tile.energy){
|
||||
// icrafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
|
||||
// }
|
||||
// if(this.euChange != tile.getEuChange() && tile.getEuChange() != -1){
|
||||
// icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void addCraftingToCrafters(ICrafting crafting) {
|
||||
// super.addCraftingToCrafters(crafting);
|
||||
// crafting.sendProgressBarUpdate(this, 0, tile.output);
|
||||
// crafting.sendProgressBarUpdate(this, 1, (int) tile.energy);
|
||||
// crafting.sendProgressBarUpdate(this, 2 , (int) tile.getEuChange());
|
||||
// }
|
||||
//
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// @Override
|
||||
// public void updateProgressBar(int id, int value) {
|
||||
// if(id == 0){
|
||||
// this.euOut = value;
|
||||
// } else if(id == 1){
|
||||
// this.storedEu = value;
|
||||
// } else if(id == 2){
|
||||
// this.euChange = value;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
for (int i = 0; i < this.crafters.size(); i++) {
|
||||
ICrafting icrafting = (ICrafting) this.crafters.get(i);
|
||||
if (this.euOut != tile.output) {
|
||||
icrafting.sendProgressBarUpdate(this, 0, tile.output);
|
||||
}
|
||||
if (this.storedEu != (int) tile.getEnergy()) {
|
||||
icrafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
|
||||
}
|
||||
if (this.euChange != tile.getEuChange() && tile.getEuChange() != -1) {
|
||||
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);
|
||||
crafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
|
||||
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
|
||||
crafting.sendProgressBarUpdate(this, 3, tile.channelID);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void updateProgressBar(int id, int value) {
|
||||
if (id == 0) {
|
||||
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.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.client.container.ContainerIDSU;
|
||||
import techreborn.client.gui.componets.TabIDConfig;
|
||||
import techreborn.cofhLib.gui.GuiBase;
|
||||
import techreborn.cofhLib.gui.element.ElementListBox;
|
||||
import techreborn.cofhLib.gui.element.ElementTextField;
|
||||
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.PacketIdsu;
|
||||
import techreborn.tiles.idsu.ClientSideIDSUManager;
|
||||
import techreborn.tiles.idsu.IDSUManager;
|
||||
import techreborn.tiles.idsu.TileIDSU;
|
||||
import techreborn.util.LogHelper;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiIDSU extends GuiBase {
|
||||
|
||||
|
||||
|
@ -36,15 +27,13 @@ public class GuiIDSU extends GuiBase {
|
|||
ElementTextField nameFeild;
|
||||
|
||||
|
||||
|
||||
public GuiIDSU(EntityPlayer player,
|
||||
TileIDSU tileIDSU)
|
||||
{
|
||||
TileIDSU tileIDSU) {
|
||||
super(new ContainerIDSU(tileIDSU, player));
|
||||
this.xSize = 156;
|
||||
this.ySize = 200;
|
||||
idsu = tileIDSU;
|
||||
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
|
||||
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
|
||||
texture = new ResourceLocation(
|
||||
"techreborn", "textures/gui/aesu.png");
|
||||
drawTitle = false;
|
||||
|
@ -60,17 +49,18 @@ public class GuiIDSU extends GuiBase {
|
|||
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(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.gui = this;
|
||||
listBox.setSelectedIndex(containerIDSU.channel);
|
||||
|
||||
// listBox.borderColor = new GuiColor(120, 120, 120, 0).getColor();
|
||||
// listBox.backgroundColor = new GuiColor(0, 0, 0, 32).getColor();
|
||||
addElement(listBox);
|
||||
|
||||
idFeild = new ElementTextFieldLimited(this, 10, 10, 30, 10, (short) 4);
|
||||
idFeild = new ElementTextFieldLimited(this, 10, 10, 30, 10, (short) 4);
|
||||
idFeild.setFilter("1234567890", false);
|
||||
|
||||
addElement(idFeild);
|
||||
|
@ -87,7 +77,7 @@ public class GuiIDSU extends GuiBase {
|
|||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
super.actionPerformed(button);
|
||||
if(isInteger(idFeild.getText())){
|
||||
if (isInteger(idFeild.getText())) {
|
||||
PacketHandler.sendPacketToServer(new PacketIdsu(button.id, idsu, Integer.parseInt(idFeild.getText()), nameFeild.getText()));
|
||||
} else {
|
||||
LogHelper.info("There was an issue in the gui!, Please report this to the TechReborn Devs");
|
||||
|
@ -96,17 +86,17 @@ public class GuiIDSU extends GuiBase {
|
|||
}
|
||||
|
||||
public static boolean isInteger(String s) {
|
||||
return isInteger(s,10);
|
||||
return isInteger(s, 10);
|
||||
}
|
||||
|
||||
public static boolean isInteger(String s, int radix) {
|
||||
if(s.isEmpty()) return false;
|
||||
for(int i = 0; i < s.length(); i++) {
|
||||
if(i == 0 && s.charAt(i) == '-') {
|
||||
if(s.length() == 1) return false;
|
||||
if (s.isEmpty()) return false;
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (i == 0 && s.charAt(i) == '-') {
|
||||
if (s.length() == 1) return false;
|
||||
else continue;
|
||||
}
|
||||
if(Character.digit(s.charAt(i),radix) < 0) return false;
|
||||
if (Character.digit(s.charAt(i), radix) < 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,10 +29,10 @@ public class TechRebornDevCommand extends CommandBase {
|
|||
@Override
|
||||
public void processCommand(ICommandSender sender, String[] args) {
|
||||
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])) {
|
||||
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("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])){
|
||||
|
|
|
@ -33,7 +33,7 @@ public class PacketSendIDSUManager extends SimplePacket {
|
|||
@Override
|
||||
public void readData(ByteBuf in) throws IOException {
|
||||
PacketBuffer buffer = new PacketBuffer(in);
|
||||
json = buffer.readStringFromBuffer(99999999);
|
||||
json = buffer.readStringFromBuffer(Integer.MAX_VALUE / 4);
|
||||
player = readPlayer(in);
|
||||
}
|
||||
|
||||
|
@ -44,18 +44,16 @@ public class PacketSendIDSUManager extends SimplePacket {
|
|||
if(player.worldObj != null){
|
||||
GuiIDSU.listBox._elements.clear();
|
||||
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);
|
||||
System.out.println("added " + valueSaveData.name + " - " + id);
|
||||
if(!valueSaveData.name.isEmpty()){
|
||||
GuiIDSU.listBox._elements.add(new ListBoxElementText(valueSaveData.name + " - " + id));
|
||||
} else {
|
||||
GuiIDSU.listBox._elements.add(new ListBoxElementText(id.toString()));
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ClientSideIDSUManager {
|
|||
public static IDSUManager CLIENT = new IDSUManager();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldLoad(WorldEvent.Load event){
|
||||
public void worldLoad(WorldEvent.Load event) {
|
||||
CLIENT = new IDSUManager();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ 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;
|
||||
|
@ -25,40 +23,38 @@ import java.util.TreeMap;
|
|||
|
||||
public class IDSUManager {
|
||||
|
||||
|
||||
public static IDSUManager INSTANCE;
|
||||
|
||||
public static final String savename = "idsu.json";
|
||||
|
||||
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){
|
||||
if(worldData.containsKey(event.world)){
|
||||
public void worldSave(WorldEvent.Save event) {
|
||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.world)) {
|
||||
worldData.get(event.world).save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@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){
|
||||
if(worldData.containsKey(event.world)){
|
||||
public void worldLoad(WorldEvent.Load event) {
|
||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.world)) {
|
||||
worldData.get(event.world).load();
|
||||
} else {
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(event.world);
|
||||
worldData.put(event.world ,worldSaveData);
|
||||
worldData.put(event.world, worldSaveData);
|
||||
worldSaveData.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@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){
|
||||
if(worldData.containsKey(event.world)){
|
||||
public void worldClosed(WorldEvent.Unload event) {
|
||||
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
|
||||
if (worldData.containsKey(event.world)) {
|
||||
worldData.get(event.world).save();
|
||||
}
|
||||
}
|
||||
|
@ -66,59 +62,54 @@ public class IDSUManager {
|
|||
worldData.clear();
|
||||
}
|
||||
|
||||
public IDSUValueSaveData getSaveDataForWorld(World world, int channel){
|
||||
if(worldData.containsKey(world)){
|
||||
public IDSUValueSaveData getSaveDataForWorld(World world, int channel) {
|
||||
if (worldData.containsKey(world)) {
|
||||
return worldData.get(world).getSaves(channel);
|
||||
} else {
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world ,worldSaveData);
|
||||
worldData.put(world, worldSaveData);
|
||||
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){
|
||||
//System.out.println(world);
|
||||
if(worldData.containsKey(world)){
|
||||
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
|
||||
if (worldData.containsKey(world)) {
|
||||
return worldData.get(world);
|
||||
} else {
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world ,worldSaveData);
|
||||
worldData.put(world, worldSaveData);
|
||||
worldSaveData.load();
|
||||
return worldSaveData;
|
||||
return worldSaveData;
|
||||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public PacketSendIDSUManager getPacket(World world, EntityPlayer player){
|
||||
public PacketSendIDSUManager getPacket(World world, EntityPlayer player) {
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
|
||||
if(getWorldDataFormWorld(world).idsuValues.isEmpty()){
|
||||
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")){
|
||||
public void loadFromString(String json, World world) {
|
||||
if (json.equals("EMPTY")) {
|
||||
return;
|
||||
}
|
||||
IDSUWorldSaveData worldSaveData;
|
||||
if(worldData.containsKey(world)){
|
||||
if (worldData.containsKey(world)) {
|
||||
worldSaveData = worldData.get(world);
|
||||
} else {
|
||||
worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world ,worldSaveData);
|
||||
worldData.put(world, worldSaveData);
|
||||
}
|
||||
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 = gson.fromJson(json, typeOfHashMap);
|
||||
//System.out.println(world);
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,11 +129,11 @@ public class IDSUManager {
|
|||
this.world = world;
|
||||
this.saveHandler = world.getSaveHandler();
|
||||
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
|
||||
file = new File(folder,"idsu.json");
|
||||
file = new File(folder, savename);
|
||||
}
|
||||
|
||||
public IDSUValueSaveData getSaves(int i){
|
||||
if(idsuValues.containsKey(i)){
|
||||
public IDSUValueSaveData getSaves(int i) {
|
||||
if (idsuValues.containsKey(i)) {
|
||||
return idsuValues.get(i);
|
||||
} else {
|
||||
IDSUValueSaveData data = new IDSUValueSaveData();
|
||||
|
@ -151,15 +142,15 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public void load(){
|
||||
if(!file.exists()){
|
||||
public void load() {
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
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 = gson.fromJson(reader, typeOfHashMap);
|
||||
} catch (Exception e) {
|
||||
|
@ -167,13 +158,12 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public void save(){
|
||||
if(idsuValues.isEmpty()){
|
||||
public void save() {
|
||||
if (idsuValues.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if(!file.exists()){
|
||||
if(!folder.exists()){
|
||||
if (!file.exists()) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package techreborn.tiles.idsu;
|
||||
|
||||
import ic2.api.energy.EnergyNet;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
@ -9,10 +8,6 @@ import ic2.api.network.INetworkClientTileEntityEventListener;
|
|||
import ic2.api.tile.IEnergyStorage;
|
||||
import ic2.core.IC2;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -20,6 +15,8 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.packets.PacketHandler;
|
||||
|
||||
public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySource, INetworkClientTileEntityEventListener, IEnergyStorage {
|
||||
|
@ -27,21 +24,21 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
public int channelID = 0;
|
||||
|
||||
public void handleGuiInputFromClient(int buttonID, int channel, EntityPlayer player, String name) {
|
||||
if(buttonID == 4){
|
||||
if (buttonID == 4) {
|
||||
channelID = channel;
|
||||
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel).name = name;
|
||||
IDSUManager.INSTANCE.getWorldDataFormWorld(worldObj).save();
|
||||
if(worldObj.isRemote){
|
||||
if (worldObj.isRemote) {
|
||||
PacketHandler.sendPacketToPlayer(IDSUManager.INSTANCE.getPacket(worldObj, player), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double getEnergy(){
|
||||
public double getEnergy() {
|
||||
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channelID).storedPower;
|
||||
}
|
||||
|
||||
public void setEnergy(double energy){
|
||||
public void setEnergy(double energy) {
|
||||
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channelID).storedPower = energy;
|
||||
}
|
||||
|
||||
|
@ -54,6 +51,9 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
private boolean isEmittingRedstone = false;
|
||||
private int redstoneUpdateInhibit = 5;
|
||||
public boolean addedToEnergyNet = false;
|
||||
private double euLastTick = 0;
|
||||
private double euChange;
|
||||
private int ticks;
|
||||
|
||||
public TileIDSU(int tier1, int output1, int maxStorage1) {
|
||||
this.tier = tier1;
|
||||
|
@ -62,8 +62,8 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public float getChargeLevel() {
|
||||
float ret = (float)this.getEnergy() / (float)this.maxStorage;
|
||||
if(ret > 1.0F) {
|
||||
float ret = (float) this.getEnergy() / (float) this.maxStorage;
|
||||
if (ret > 1.0F) {
|
||||
ret = 1.0F;
|
||||
}
|
||||
|
||||
|
@ -72,19 +72,19 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
|
||||
public void readFromNBT(NBTTagCompound 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.channelID = nbttagcompound.getInteger("channel");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
nbttagcompound.setDouble("energy", this.getEnergy());
|
||||
nbttagcompound.setByte("redstoneMode", this.redstoneMode);
|
||||
nbttagcompound.setInteger("channel", this.channelID);
|
||||
}
|
||||
|
||||
public void onLoaded() {
|
||||
super.onLoaded();
|
||||
if(IC2.platform.isSimulating()) {
|
||||
if (IC2.platform.isSimulating()) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
this.addedToEnergyNet = true;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public void onUnloaded() {
|
||||
if(IC2.platform.isSimulating() && this.addedToEnergyNet) {
|
||||
if (IC2.platform.isSimulating() && this.addedToEnergyNet) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
this.addedToEnergyNet = false;
|
||||
}
|
||||
|
@ -106,20 +106,35 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
|
||||
public void 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;
|
||||
|
||||
if(this.redstoneMode == 5 || this.redstoneMode == 6) {
|
||||
if (this.redstoneMode == 5 || this.redstoneMode == 6) {
|
||||
this.hasRedstone = this.worldObj.isBlockIndirectlyGettingPowered(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
|
||||
boolean shouldEmitRedstone1 = this.shouldEmitRedstone();
|
||||
if(shouldEmitRedstone1 != this.isEmittingRedstone) {
|
||||
if (shouldEmitRedstone1 != this.isEmittingRedstone) {
|
||||
this.isEmittingRedstone = shouldEmitRedstone1;
|
||||
this.setActive(this.isEmittingRedstone);
|
||||
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord));
|
||||
}
|
||||
|
||||
if(needsInvUpdate) {
|
||||
if (needsInvUpdate) {
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
|
@ -138,7 +153,7 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public double getOfferedEnergy() {
|
||||
return this.getEnergy() >= (double)this.output && (this.redstoneMode != 5 || !this.hasRedstone) && (this.redstoneMode != 6 || !this.hasRedstone || this.getEnergy() >= (double)this.maxStorage)?Math.min(this.getEnergy(), (double)this.output):0.0D;
|
||||
return this.getEnergy() >= (double) this.output && (this.redstoneMode != 5 || !this.hasRedstone) && (this.redstoneMode != 6 || !this.hasRedstone || this.getEnergy() >= (double) this.maxStorage) ? Math.min(this.getEnergy(), (double) this.output) : 0.0D;
|
||||
}
|
||||
|
||||
public void drawEnergy(double amount) {
|
||||
|
@ -146,11 +161,11 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public double getDemandedEnergy() {
|
||||
return (double)this.maxStorage - this.getEnergy();
|
||||
return (double) this.maxStorage - this.getEnergy();
|
||||
}
|
||||
|
||||
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
|
||||
if(this.getEnergy() >= (double)this.maxStorage) {
|
||||
if (this.getEnergy() >= (double) this.maxStorage) {
|
||||
return amount;
|
||||
} else {
|
||||
setEnergy(this.getEnergy() + amount);
|
||||
|
@ -167,7 +182,6 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
|
||||
|
||||
public void onGuiClosed(EntityPlayer entityPlayer) {
|
||||
}
|
||||
|
||||
|
@ -176,12 +190,12 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public void setFacing(short facing) {
|
||||
if(this.addedToEnergyNet) {
|
||||
if (this.addedToEnergyNet) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
}
|
||||
|
||||
super.setFacing(facing);
|
||||
if(this.addedToEnergyNet) {
|
||||
if (this.addedToEnergyNet) {
|
||||
this.addedToEnergyNet = false;
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
this.addedToEnergyNet = true;
|
||||
|
@ -191,21 +205,21 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
|
||||
public boolean shouldEmitRedstone() {
|
||||
boolean shouldEmitRedstone = false;
|
||||
switch(this.redstoneMode) {
|
||||
switch (this.redstoneMode) {
|
||||
case 1:
|
||||
shouldEmitRedstone = this.getEnergy() >= (double)(this.maxStorage - this.output * 20);
|
||||
shouldEmitRedstone = this.getEnergy() >= (double) (this.maxStorage - this.output * 20);
|
||||
break;
|
||||
case 2:
|
||||
shouldEmitRedstone = this.getEnergy() > (double)this.output && this.getEnergy() < (double)this.maxStorage;
|
||||
shouldEmitRedstone = this.getEnergy() > (double) this.output && this.getEnergy() < (double) this.maxStorage;
|
||||
break;
|
||||
case 3:
|
||||
shouldEmitRedstone = this.getEnergy() > (double)this.output && this.getEnergy() < (double)this.maxStorage || this.getEnergy() < (double)this.output;
|
||||
shouldEmitRedstone = this.getEnergy() > (double) this.output && this.getEnergy() < (double) this.maxStorage || this.getEnergy() < (double) this.output;
|
||||
break;
|
||||
case 4:
|
||||
shouldEmitRedstone = this.getEnergy() < (double)this.output;
|
||||
shouldEmitRedstone = this.getEnergy() < (double) this.output;
|
||||
}
|
||||
|
||||
if(this.isEmittingRedstone != shouldEmitRedstone && this.redstoneUpdateInhibit != 0) {
|
||||
if (this.isEmittingRedstone != shouldEmitRedstone && this.redstoneUpdateInhibit != 0) {
|
||||
--this.redstoneUpdateInhibit;
|
||||
return this.isEmittingRedstone;
|
||||
} else {
|
||||
|
@ -216,7 +230,7 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
|
||||
public void onNetworkEvent(EntityPlayer player, int event) {
|
||||
++this.redstoneMode;
|
||||
if(this.redstoneMode >= redstoneModes) {
|
||||
if (this.redstoneMode >= redstoneModes) {
|
||||
this.redstoneMode = 0;
|
||||
}
|
||||
|
||||
|
@ -224,22 +238,20 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public String getredstoneMode() {
|
||||
return this.redstoneMode <= 6 && this.redstoneMode >= 0? StatCollector.translateToLocal("ic2.EUStorage.gui.mod.redstone" + this.redstoneMode):"";
|
||||
return this.redstoneMode <= 6 && this.redstoneMode >= 0 ? StatCollector.translateToLocal("ic2.EUStorage.gui.mod.redstone" + this.redstoneMode) : "";
|
||||
}
|
||||
|
||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
||||
ItemStack ret = super.getWrenchDrop(entityPlayer);
|
||||
float energyRetainedInStorageBlockDrops = ConfigUtil.getFloat(MainConfig.get(), "balance/energyRetainedInStorageBlockDrops");
|
||||
if(energyRetainedInStorageBlockDrops > 0.0F) {
|
||||
NBTTagCompound nbttagcompound = StackUtil.getOrCreateNbtData(ret);
|
||||
nbttagcompound.setDouble("energy", this.getEnergy() * (double)energyRetainedInStorageBlockDrops);
|
||||
}
|
||||
|
||||
return ret;
|
||||
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
|
||||
writeToNBT(tileEntity);
|
||||
dropStack.setTagCompound(new NBTTagCompound());
|
||||
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
|
||||
return dropStack;
|
||||
}
|
||||
|
||||
public int getStored() {
|
||||
return (int)this.getEnergy();
|
||||
return (int) this.getEnergy();
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
|
@ -251,7 +263,7 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
}
|
||||
|
||||
public double getOutputEnergyUnitsPerTick() {
|
||||
return (double)this.output;
|
||||
return (double) this.output;
|
||||
}
|
||||
|
||||
public void setStored(int energy1) {
|
||||
|
@ -266,4 +278,11 @@ public class TileIDSU extends TileEntityBlock implements IEnergySink, IEnergySou
|
|||
public boolean isTeleporterCompatible(ForgeDirection side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public double getEuChange() {
|
||||
if (euChange == -1) {
|
||||
return -1;
|
||||
}
|
||||
return (euChange / ticks);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue