Convert FusionReactor

This commit is contained in:
Ourten 2017-01-08 16:32:03 +01:00
parent bd16289c60
commit b93fe6c5ad
7 changed files with 222 additions and 349 deletions

View file

@ -197,8 +197,24 @@ public class GuiHandler implements IGuiHandler {
} else if (ID == GuiHandler.idsuID) {
return new ContainerIDSU((TileIDSU) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.fusionID) {
return new ContainerFusionReactor((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)),
player);
return new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 88, 17)
.slot(1, 88, 53).outputSlot(2, 148, 35).syncEnergyValue()
.syncIntegerValue(
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::getCoilStatus,
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::setCoilStatus)
.syncIntegerValue(
((TileEntityFusionController) world
.getTileEntity(new BlockPos(x, y, z)))::getCrafingTickTime,
((TileEntityFusionController) world
.getTileEntity(new BlockPos(x, y, z)))::setCrafingTickTime)
.syncIntegerValue(
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::getFinalTickTime,
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::setFinalTickTime)
.syncIntegerValue(
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::getNeededPower,
((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)))::setNeededPower)
.addInventory().create();
} else if (ID == GuiHandler.chargeBench) {
return new ContainerBuilder("chargebench").player(player.inventory).inventory().hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).energySlot(0, 62, 21)

View file

@ -1,71 +0,0 @@
package techreborn.client.container;
import net.minecraft.inventory.IContainerListener;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.container.RebornContainer;
import reborncore.common.recipes.RecipeCrafter;
public abstract class ContainerCrafting extends RebornContainer {
RecipeCrafter crafter;
int currentTickTime = 0;
int currentNeededTicks = 0;
int energy;
public ContainerCrafting(RecipeCrafter crafter) {
this();
this.crafter = crafter;
}
public ContainerCrafting() {
}
public void setCrafter(RecipeCrafter crafter) {
this.crafter = crafter;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); i++) {
IContainerListener IContainerListener = this.listeners.get(i);
if (this.currentTickTime != crafter.currentTickTime || crafter.currentTickTime == -1) {
IContainerListener.sendProgressBarUpdate(this, 0, crafter.currentTickTime);
}
if (this.currentNeededTicks != crafter.currentNeededTicks) {
IContainerListener.sendProgressBarUpdate(this, 1, crafter.currentNeededTicks);
}
if (this.energy != (int) crafter.energy.getEnergy()) {
IContainerListener.sendProgressBarUpdate(this, 2, (int) crafter.energy.getEnergy());
}
}
}
@Override
public void addListener(IContainerListener crafting) {
super.addListener(crafting);
crafting.sendProgressBarUpdate(this, 0, crafter.currentTickTime);
crafting.sendProgressBarUpdate(this, 1, crafter.currentNeededTicks);
crafting.sendProgressBarUpdate(this, 2, (int) crafter.energy.getEnergy());
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 0) {
this.currentTickTime = value;
if (this.currentTickTime == -1) {
this.currentTickTime = 0;
}
} else if (id == 1) {
this.currentNeededTicks = value;
} else if (id == 2) {
this.energy = value;
}
this.crafter.currentTickTime = currentTickTime;
this.crafter.currentNeededTicks = currentNeededTicks;
this.crafter.energy.setEnergy(energy);
}
}

View file

@ -1,111 +0,0 @@
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.client.gui.slots.SlotOutput;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
public class ContainerFusionReactor extends RebornContainer {
public int coilStatus;
public int energy;
public int tickTime;
public int finalTickTime;
public int neededEU;
TileEntityFusionController fusionController;
public ContainerFusionReactor(TileEntityFusionController tileEntityFusionController, EntityPlayer player) {
super();
this.fusionController = tileEntityFusionController;
addSlotToContainer(new BaseSlot(tileEntityFusionController, 0, 88, 17));
addSlotToContainer(new BaseSlot(tileEntityFusionController, 1, 88, 53));
addSlotToContainer(new SlotOutput(tileEntityFusionController, 2, 148, 35));
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, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
}
}
@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.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);
}
}
}
@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);
}
@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 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

