Fusion reactor fixes & rewrite, energy fixes.

This commit is contained in:
Dragon2488 2016-07-22 21:45:55 +07:00
parent fe64b8ccf7
commit 06fad2264f
13 changed files with 279 additions and 386 deletions

View file

@ -7,21 +7,22 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.client.gui.SlotOutput;
import reborncore.common.container.RebornContainer;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
public class ContainerFusionReactor extends RebornContainer
{
public class ContainerFusionReactor extends RebornContainer {
public int coilStatus;
public int energy;
public int tickTime;
public int finalTickTime;
public int neededEU;
public int neededEnergy;
public int energy;
public boolean hasCoils;
TileEntityFusionController fusionController;
public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController, EntityPlayer player)
{
public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController, EntityPlayer player) {
super();
this.fusionController = tileEntityFusionController;
@ -31,105 +32,73 @@ public class ContainerFusionReactor extends RebornContainer
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 BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@Override
public void detectAndSendChanges()
{
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); i++)
{
IContainerListener IContainerListener = this.listeners.get(i);
if (this.coilStatus != fusionController.coilStatus)
{
IContainerListener.sendProgressBarUpdate(this, 0, fusionController.coilStatus);
}
if (this.energy != (int) fusionController.getEnergy())
{
IContainerListener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
}
if (this.tickTime != fusionController.crafingTickTime)
{
IContainerListener.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime);
}
if (this.finalTickTime != fusionController.finalTickTime)
{
IContainerListener.sendProgressBarUpdate(this, 3, fusionController.finalTickTime);
}
if (this.neededEU != fusionController.neededPower)
{
IContainerListener.sendProgressBarUpdate(this, 4, fusionController.neededPower);
}
FusionReactorRecipe rec = fusionController.recipe;
for (int i = 0; i < this.listeners.size(); i++) {
IContainerListener listener = this.listeners.get(i);
listener.sendProgressBarUpdate(this, 0, fusionController.hasCoils ? 1 : 0);
listener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
listener.sendProgressBarUpdate(this, 2, rec == null ? 0 : (int) rec.getStartEU());
listener.sendProgressBarUpdate(this, 3, rec == null ? -1 : fusionController.recipeTickTime);
listener.sendProgressBarUpdate(this, 4, rec == null ? 0 : rec.getTickTime());
}
}
@Override
public void addListener(IContainerListener crafting)
{
super.addListener(crafting);
crafting.sendProgressBarUpdate(this, 0, fusionController.coilStatus);
crafting.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
crafting.sendProgressBarUpdate(this, 2, fusionController.crafingTickTime);
crafting.sendProgressBarUpdate(this, 3, fusionController.finalTickTime);
crafting.sendProgressBarUpdate(this, 4, fusionController.neededPower);
public void addListener(IContainerListener listener) {
super.addListener(listener);
FusionReactorRecipe rec = fusionController.recipe;
listener.sendProgressBarUpdate(this, 0, fusionController.hasCoils ? 1 : 0);
listener.sendProgressBarUpdate(this, 1, (int) fusionController.getEnergy());
listener.sendProgressBarUpdate(this, 2, rec == null ? 0 : (int) rec.getStartEU());
listener.sendProgressBarUpdate(this, 3, rec == null ? -1 : fusionController.recipeTickTime);
listener.sendProgressBarUpdate(this, 4, rec == null ? 0 : rec.getTickTime());
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value)
{
if (id == 0)
{
this.coilStatus = value;
} else if (id == 1)
{
this.energy = value;
} else if (id == 2)
{
this.tickTime = value;
} else if (id == 3)
{
this.finalTickTime = value;
} else if (id == 4)
{
this.neededEU = value;
}
if (tickTime == -1)
{
tickTime = 0;
}
if (finalTickTime == -1)
{
finalTickTime = 0;
}
if (neededEU == -1)
{
neededEU = 0;
public void updateProgressBar(int id, int value) {
switch (id) {
case 0:
this.hasCoils = value == 1;
break;
case 1:
this.energy = value;
break;
case 2:
this.neededEnergy = value;
break;
case 3:
this.tickTime = value;
break;
case 4:
this.finalTickTime = value;
break;
}
}
public int getProgressScaled()
{
public int getProgressScaled() {
return Math.max(0, Math.min(24,
(this.tickTime > 0 ? 1 : 0) + this.tickTime * 24 / (this.finalTickTime < 1 ? 1 : this.finalTickTime)));
}
}

View file

@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import reborncore.common.powerSystem.PowerSystem;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.client.container.ContainerFusionReactor;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
@ -19,29 +20,28 @@ public class GuiFusionReactor extends GuiContainer
"textures/gui/fusion_reactor.png");
ContainerFusionReactor containerFusionReactor;
TileEntityFusionController fusionController;
public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu)
{
public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu) {
super(new ContainerFusionReactor(tileaesu, player));
containerFusionReactor = (ContainerFusionReactor) this.inventorySlots;
this.fusionController = tileaesu;
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_)
{
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
String name = I18n.translateToLocal("tile.techreborn.fusioncontrolcomputer.name");
this.fontRendererObj.drawString(name, 87, 6, 4210752);
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(PowerSystem.getLocalizedPower(containerFusionReactor.energy), 11, 8, 16448255);
this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No"), 11, 16,
16448255);
if (containerFusionReactor.neededEU > 1 && containerFusionReactor.tickTime < 1)
this.fontRendererObj.drawString(
"Start: " + percentage(containerFusionReactor.neededEU, containerFusionReactor.energy) + "%", 11,
24, 16448255);
this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.hasCoils ? "Yes" : "No"), 11, 16, 16448255);
if(containerFusionReactor.tickTime != -1) {
if (containerFusionReactor.tickTime == 0) {
this.fontRendererObj.drawString("Start: " + percentage(containerFusionReactor.neededEnergy,
containerFusionReactor.energy) + "%", 11, 24, 16448255);
} else {
this.fontRendererObj.drawString("Fusion: " + percentage(containerFusionReactor.finalTickTime,
containerFusionReactor.tickTime) + "%", 11, 24, 16448255);
}
}
}
@ -85,7 +85,7 @@ public class GuiFusionReactor extends GuiContainer
}
public int percentage(int MaxValue, int CurrentValue)
public int percentage(double MaxValue, double CurrentValue)
{
if (CurrentValue == 0)
return 0;