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) { } else if (ID == GuiHandler.idsuID) {
return new ContainerIDSU((TileIDSU) world.getTileEntity(new BlockPos(x, y, z)), player); return new ContainerIDSU((TileIDSU) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.fusionID) { } else if (ID == GuiHandler.fusionID) {
return new ContainerFusionReactor((TileEntityFusionController) world.getTileEntity(new BlockPos(x, y, z)), return new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
player); .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) { } else if (ID == GuiHandler.chargeBench) {
return new ContainerBuilder("chargebench").player(player.inventory).inventory().hotbar(8, 142) 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) .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.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n; import net.minecraft.util.text.translation.I18n;
import reborncore.client.multiblock.MultiblockRenderEvent;
import reborncore.client.multiblock.MultiblockSet; import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.misc.Location; import reborncore.common.misc.Location;
import reborncore.common.multiblock.CoordTriplet;
import reborncore.common.powerSystem.PowerSystem; import reborncore.common.powerSystem.PowerSystem;
import techreborn.client.ClientMultiBlocks; import techreborn.client.ClientMultiBlocks;
import techreborn.client.container.ContainerFusionReactor; import techreborn.client.container.builder.ContainerBuilder;
import techreborn.proxies.ClientProxy; import techreborn.proxies.ClientProxy;
import techreborn.tiles.fusionReactor.TileEntityFusionController; import techreborn.tiles.fusionReactor.TileEntityFusionController;
@ -22,49 +24,51 @@ import java.io.IOException;
public class GuiFusionReactor extends GuiContainer { public class GuiFusionReactor extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn", public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/fusion_reactor.png"); "textures/gui/fusion_reactor.png");
ContainerFusionReactor containerFusionReactor;
TileEntityFusionController fusionController; TileEntityFusionController fusionController;
public GuiFusionReactor(EntityPlayer player, TileEntityFusionController tileaesu) { public GuiFusionReactor(final EntityPlayer player, final TileEntityFusionController fusion) {
super(new ContainerFusionReactor(tileaesu, player)); super(new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
containerFusionReactor = (ContainerFusionReactor) this.inventorySlots; .addInventory().tile(fusion).slot(0, 88, 17).slot(1, 88, 53).outputSlot(2, 148, 35).syncEnergyValue()
this.fusionController = tileaesu; .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_) { @Override
String name = I18n.translateToLocal("tile.techreborn.fusioncontrolcomputer.name"); 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(name, 87, 6, 4210752);
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8, 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(PowerSystem.getLocaliszedPower(this.fusionController.getEnergy()), 11, 8,
this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No"), 11, 16, 16448255);
16448255); this.fontRendererObj.drawString("Coils: " + (this.fusionController.getCoilStatus() == 1 ? "Yes" : "No"), 11, 16,
if (containerFusionReactor.neededEU > 1 && containerFusionReactor.tickTime < 1) 16448255);
this.fontRendererObj.drawString( if (this.fusionController.getNeededPower() > 1 && this.fusionController.getCrafingTickTime() < 1)
"Start: " + percentage(containerFusionReactor.neededEU, containerFusionReactor.energy) + "%", 11, this.fontRendererObj.drawString("Start: "
24, 16448255); + this.percentage(this.fusionController.getNeededPower(), (int) this.fusionController.getEnergy())
+ "%", 11, 24, 16448255);
} }
@Override @Override
public void initGui() { public void initGui() {
int k = (this.width - this.xSize) / 2; final int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2; final int l = (this.height - this.ySize) / 2;
GuiButton button = new GuiButton(212, k + this.xSize - 24, l + 4, 20, final GuiButton button = new GuiButton(212, k + this.xSize - 24, l + 4, 20, 20, "");
20, ""); this.buttonList.add(button);
buttonList.add(button);
super.initGui(); super.initGui();
BlockPos coordinates = new final BlockPos coordinates = new BlockPos(
BlockPos(fusionController.getPos().getX() - this.fusionController.getPos().getX()
(EnumFacing.getFront(fusionController.getFacingInt()).getFrontOffsetX() - EnumFacing.getFront(this.fusionController.getFacingInt()).getFrontOffsetX() * 2,
* 2), fusionController.getPos().getY() - 1, this.fusionController.getPos().getY() - 1, this.fusionController.getPos().getZ()
fusionController.getPos().getZ() - - EnumFacing.getFront(this.fusionController.getFacingInt()).getFrontOffsetZ() * 2);
(EnumFacing.getFront(fusionController.getFacingInt()).getFrontOffsetZ() if (coordinates.equals(MultiblockRenderEvent.anchor)) {
* 2));
if (coordinates.equals(ClientProxy.multiblockRenderEvent.anchor)) {
ClientProxy.multiblockRenderEvent.setMultiblock(null); ClientProxy.multiblockRenderEvent.setMultiblock(null);
button.displayString = "B"; button.displayString = "B";
} else { } else {
@ -73,42 +77,41 @@ public class GuiFusionReactor extends GuiContainer {
} }
@Override @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); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture); this.mc.getTextureManager().bindTexture(GuiFusionReactor.texture);
int k = (this.width - this.xSize) / 2; final int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2; final int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); 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 // 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) if (CurrentValue == 0)
return 0; return 0;
return (int) ((CurrentValue * 100.0f) / MaxValue); return (int) (CurrentValue * 100.0f / MaxValue);
} }
@Override @Override
public void actionPerformed(GuiButton button) throws IOException { public void actionPerformed(final GuiButton button) throws IOException {
super.actionPerformed(button); super.actionPerformed(button);
if (button.id == 212) { if (button.id == 212) {
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) { if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
//This code here makes a basic multiblock and then sets to theselected one. // This code here makes a basic multiblock and then sets to
MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor); // theselected one.
ClientProxy.multiblockRenderEvent.setMultiblock(set); final MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor);
ClientProxy.multiblockRenderEvent.parent = new ClientProxy.multiblockRenderEvent.setMultiblock(set);
Location(fusionController.getPos().getX(), ClientProxy.multiblockRenderEvent.parent = new Location(this.fusionController.getPos().getX(),
fusionController.getPos().getY(), fusionController.getPos().getZ(), this.fusionController.getPos().getY(), this.fusionController.getPos().getZ(),
fusionController.getWorld()); this.fusionController.getWorld());
ClientProxy.multiblockRenderEvent.anchor = new MultiblockRenderEvent.anchor = new BlockPos(this.fusionController.getPos().getX(),
BlockPos(fusionController.getPos().getX(), this.fusionController.getPos().getY() - 1, this.fusionController.getPos().getZ());
fusionController.getPos().getY() - 1,
fusionController.getPos().getZ());
button.displayString = "A"; button.displayString = "A";
} else { } else {

View file

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

View file

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