Updated LESU. Closes #1322

This commit is contained in:
drcrazy 2017-10-26 02:26:07 +03:00
parent bae5f73d85
commit c8b6edd390
5 changed files with 57 additions and 229 deletions

View file

@ -59,7 +59,7 @@ public enum EGui implements IMachineGuiHandler {
INDUSTRIAL_ELECTROLYZER(true),
INDUSTRIAL_GRINDER(true),
IRON_FURNACE(true),
LESU(false),
LESU(true),
LOW_VOLTAGE_SU(true),
MANUAL(false),
MATTER_FABRICATOR(true),

View file

@ -30,7 +30,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;
import techreborn.client.container.ContainerDestructoPack;
import techreborn.client.container.ContainerLESU;
import techreborn.client.container.IContainerProvider;
import techreborn.client.gui.*;
import techreborn.client.gui.autocrafting.GuiAutoCrafting;
@ -61,8 +60,6 @@ public class GuiHandler implements IGuiHandler {
switch (gui) {
case DESTRUCTOPACK:
return new ContainerDestructoPack(player);
case LESU:
return new ContainerLESU((TileLapotronicSU) tile, player);
default:
break;
}

View file

@ -1,117 +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.lesu.TileLapotronicSU;
public class ContainerLESU extends RebornContainer {
public int euOut;
public int storedEu;
public int euChange;
public int connectedBlocks;
public double euStorage;
EntityPlayer player;
TileLapotronicSU tile;
public ContainerLESU(TileLapotronicSU tileaesu, EntityPlayer player) {
tile = tileaesu;
this.player = player;
// input
this.addSlotToContainer(new BaseSlot(tileaesu.inventory, 0, 116, 23));
this.addSlotToContainer(new BaseSlot(tileaesu.inventory, 1, 116, 59));
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.getMaxOutput()) {
IContainerListener.sendWindowProperty(this, 0, (int) tile.getMaxOutput());
}
if (this.storedEu != tile.getEnergy()) {
IContainerListener.sendWindowProperty(this, 1, (int) tile.getEnergy());
}
if (this.euChange != tile.getEuChange() && tile.getEuChange() != -1) {
IContainerListener.sendWindowProperty(this, 2, (int) tile.getEuChange());
}
if (this.connectedBlocks != tile.connectedBlocks) {
IContainerListener.sendWindowProperty(this, 3, tile.connectedBlocks);
}
}
}
@Override
public void addListener(IContainerListener crafting) {
super.addListener(crafting);
crafting.sendWindowProperty(this, 0, (int) tile.getMaxOutput());
crafting.sendWindowProperty(this, 1, (int) tile.getEnergy());
crafting.sendWindowProperty(this, 2, (int) tile.getEuChange());
crafting.sendWindowProperty(this, 3, tile.connectedBlocks);
}
@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.connectedBlocks = value;
} else if (id == 4) {
this.euStorage = value;
}
this.euStorage = ((connectedBlocks + 1) * TileLapotronicSU.storagePerBlock);
}
}

View file

@ -24,61 +24,43 @@
package techreborn.client.gui;
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.client.resources.I18n;
import reborncore.common.powerSystem.PowerSystem;
import techreborn.client.container.ContainerLESU;
import techreborn.tiles.lesu.TileLapotronicSU;
import java.awt.*;
public class GuiLESU extends GuiBase {
public class GuiLESU extends GuiContainer {
TileLapotronicSU tile;
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/aesu.png");
TileLapotronicSU aesu;
ContainerLESU containerLesu;
public GuiLESU(EntityPlayer player, TileLapotronicSU tileaesu) {
super(new ContainerLESU(tileaesu, player));
this.xSize = 176;
this.ySize = 197;
aesu = tileaesu;
this.containerLesu = (ContainerLESU) this.inventorySlots;
public GuiLESU(final EntityPlayer player, final TileLapotronicSU tile) {
super(player, tile, tile.createContainer(player));
this.tile = tile;
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
this.drawDefaultBackground();
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 drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
final Layer layer = Layer.BACKGROUND;
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
this.fontRenderer.drawString(I18n.format("tile.techreborn:lapotronic_su.name"), 40, 10,
Color.WHITE.getRGB());
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerLesu.euOut) + "/t", 10, 20,
Color.WHITE.getRGB());
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerLesu.storedEu), 10, 30,
Color.WHITE.getRGB());
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerLesu.euChange) + " change", 10, 40,
Color.WHITE.getRGB());
this.fontRenderer.drawString(containerLesu.connectedBlocks + " blocks", 10, 50, Color.WHITE.getRGB());
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(containerLesu.euStorage) + " max", 10, 60,
Color.WHITE.getRGB());
this.drawSlot(62, 45, layer);
this.drawSlot(98, 45, layer);
this.drawArmourSlots(8, 18, layer);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final Layer layer = Layer.FOREGROUND;
GlStateManager.pushMatrix();
GlStateManager.scale(0.6, 0.6, 1);
this.drawCentredString(PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) this.tile.getEnergy()) + "/"
+ PowerSystem.getLocaliszedPowerFormattedNoSuffix((int) this.tile.getMaxPower()) + " "
+ PowerSystem.getDisplayPower().abbreviation, 35, 0, 58, layer);
GlStateManager.popMatrix();
this.builder.drawMultiEnergyBar(this, 81, 28, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(),
mouseX, mouseY, 0, layer);
}
}

