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 {

View file

@ -14,7 +14,6 @@ import techreborn.api.generator.GeneratorRecipeHelper;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.machines.AssemblingMachineRecipe;
import techreborn.api.recipe.machines.ImplosionCompressorRecipe;
import techreborn.client.container.ContainerFusionReactor;
import techreborn.client.gui.*;
import techreborn.compat.CompatManager;
import techreborn.compat.jei.alloySmelter.AlloySmelterRecipeCategory;
@ -272,10 +271,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
final IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry();
recipeTransferRegistry
.addRecipeTransferHandler(ContainerFusionReactor.class, RecipeCategoryUids.FUSION_REACTOR, 0, 2, 3, 36);
recipeTransferRegistry.addRecipeTransferHandler(
new BuiltContainerTransferInfo("fusionreactor", RecipeCategoryUids.FUSION_REACTOR, 36, 2, 0, 36));
recipeTransferRegistry.addRecipeTransferHandler(
new BuiltContainerTransferInfo("industrialelectrolyzer", RecipeCategoryUids.INDUSTRIAL_ELECTROLYZER, 36,
2, 0, 36));

View file

@ -5,11 +5,13 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.init.ModBlocks;
@ -39,18 +41,18 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return !(direction == EnumFacing.DOWN || direction == EnumFacing.UP);
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return direction == EnumFacing.DOWN || direction == EnumFacing.UP;
}
@Override
public double getMaxOutput() {
if (!hasStartedCrafting) {
if (!this.hasStartedCrafting) {
return 0;
}
return 1000000;
@ -58,7 +60,7 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
@Override
public double getMaxInput() {
if (hasStartedCrafting) {
if (this.hasStartedCrafting) {
return 0;
}
return 8192;
@ -70,68 +72,68 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
crafingTickTime = tagCompound.getInteger("crafingTickTime");
finalTickTime = tagCompound.getInteger("finalTickTime");
neededPower = tagCompound.getInteger("neededPower");
hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
this.crafingTickTime = tagCompound.getInteger("crafingTickTime");
this.finalTickTime = tagCompound.getInteger("finalTickTime");
this.neededPower = tagCompound.getInteger("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
if (crafingTickTime == -1) {
crafingTickTime = 0;
if (this.crafingTickTime == -1) {
this.crafingTickTime = 0;
}
if (finalTickTime == -1) {
finalTickTime = 0;
if (this.finalTickTime == -1) {
this.finalTickTime = 0;
}
if (neededPower == -1) {
neededPower = 0;
if (this.neededPower == -1) {
this.neededPower = 0;
}
tagCompound.setInteger("crafingTickTime", crafingTickTime);
tagCompound.setInteger("finalTickTime", finalTickTime);
tagCompound.setInteger("neededPower", neededPower);
tagCompound.setBoolean("hasStartedCrafting", hasStartedCrafting);
tagCompound.setInteger("crafingTickTime", this.crafingTickTime);
tagCompound.setInteger("finalTickTime", this.finalTickTime);
tagCompound.setInteger("neededPower", this.neededPower);
tagCompound.setBoolean("hasStartedCrafting", this.hasStartedCrafting);
return tagCompound;
}
public boolean checkCoils() {
if ((isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ()))
&& (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ()))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 3))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 3))
&& (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3))) {
coilStatus = 1;
if (this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ())
&& this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ())
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 3)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 3)
&& this.isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3)) {
this.coilStatus = 1;
return true;
}
coilStatus = 0;
this.coilStatus = 0;
return false;
}
private boolean isCoil(int x, int y, int z) {
return world.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FUSION_COIL;
private boolean isCoil(final int x, final int y, final int z) {
return this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FUSION_COIL;
}
@Override
@ -139,104 +141,104 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
super.updateEntity();
// TODO improve this code a lot
if (world.getTotalWorldTime() % 20 == 0) {
checkCoils();
if (this.world.getTotalWorldTime() % 20 == 0) {
this.checkCoils();
}
if (!world.isRemote) {
if (coilStatus == 1) {
if (currentRecipe == null) {
if (inventory.hasChanged || crafingTickTime != 0) {
for (FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true,
true, true)) {
if (!this.world.isRemote) {
if (this.coilStatus == 1) {
if (this.currentRecipe == null) {
if (this.inventory.hasChanged || this.crafingTickTime != 0) {
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), reactorRecipe.getTopInput(), true,
true, true)) {
if (reactorRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot),
reactorRecipe.getBottomInput(), true, true, true)) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot),
reactorRecipe.getBottomInput(), true, true, true)) {
break;
}
}
if (canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)) {
currentRecipe = reactorRecipe;
if (crafingTickTime != 0) {
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
if (this.canFitStack(reactorRecipe.getOutput(), this.outputStackSlot, true)) {
this.currentRecipe = reactorRecipe;
if (this.crafingTickTime != 0) {
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
}
hasStartedCrafting = false;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
this.hasStartedCrafting = false;
this.crafingTickTime = 0;
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
break;
}
}
}
}
} else {
if (inventory.hasChanged) {
if (!validateRecipe()) {
resetCrafter();
if (this.inventory.hasChanged) {
if (!this.validateRecipe()) {
this.resetCrafter();
return;
}
}
if (!hasStartedCrafting) {
if (canUseEnergy(currentRecipe.getStartEU() + 64)) {
useEnergy(currentRecipe.getStartEU());
hasStartedCrafting = true;
if (!this.hasStartedCrafting) {
if (this.canUseEnergy(this.currentRecipe.getStartEU() + 64)) {
this.useEnergy(this.currentRecipe.getStartEU());
this.hasStartedCrafting = true;
}
} else {
if (crafingTickTime < currentRecipe.getTickTime()) {
if (currentRecipe.getEuTick() > 0) { // Power gen
addEnergy(currentRecipe.getEuTick()); // Waste
if (this.crafingTickTime < this.currentRecipe.getTickTime()) {
if (this.currentRecipe.getEuTick() > 0) { // Power gen
this.addEnergy(this.currentRecipe.getEuTick()); // Waste
// power
// if it
// has
// no
// where
// to go
crafingTickTime++;
this.crafingTickTime++;
} else { // Power user
if (canUseEnergy(currentRecipe.getEuTick() * -1)) {
setEnergy(getEnergy() - (currentRecipe.getEuTick() * -1));
crafingTickTime++;
if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
this.crafingTickTime++;
}
}
} else {
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
if (getStackInSlot(outputStackSlot) == ItemStack.EMPTY) {
setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy());
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
if (this.getStackInSlot(this.outputStackSlot) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
decrStackSize(outputStackSlot, -currentRecipe.getOutput().getCount());
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
decrStackSize(topStackSlot, currentRecipe.getTopInput().getCount());
if (currentRecipe.getBottomInput() != ItemStack.EMPTY) {
decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().getCount());
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (this.currentRecipe.getBottomInput() != ItemStack.EMPTY) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
resetCrafter();
this.resetCrafter();
}
}
}
}
} else {
if (currentRecipe != null) {
resetCrafter();
if (this.currentRecipe != null) {
this.resetCrafter();
}
}
}
if (inventory.hasChanged) {
inventory.hasChanged = false;
if (this.inventory.hasChanged) {
this.inventory.hasChanged = false;
}
}
private boolean validateRecipe() {
if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)) {
if (currentRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true,
true)) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), this.currentRecipe.getTopInput(), true, true, true)) {
if (this.currentRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), this.currentRecipe.getBottomInput(), true, true,
true)) {
return false;
}
}
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
return true;
}
}
@ -244,22 +246,22 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
private void resetCrafter() {
currentRecipe = null;
crafingTickTime = -1;
finalTickTime = -1;
neededPower = -1;
hasStartedCrafting = false;
this.currentRecipe = null;
this.crafingTickTime = -1;
this.finalTickTime = -1;
this.neededPower = -1;
this.hasStartedCrafting = false;
}
public boolean canFitStack(ItemStack stack, int slot, boolean oreDic) {// Checks to see if it can fit the stack
public boolean canFitStack(final ItemStack stack, final int slot, final boolean oreDic) {// Checks to see if it can fit the stack
if (stack == ItemStack.EMPTY) {
return true;
}
if (inventory.getStackInSlot(slot) == ItemStack.EMPTY) {
if (this.inventory.getStackInSlot(slot) == ItemStack.EMPTY) {
return true;
}
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + this.inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
return true;
}
}
@ -283,6 +285,43 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getCoilStatus() {
return this.coilStatus;
}
public void setCoilStatus(final int coilStatus) {
this.coilStatus = coilStatus;
}
public int getCrafingTickTime() {
return this.crafingTickTime;
}
public void setCrafingTickTime(final int crafingTickTime) {
this.crafingTickTime = crafingTickTime;
}
public int getFinalTickTime() {
return this.finalTickTime;
}
public void setFinalTickTime(final int finalTickTime) {
this.finalTickTime = finalTickTime;
}
public int getNeededPower() {
return this.neededPower;
}
public void setNeededPower(final int neededPower) {
this.neededPower = neededPower;
}
public int getProgressScaled() {
return Math.max(0, Math.min(24, (this.getCrafingTickTime() > 0 ? 1 : 0)
+ this.getCrafingTickTime() * 24 / (this.finalTickTime < 1 ? 1 : this.finalTickTime)));
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB