Improve IDSU

This commit is contained in:
modmuss50 2017-06-13 13:14:02 +01:00
parent c4868a3264
commit 14e30481e5
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
5 changed files with 29 additions and 287 deletions

View file

@ -50,7 +50,7 @@ public enum EGui {
DIGITAL_CHEST(true),
DESTRUCTOPACK(false),
LESU(false),
IDSU(false),
IDSU(true),
CHARGEBENCH(true),
FUSION_CONTROLLER(true),
VACUUM_FREEZER(true),

View file

@ -62,8 +62,6 @@ public class GuiHandler implements IGuiHandler {
return new ContainerDestructoPack(player);
case LESU:
return new ContainerLESU((TileLesu) tile, player);
case IDSU:
return new ContainerIDSU((TileIDSU) tile, player);
default:
break;
}

View file

@ -1,105 +0,0 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IContainerListener;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.client.gui.slots.BaseSlot;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.idsu.TileIDSU;
public class ContainerIDSU extends RebornContainer {
public int euOut;
public int storedEu;
public int euChange;
public int channel;
EntityPlayer player;
TileIDSU tile;
public ContainerIDSU(TileIDSU tileIDSU, EntityPlayer player) {
tile = tileIDSU;
this.player = player;
int i;
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 115 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 173));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); i++) {
IContainerListener IContainerListener = this.listeners.get(i);
if (this.euOut != tile.maxEnergy) {
IContainerListener.sendProgressBarUpdate(this, 0, tile.maxEnergy);
}
if (this.storedEu != (int) tile.getEnergy()) {
IContainerListener.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
}
if (this.euChange != tile.getEuChange() && tile.getEuChange() != -1) {
IContainerListener.sendProgressBarUpdate(this, 2, (int) tile.getEuChange());
}
}
}
@Override
public void addListener(IContainerListener crafting) {
super.addListener(crafting);
crafting.sendProgressBarUpdate(this, 0, tile.maxEnergy);
crafting.sendProgressBarUpdate(this, 1, (int) tile.getEnergy());
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;
} else if (id == 3) {
this.channel = value;
}
}
}

View file

@ -24,95 +24,43 @@
package techreborn.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import reborncore.common.network.NetworkManager;
import reborncore.common.powerSystem.PowerSystem;
import techreborn.client.container.ContainerIDSU;
import techreborn.packets.PacketIdsu;
import techreborn.tiles.idsu.TileIDSU;
import java.awt.*;
import java.io.IOException;
public class GuiIDSU extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/aesu.png");
public class GuiIDSU extends GuiBase {
TileIDSU idsu;
ContainerIDSU containerIDSU;
public GuiIDSU(EntityPlayer player, TileIDSU tileIDSU) {
super(new ContainerIDSU(tileIDSU, player));
super(player, tileIDSU, tileIDSU.createContainer(player));
this.xSize = 176;
this.ySize = 197;
idsu = tileIDSU;
this.containerIDSU = (ContainerIDSU) this.inventorySlots;
}
public static boolean isInteger(String s) {
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;
else
continue;
}
if (Character.digit(s.charAt(i), radix) < 0)
return false;
}
return true;
}
@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 + 115, l + 5, 15, 20, "++"));
this.buttonList.add(new GuiButton(1, k + 115, l + 5 + 20, 15, 20, "+"));
this.buttonList.add(new GuiButton(2, k + 115, l + 5 + (20 * 2), 15, 20, "-"));
this.buttonList.add(new GuiButton(3, k + 115, l + 5 + (20 * 3), 15, 20, "--"));
this.buttonList.add(new GuiButton(4, k + 40, l + 10, 10, 10, "+"));
protected void drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
final Layer layer = Layer.BACKGROUND;
this.drawSlot(62, 45, layer);
this.drawSlot(98, 45, layer);
this.drawArmourSlots(8, 18, layer);
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final Layer layer = Layer.FOREGROUND;
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
this.fontRendererObj.drawString(I18n.translateToLocal("tile.techreborn.idsu.name"), 75, 10,
Color.WHITE.getRGB());
this.fontRendererObj.drawString(PowerSystem.getLocaliszedPower(containerIDSU.euOut) + "/tick", 10, 22,
Color.WHITE.getRGB());
this.fontRendererObj.drawString(PowerSystem.getLocaliszedPower(containerIDSU.storedEu), 10, 32,
Color.WHITE.getRGB());
this.fontRendererObj.drawString(PowerSystem.getLocaliszedPower(containerIDSU.euChange) + " change", 10, 42,
Color.WHITE.getRGB());
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
super.actionPerformed(button);
NetworkManager.sendToServer(new PacketIdsu(button.id, idsu));
GlStateManager.pushMatrix();
GlStateManager.scale(0.6, 0.6, 1);
this.drawCentredString(PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) this.idsu.getEnergy()) + "/" + PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) this.idsu.getMaxPower()) + " " + PowerSystem.getDisplayPower().abbreviation, 35, 0, 58, layer);
GlStateManager.popMatrix();
this.builder.drawMultiEnergyBar(this, 81, 28, (int) this.idsu.getEnergy(), (int) this.idsu.getMaxPower(), mouseX, mouseY, 0, layer);
}
}

View file

@ -25,19 +25,20 @@
package techreborn.tiles.idsu;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import org.apache.commons.lang3.StringUtils;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;
import techreborn.tiles.storage.TileEnergyStorage;
@RebornRegistry(modID = ModInfo.MOD_ID)
public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
public class TileIDSU extends TileEnergyStorage implements IContainerProvider {
@ConfigRegistry(config = "machines", category = "idsu", key = "IdsuMaxInput", comment = "IDSU Max Input (Value in EU)")
public static int maxInput = 8192;
@ -47,12 +48,9 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
public static int maxEnergy = 100000000;
public String ownerUdid;
private double euLastTick = 0;
private double euChange;
private int ticks;
public TileIDSU() {
super();
super("IDSU", 2, ModBlocks.INTERDIMENSIONAL_SU, EnumPowerTier.EXTREME, maxInput, maxOutput, maxEnergy);
}
@Override
@ -71,45 +69,6 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
IDSUManager.INSTANCE.getSaveDataForWorld(world, ownerUdid).storedPower = energy;
}
@Override
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
}
@Override
public double getBaseMaxPower() {
return maxEnergy;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
@Override
public double getBaseMaxOutput() {
return maxOutput;
}
@Override
public double getBaseMaxInput() {
return maxInput;
}
public float getChargeLevel() {
float ret = (float) this.getEnergy() / (float) maxEnergy;
if (ret > 1.0F) {
ret = 1.0F;
}
return ret;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.ownerUdid = nbttagcompound.getString("ownerUdid");
@ -124,68 +83,10 @@ public class TileIDSU extends TilePowerAcceptor implements IWrenchable {
return nbttagcompound;
}
public void updateEntity() {
super.updateEntity();
if (ticks == 100) {
euChange = -1;
ticks = 0;
} else {
ticks++;
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
euLastTick = getEnergy();
boolean needsInvUpdate = false;
if (needsInvUpdate) {
this.markDirty();
}
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer p0, EnumFacing p1) {
return true;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer p0) {
return true;
}
@Override
public float getWrenchDropRate() {
return 1.0F;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.INTERDIMENSIONAL_SU, 1);
writeToNBT(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
return dropStack;
}
public double getEuChange() {
if (euChange == -1) {
return -1;
}
return (euChange / ticks);
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("mfsu").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create();
}
}