View file

@ -26,25 +26,26 @@ package techreborn.tiles.lesu;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.IToolDrop;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.Inventory;
import techreborn.blocks.storage.BlockLapotronicSU;
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;
import java.util.ArrayList;
@RebornRegistry(modID = ModInfo.MOD_ID)
public class TileLapotronicSU extends TilePowerAcceptor implements IToolDrop{// TODO wrench
public class TileLapotronicSU extends TileEnergyStorage implements IContainerProvider{
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxInput", comment = "LESU Max Input (Value in EU)")
public static int maxInput = 8192;
// @ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxInput", comment = "LESU Max Input (Value in EU)")
// public static int maxInput = 8192;
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxOutput", comment = "LESU Base Output (Value in EU)")
public static int baseOutput = 16;
@ConfigRegistry(config = "machines", category = "lesu", key = "LesuMaxEnergyPerBlock", comment = "LESU Max Energy Per Block (Value in EU)")
@ -53,16 +54,10 @@ public class TileLapotronicSU extends TilePowerAcceptor implements IToolDrop{//
public static int extraIOPerBlock = 8;
public int connectedBlocks = 0;
public Inventory inventory = new Inventory(2, "TileAdjustableSU", 64, this);
private ArrayList<LesuNetwork> countedNetworks = new ArrayList<>();
private double euLastTick = 0;
private double euChange;
private int ticks;
private int output;
private int maxStorage;
public TileLapotronicSU() {
super();
super("LESU", 2, ModBlocks.LAPOTRONIC_SU, EnumPowerTier.INSANE, 8192, baseOutput, 1000000);
}
@Override
@ -94,56 +89,8 @@ public class TileLapotronicSU extends TilePowerAcceptor implements IToolDrop{//
}
}
}
maxStorage = ((connectedBlocks + 1) * storagePerBlock);
output = (connectedBlocks * extraIOPerBlock) + baseOutput;
if (ticks == 100) {
euChange = -1;
ticks = 0;
} else {
ticks++;
if (euChange == -1) {
euChange = 0;
}
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
euLastTick = getEnergy();
}
public double getEuChange() {
if (euChange == -1) {
return 0;
}
return (euChange / ticks);
}
@Override
public double getBaseMaxPower() {
return maxStorage;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return direction != getFacingEnum();
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return direction == getFacingEnum();
}
@Override
public double getBaseMaxOutput() {
return output;
}
@Override
public double getBaseMaxInput() {
return maxInput;
this.maxStorage = ((connectedBlocks + 1) * storagePerBlock);
this.maxOutput = (connectedBlocks * extraIOPerBlock) + baseOutput;
}
@Override
@ -154,9 +101,28 @@ public class TileLapotronicSU extends TilePowerAcceptor implements IToolDrop{//
}
return null;
}
public int getOutputRate() {
return this.maxOutput;
}
public void setOutputRate(int output) {
this.maxOutput = output;
}
public int getMaxStorage() {
return this.maxStorage;
}
public void setMaxStorage(int value) {
this.maxStorage = value;
}
@Override
public ItemStack getToolDrop(EntityPlayer p0) {
return new ItemStack(ModBlocks.LAPOTRONIC_SU, 1);
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("lesu").player(player.inventory).inventory().hotbar().armor().complete(8, 18)
.addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue()
.syncIntegerValue(this::getOutputRate, this::setOutputRate)
.syncIntegerValue(this::getMaxStorage, this::setMaxStorage).addInventory().create(this);
}
}