@ -8,12 +8,14 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import reborncore.client.multiblock.MultiblockRenderEvent;
import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.misc.Location;
import reborncore.common.multiblock.CoordTriplet;
import reborncore.common.powerSystem.PowerSystem;
import techreborn.client.ClientMultiBlocks;
import techreborn.client.container.ContainerFusionReactor;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.proxies.ClientProxy;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
@ -22,49 +24,51 @@ import java.io.IOException;
public class GuiFusionReactor extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/fusion_reactor.png");
"textures/gui/fusion_reactor.png");
ContainerFusionReactor containerFusionReactor;
TileEntityFusionController fusionController;
public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu) {
super(new ContainerFusionReactor(tileaesu, player));
containerFusionReactor = (ContainerFusionReactor) this.inventorySlots;
this.fusionController = tileaesu;
public GuiFusionReactor(final EntityPlayer player, final TileEntityFusionController fusion) {
super(new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(fusion).slot(0, 88, 17).slot(1, 88, 53).outputSlot(2, 148, 35).syncEnergyValue()
.syncIntegerValue(fusion::getCoilStatus, fusion::setCoilStatus)
.syncIntegerValue(fusion::getCrafingTickTime, fusion::setCrafingTickTime)
.syncIntegerValue(fusion::getFinalTickTime, fusion::setFinalTickTime)
.syncIntegerValue(fusion::getNeededPower, fusion::setNeededPower).addInventory().create());
this.fusionController = fusion;
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
String name = I18n.translateToLocal("tile.techreborn.fusioncontrolcomputer.name");
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final 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.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(PowerSystem.getLocaliszedPower(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(PowerSystem.getLocaliszedPower(this.fusionController.getEnergy()), 11, 8,
16448255);
this.fontRendererObj.drawString("Coils: " + (this.fusionController.getCoilStatus() == 1 ? "Yes" : "No"), 11, 16,
16448255);
if (this.fusionController.getNeededPower() > 1 && this.fusionController.getCrafingTickTime() < 1)
this.fontRendererObj.drawString("Start: "
+ this.percentage(this.fusionController.getNeededPower(), (int) this.fusionController.getEnergy())
+ "%", 11, 24, 16448255);
}
@Override
public void initGui() {
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
GuiButton button = new GuiButton(212, k + this.xSize - 24, l + 4, 20,
20, "");
buttonList.add(button);
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
final GuiButton button = new GuiButton(212, k + this.xSize - 24, l + 4, 20, 20, "");
this.buttonList.add(button);
super.initGui();
BlockPos coordinates = new
BlockPos(fusionController.getPos().getX() -
(EnumFacing.getFront(fusionController.getFacingInt()).getFrontOffsetX()
* 2), fusionController.getPos().getY() - 1,
fusionController.getPos().getZ() -
(EnumFacing.getFront(fusionController.getFacingInt()).getFrontOffsetZ()
* 2));
if (coordinates.equals(ClientProxy.multiblockRenderEvent.anchor)) {
final BlockPos coordinates = new BlockPos(
this.fusionController.getPos().getX()
- EnumFacing.getFront(this.fusionController.getFacingInt()).getFrontOffsetX() * 2,
this.fusionController.getPos().getY() - 1, this.fusionController.getPos().getZ()
- EnumFacing.getFront(this.fusionController.getFacingInt()).getFrontOffsetZ() * 2);
if (coordinates.equals(MultiblockRenderEvent.anchor)) {
ClientProxy.multiblockRenderEvent.setMultiblock(null);
button.displayString = "B";
} else {
@ -73,42 +77,41 @@ public class GuiFusionReactor extends GuiContainer {
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_,
final 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.mc.getTextureManager().bindTexture(GuiFusionReactor.texture);
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14);
this.drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14);
// progressBar
drawTexturedModalRect(k + 111, l + 34, 176, 14, containerFusionReactor.getProgressScaled(), 16);
this.drawTexturedModalRect(k + 111, l + 34, 176, 14, this.fusionController.getProgressScaled(), 16);
}
public int percentage(int MaxValue, int CurrentValue) {
public int percentage(final int MaxValue, final int CurrentValue) {
if (CurrentValue == 0)
return 0;
return (int) ((CurrentValue * 100.0f) / MaxValue);
return (int) (CurrentValue * 100.0f / MaxValue);
}
@Override
public void actionPerformed(GuiButton button) throws IOException {
public void actionPerformed(final GuiButton button) throws IOException {
super.actionPerformed(button);
if (button.id == 212) {
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
//This code here makes a basic multiblock and then sets to theselected one.
MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor);
ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.parent = new
Location(fusionController.getPos().getX(),
fusionController.getPos().getY(), fusionController.getPos().getZ(),
fusionController.getWorld());
ClientProxy.multiblockRenderEvent.anchor = new
BlockPos(fusionController.getPos().getX(),
fusionController.getPos().getY() - 1,
fusionController.getPos().getZ());
// This code here makes a basic multiblock and then sets to
// theselected one.
final MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor);
ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.parent = new Location(this.fusionController.getPos().getX(),
this.fusionController.getPos().getY(), this.fusionController.getPos().getZ(),
this.fusionController.getWorld());
MultiblockRenderEvent.anchor = new BlockPos(this.fusionController.getPos().getX(),
this.fusionController.getPos().getY() - 1, this.fusionController.getPos().getZ());
button.displayString = "A";
} else {