Updated reactor GUI. Closes #1422

This commit is contained in:
drcrazy 2018-01-29 18:17:32 +03:00
parent 2e115242a2
commit a6df9441ec
5 changed files with 325 additions and 300 deletions

View file

@ -42,6 +42,7 @@ public class ClientMultiBlocks {
checkMachine(); checkMachine();
} }
@Deprecated
public static void checkCoils() { public static void checkCoils() {
if ((isCoil(3, 0, 1)) && (isCoil(3, 0, 0)) && (isCoil(3, 0, 0 - 1)) && (isCoil(0 - 3, 0, 1)) if ((isCoil(3, 0, 1)) && (isCoil(3, 0, 0)) && (isCoil(3, 0, 0 - 1)) && (isCoil(0 - 3, 0, 1))
&& (isCoil(0 - 3, 0, 0)) && (isCoil(0 - 3, 0, 0 - 1)) && (isCoil(2, 0, 2)) && (isCoil(2, 0, 1)) && (isCoil(0 - 3, 0, 0)) && (isCoil(0 - 3, 0, 0 - 1)) && (isCoil(2, 0, 2)) && (isCoil(2, 0, 1))
@ -52,6 +53,7 @@ public class ClientMultiBlocks {
} }
} }
@Deprecated
private static boolean isCoil(int x, int y, int z) { private static boolean isCoil(int x, int y, int z) {
reactor.addComponent(new BlockPos(x, y, z), ModBlocks.FUSION_COIL.getDefaultState()); reactor.addComponent(new BlockPos(x, y, z), ModBlocks.FUSION_COIL.getDefaultState());
return true; return true;

View file

@ -24,123 +24,116 @@
package techreborn.client.gui; package techreborn.client.gui;
import java.io.IOException;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.client.resources.I18n; import reborncore.client.multiblock.Multiblock;
import reborncore.client.multiblock.MultiblockRenderEvent; import reborncore.client.multiblock.MultiblockRenderEvent;
import reborncore.client.multiblock.MultiblockSet; import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.powerSystem.PowerSystem; import techreborn.client.gui.widget.GuiButtonHologram;
import techreborn.client.ClientMultiBlocks; import techreborn.init.ModBlocks;
import techreborn.proxies.ClientProxy; import techreborn.proxies.ClientProxy;
import techreborn.tiles.fusionReactor.TileFusionControlComputer; import techreborn.tiles.fusionReactor.TileFusionControlComputer;
import java.io.IOException; public class GuiFusionReactor extends GuiBase {
public class GuiFusionReactor extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/fusion_reactor.png");
TileFusionControlComputer tile; TileFusionControlComputer tile;
public GuiFusionReactor(final EntityPlayer player, final TileFusionControlComputer fusion) { public GuiFusionReactor(final EntityPlayer player, final TileFusionControlComputer tile) {
super(fusion.createContainer(player)); super(player, tile, tile.createContainer(player));
this.tile = fusion; this.tile = tile;
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) { protected void drawGuiContainerBackgroundLayer(final float partialTicks, final int mouseX, final int mouseY) {
final String name = I18n.format("tile.techreborn:fusion_control_computer.name"); super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
this.fontRenderer.drawString(name, 87, 6, 4210752); final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(this.tile.getEnergy()), 11, 8, this.drawSlot(34, 47, layer);
16448255); this.drawSlot(126, 47, layer);
this.fontRenderer.drawString("Coils: " + (this.tile.getCoilStatus() == 1 ? "Yes" : "No"), 11, 16, this.drawOutputSlot(80, 47, layer);
16448255);
if (this.tile.getNeededPower() > 1 && this.tile.getCrafingTickTime() < 1)
this.fontRenderer.drawString("Start: "
+ this.percentage(this.tile.getNeededPower(), (int) this.tile.getEnergy())
+ "%", 11, 24, 16448255);
this.builder.drawJEIButton(this, 150, 4, layer);
} }
@Override @Override
public void initGui() { protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
final int k = (this.width - this.xSize) / 2; super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final int l = (this.height - this.ySize) / 2; final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
final GuiButton button = new GuiButton(212, k + this.xSize - 24, l + 4, 20, 20, "");
this.buttonList.add(button); this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 55, 51, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
super.initGui(); this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 105, 51, mouseX, mouseY, TRBuilder.ProgressDirection.LEFT, layer);
final BlockPos coordinates = new BlockPos( this.builder.drawMultiEnergyBar(this, 9, 19, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
this.tile.getPos().getX() if (tile.checkCoils()) {
- EnumFacing.getFront(this.tile.getFacingInt()).getFrontOffsetX() * 2, addHologramButton(6, 4, 212, layer);
this.tile.getPos().getY() - 1, this.tile.getPos().getZ() builder.drawHologramButton(this, 6, 4, mouseX, mouseY, layer);
- EnumFacing.getFront(this.tile.getFacingInt()).getFrontOffsetZ() * 2);
if (coordinates.equals(MultiblockRenderEvent.anchor)) {
ClientProxy.multiblockRenderEvent.setMultiblock(null);
button.displayString = "B";
} else { } else {
button.displayString = "A"; builder.drawMultiblockMissingBar(this, layer);
addHologramButton(76, 56, 212, layer);
builder.drawHologramButton(this, 76, 56, mouseX, mouseY, layer);
} }
} }
@Override public void addHologramButton(int x, int y, int id, Layer layer) {
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, if (id == 0)
final int p_146976_3_) { buttonList.clear();
this.drawDefaultBackground(); int factorX = 0;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); int factorY = 0;
this.mc.getTextureManager().bindTexture(GuiFusionReactor.texture); if (layer == Layer.BACKGROUND) {
final int k = (this.width - this.xSize) / 2; factorX = guiLeft;
final int l = (this.height - this.ySize) / 2; factorY = guiTop;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
this.drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14);
// progressBar
this.drawTexturedModalRect(k + 111, l + 34, 176, 14, this.tile.getProgressScaled(), 16);
} }
buttonList.add(new GuiButtonHologram(id, x + factorX, y + factorY, this, layer));
public int percentage(final int MaxValue, final int CurrentValue) {
if (CurrentValue == 0)
return 0;
return (int) (CurrentValue * 100.0f / MaxValue);
} }
@Override @Override
public void actionPerformed(final 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 && !GuiBase.showSlotConfig) {
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) { if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
// This code here makes a basic multiblock and then sets to // This code here makes a basic multiblock and then sets to the selected one.
// theselected one. final Multiblock multiblock = new Multiblock();
final MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor); IBlockState coil = ModBlocks.FUSION_COIL.getDefaultState();
this.addComponent(3, 0, 1, coil, multiblock);
this.addComponent(3, 0, 0, coil, multiblock);
this.addComponent(3, 0, -1, coil, multiblock);
this.addComponent(-3, 0, 1, coil, multiblock);
this.addComponent(-3, 0, 0, coil, multiblock);
this.addComponent(-3, 0, -1, coil, multiblock);
this.addComponent(2, 0, 2, coil, multiblock);
this.addComponent(2, 0, 1, coil, multiblock);
this.addComponent(2, 0, -1, coil, multiblock);
this.addComponent(2, 0, -2, coil, multiblock);
this.addComponent(-2, 0, 2, coil, multiblock);
this.addComponent(-2, 0, 1, coil, multiblock);
this.addComponent(-2, 0, -1, coil, multiblock);
this.addComponent(-2, 0, -2, coil, multiblock);
this.addComponent(1, 0, 3, coil, multiblock);
this.addComponent(1, 0, 2, coil, multiblock);
this.addComponent(1, 0, -2, coil, multiblock);
this.addComponent(1, 0, -3, coil, multiblock);
this.addComponent(-1, 0, 3, coil, multiblock);
this.addComponent(-1, 0, 2, coil, multiblock);
this.addComponent(-1, 0, -2, coil, multiblock);
this.addComponent(-1, 0, -3, coil, multiblock);
this.addComponent(0, 0, 3, coil, multiblock);
this.addComponent(0, 0, -3, coil, multiblock);
final MultiblockSet set = new MultiblockSet(multiblock);
ClientProxy.multiblockRenderEvent.setMultiblock(set); ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.parent = this.tile.getPos(); ClientProxy.multiblockRenderEvent.parent = this.tile.getPos();
// new Location(this.fusionController.getPos().getX(), MultiblockRenderEvent.anchor = new BlockPos(this.tile.getPos().getX(), this.tile.getPos().getY() - 1,
// this.fusionController.getPos().getY(), this.fusionController.getPos().getZ(), this.tile.getPos().getZ());
// this.fusionController.getWorld());
MultiblockRenderEvent.anchor = new BlockPos(this.tile.getPos().getX(),
this.tile.getPos().getY() - 1, this.tile.getPos().getZ());
button.displayString = "A";
} else { } else {
ClientProxy.multiblockRenderEvent.setMultiblock(null); ClientProxy.multiblockRenderEvent.setMultiblock(null);
button.displayString = "B";
} }
} }
} }
@Override public void addComponent(final int x, final int y, final int z, final IBlockState blockState, final Multiblock multiblock) {
public void drawScreen(int mouseX, int mouseY, float partialTicks) { multiblock.addComponent(new BlockPos(x, y, z), blockState);
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
} }
} }

View file

@ -311,12 +311,12 @@ public class TechRebornJeiPlugin implements IModPlugin {
addRecipeClickArea(GuiPlasmaGenerator.class, 150, 4, 18, 18, EFluidGenerator.PLASMA.getRecipeID()); addRecipeClickArea(GuiPlasmaGenerator.class, 150, 4, 18, 18, EFluidGenerator.PLASMA.getRecipeID());
addRecipeClickArea(GuiDistillationTower.class, 150, 4, 18, 18, RecipeCategoryUids.DISTILLATION_TOWER); addRecipeClickArea(GuiDistillationTower.class, 150, 4, 18, 18, RecipeCategoryUids.DISTILLATION_TOWER);
addRecipeClickArea(GuiScrapboxinator.class, 150, 4, 18, 18, RecipeCategoryUids.SCRAPBOX); addRecipeClickArea(GuiScrapboxinator.class, 150, 4, 18, 18, RecipeCategoryUids.SCRAPBOX);
addRecipeClickArea(GuiFusionReactor.class, 150, 4, 18, 18, RecipeCategoryUids.FUSION_REACTOR);
//OLD ONES //OLD ONES
addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER, addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER,
VanillaRecipeCategoryUid.FUEL); VanillaRecipeCategoryUid.FUEL);
addRecipeClickArea(GuiAssemblingMachine.class, 85, 34, 24, 20, RecipeCategoryUids.ASSEMBLING_MACHINE); addRecipeClickArea(GuiAssemblingMachine.class, 85, 34, 24, 20, RecipeCategoryUids.ASSEMBLING_MACHINE);
addRecipeClickArea(GuiFusionReactor.class, 111, 34, 27, 19, RecipeCategoryUids.FUSION_REACTOR);
addRecipeClickArea(GuiRollingMachine.class, 89, 32, 26, 25, RecipeCategoryUids.ROLLING_MACHINE); addRecipeClickArea(GuiRollingMachine.class, 89, 32, 26, 25, RecipeCategoryUids.ROLLING_MACHINE);
addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING,
VanillaRecipeCategoryUid.FUEL); VanillaRecipeCategoryUid.FUEL);

View file

@ -31,8 +31,8 @@ import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory; import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n; import net.minecraft.util.text.translation.I18n;
import techreborn.client.gui.GuiFusionReactor;
import techreborn.compat.jei.RecipeCategoryUids; import techreborn.compat.jei.RecipeCategoryUids;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
@ -41,6 +41,7 @@ import javax.annotation.Nonnull;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReactorRecipeWrapper> { public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReactorRecipeWrapper> {
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/jei.png");
private static final int inputSlotTop = 0; private static final int inputSlotTop = 0;
private static final int inputSlotBottom = 1; private static final int inputSlotBottom = 1;
private static final int outputSlot = 2; private static final int outputSlot = 2;
@ -51,7 +52,7 @@ public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReacto
private final String title; private final String title;
public FusionReactorRecipeCategory(IGuiHelper guiHelper) { public FusionReactorRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createDrawable(GuiFusionReactor.texture, 86, 16, 85, 64, 0, 40, 20, 20); background = guiHelper.createDrawable(texture, 0, 172, 116, 64, 0, 40, 20, 20);
title = I18n.translateToLocal("tile.techreborn:fusion_control_computer.name"); title = I18n.translateToLocal("tile.techreborn:fusion_control_computer.name");
} }
@ -87,9 +88,9 @@ public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReacto
@Nonnull @Nonnull
IIngredients ingredients) { IIngredients ingredients) {
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks(); IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
itemStacks.init(inputSlotTop, true, 21, 0); itemStacks.init(inputSlotTop, true, 23, 7);
itemStacks.init(inputSlotBottom, true, 21, 36); itemStacks.init(inputSlotBottom, true, 115, 7);
itemStacks.init(outputSlot, false, 81, 18); itemStacks.init(outputSlot, false, 69, 7);
itemStacks.set(inputSlotTop, recipeWrapper.getTopInput()); itemStacks.set(inputSlotTop, recipeWrapper.getTopInput());
itemStacks.set(inputSlotBottom, recipeWrapper.getBottomInput()); itemStacks.set(inputSlotBottom, recipeWrapper.getBottomInput());

View file

@ -29,7 +29,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; 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 reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.tile.IInventoryProvider; import reborncore.api.tile.IInventoryProvider;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
@ -46,7 +45,8 @@ import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo; import techreborn.lib.ModInfo;
@RebornRegistry(modID = ModInfo.MOD_ID) @RebornRegistry(modID = ModInfo.MOD_ID)
public class TileFusionControlComputer extends TilePowerAcceptor implements IToolDrop, IInventoryProvider, IContainerProvider { public class TileFusionControlComputer extends TilePowerAcceptor
implements IToolDrop, IInventoryProvider, IContainerProvider {
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxInput", comment = "Fusion Reactor Max Input (Value in EU)") @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxInput", comment = "Fusion Reactor Max Input (Value in EU)")
public static int maxInput = 8192; public static int maxInput = 8192;
@ -54,10 +54,8 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
public static int maxOutput = 1000000; public static int maxOutput = 1000000;
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxEnergy", comment = "Fusion Reactor Max Energy (Value in EU)") @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxEnergy", comment = "Fusion Reactor Max Energy (Value in EU)")
public static int maxEnergy = 100000000; public static int maxEnergy = 100000000;
// @ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorWrenchDropRate", comment = "Fusion Reactor Wrench Drop Rate")
public static float wrenchDropRate = 1.0F;
public Inventory inventory = new Inventory(3, "TileFusionControlComputer", 64, this); public Inventory inventory;
// 0= no coils, 1 = coils // 0= no coils, 1 = coils
public int coilStatus = 0; public int coilStatus = 0;
@ -72,6 +70,206 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
public TileFusionControlComputer() { public TileFusionControlComputer() {
super(); super();
this.inventory = new Inventory(3, "TileFusionControlComputer", 64, this);
}
/**
* Check that reactor has all necessary coils in place
*
* @return boolean Return true if coils are present
*/
public boolean checkCoils() {
int posX = this.getPos().getX();
int posY = this.getPos().getY();
int posZ = this.getPos().getZ();
if (isCoil(posX + 3, posY, posZ + 1) && isCoil(posX + 3, posY, posZ) && isCoil(posX + 3, posY, posZ - 1)
&& isCoil(posX - 3, posY, posZ + 1) && isCoil(posX - 3, posY, posZ) && isCoil(posX - 3, posY, posZ - 1)
&& isCoil(posX + 2, posY, posZ + 2) && isCoil(posX + 2, posY, posZ + 1)
&& isCoil(posX + 2, posY, posZ - 1) && isCoil(posX + 2, posY, posZ - 2)
&& isCoil(posX - 2, posY, posZ + 2) && isCoil(posX - 2, posY, posZ + 1)
&& isCoil(posX - 2, posY, posZ - 1) && isCoil(posX - 2, posY, posZ - 2)
&& isCoil(posX + 1, posY, posZ + 3) && isCoil(posX + 1, posY, posZ + 2)
&& isCoil(posX + 1, posY, posZ - 2) && isCoil(posX + 1, posY, posZ - 3)
&& isCoil(posX - 1, posY, posZ + 3) && isCoil(posX - 1, posY, posZ + 2)
&& isCoil(posX - 1, posY, posZ - 2) && isCoil(posX - 1, posY, posZ - 3) && isCoil(posX, posY, posZ + 3)
&& isCoil(posX, posY, posZ - 3)) {
coilStatus = 1;
return true;
}
coilStatus = 0;
return false;
}
/**
* Checks if block is fusion coil
*
* @param x int X coordinate for block
* @param y int Y coordinate for block
* @param z int Z coordinate for block
* @return boolean Returns true if block is 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;
}
/**
* Resets crafter progress and recipe
*/
private void resetCrafter() {
this.currentRecipe = null;
this.crafingTickTime = 0;
this.finalTickTime = 0;
this.neededPower = 0;
this.hasStartedCrafting = false;
}
/**
* Checks that ItemStack could be inserted into slot provided, including check
* for existing item in slot and maximum stack size
*
* @param stack ItemStack ItemStack to insert
* @param slot int Slot ID to check
* @param oreDic boolean Should we use ore dictionary
* @return boolean Returns true if ItemStack will fit into slot
*/
public boolean canFitStack(final ItemStack stack, final int slot, final boolean oreDic) {// Checks to see if it can
// fit the stack
if (stack.isEmpty()) {
return true;
}
if (this.inventory.getStackInSlot(slot).isEmpty()) {
return true;
}
if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + this.inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
return true;
}
}
return false;
}
/**
* Returns progress scaled to input value
*
* @param scale int Maximum value for progress
* @return int Scale of progress
*/
public int getProgressScaled(int scale) {
if (this.crafingTickTime != 0) {
return this.crafingTickTime * scale / this.finalTickTime;
}
return 0;
}
/**
* Tries to set current recipe based in inputs in reactor
*/
private void updateCurrentRecipe() {
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (validateReactorRecipe(reactorRecipe)) {
this.currentRecipe = reactorRecipe;
this.crafingTickTime = 0;
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
this.hasStartedCrafting = false;
break;
}
}
}
/**
* Validates that reactor can execute recipe provided, e.g. has all inputs and can fit output
*
* @param recipe FusionReactorRecipe Recipe to validate
* @return boolean True if reactor can execute recipe provided
*/
private boolean validateReactorRecipe(FusionReactorRecipe recipe) {
if (ItemUtils.isItemEqual(this.getStackInSlot(topStackSlot), recipe.getTopInput(), true, true, true)) {
if (recipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(bottomStackSlot), recipe.getBottomInput(), true, true, true)) {
return false;
}
}
if (this.canFitStack(recipe.getOutput(), outputStackSlot, true)) {
return true;
}
}
return false;
}
// TilePowerAcceptor
@Override
public void update() {
super.update();
if (this.world.isRemote) {
return;
}
// Force check every second
if (this.world.getTotalWorldTime() % 20 == 0) {
this.checkCoils();
this.inventory.hasChanged = true;
}
if (this.coilStatus == 0) {
this.resetCrafter();
return;
}
if (this.currentRecipe == null && this.inventory.hasChanged == true) {
updateCurrentRecipe();
}
if (this.currentRecipe != null) {
if (this.inventory.hasChanged && !validateReactorRecipe(this.currentRecipe)) {
resetCrafter();
return;
}
if (!this.hasStartedCrafting) {
// Ignition!
if (this.canUseEnergy(this.currentRecipe.getStartEU())) {
this.useEnergy(this.currentRecipe.getStartEU());
this.hasStartedCrafting = true;
}
}
if (hasStartedCrafting && this.crafingTickTime < this.finalTickTime) {
this.crafingTickTime++;
// Power gen
if (this.currentRecipe.getEuTick() > 0) {
// Waste power if it has no where to go
this.addEnergy(this.currentRecipe.getEuTick());
} else { // Power user
if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
}
}
} else if (this.crafingTickTime >= this.finalTickTime) {
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
if (this.getStackInSlot(this.outputStackSlot).isEmpty()) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (!this.currentRecipe.getBottomInput().isEmpty()) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
if (this.validateReactorRecipe(this.currentRecipe)) {
this.crafingTickTime = 0;
} else {
this.resetCrafter();
}
}
}
this.markDirty();
}
if (this.inventory.hasChanged) {
this.inventory.hasChanged = false;
}
} }
@Override @Override
@ -117,16 +315,6 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
@Override @Override
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) { public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
if (this.crafingTickTime == -1) {
this.crafingTickTime = 0;
}
if (this.finalTickTime == -1) {
this.finalTickTime = 0;
}
if (this.neededPower == -1) {
this.neededPower = 0;
}
tagCompound.setInteger("crafingTickTime", this.crafingTickTime); tagCompound.setInteger("crafingTickTime", this.crafingTickTime);
tagCompound.setInteger("finalTickTime", this.finalTickTime); tagCompound.setInteger("finalTickTime", this.finalTickTime);
tagCompound.setInteger("neededPower", this.neededPower); tagCompound.setInteger("neededPower", this.neededPower);
@ -134,42 +322,7 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
return tagCompound; return tagCompound;
} }
public boolean checkCoils() { // TileLegacyMachineBase
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;
}
this.coilStatus = 0;
return false;
}
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 @Override
public void onLoad() { public void onLoad() {
super.onLoad(); super.onLoad();
@ -177,147 +330,48 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
} }
@Override @Override
public void update() { public boolean canBeUpgraded() {
super.update();
// TODO improve this code a lot
if (this.world.isRemote) {
return;
}
if (this.world.getTotalWorldTime() % 20 == 0) {
this.checkCoils();
}
if (this.coilStatus == 0) {
this.resetCrafter();
return;
}
if (this.currentRecipe == null && this.inventory.hasChanged){
this.crafingTickTime = 0;
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (this.validateRecipe(reactorRecipe)){
this.currentRecipe = reactorRecipe;
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
break;
}
}
}
else {
if (this.inventory.hasChanged) {
if (!this.validateRecipe(this.currentRecipe)) {
this.resetCrafter();
return;
}
}
}
if (this.currentRecipe != null) {
if (!this.hasStartedCrafting) {
// Ignition!
if (this.canUseEnergy(this.currentRecipe.getStartEU())) {
this.useEnergy(this.currentRecipe.getStartEU());
this.hasStartedCrafting = true;
}
}
if (hasStartedCrafting && this.crafingTickTime < this.finalTickTime) {
this.crafingTickTime++;
// Power gen
if (this.currentRecipe.getEuTick() > 0) {
// Waste power if it has no where to go
this.addEnergy(this.currentRecipe.getEuTick());
} else { // Power user
if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
}
}
} else if (this.crafingTickTime >= this.finalTickTime) {
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
if (this.getStackInSlot(this.outputStackSlot).isEmpty()) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (!this.currentRecipe.getBottomInput().isEmpty()) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
if (this.validateRecipe(this.currentRecipe)){
this.crafingTickTime = 0;
}
else {
this.resetCrafter();
}
}
}
this.markDirty();
}
if (this.inventory.hasChanged) {
this.inventory.hasChanged = false;
}
}
private boolean validateRecipe(FusionReactorRecipe recipe) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), recipe.getTopInput(), true, true, true)) {
if (recipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), recipe.getBottomInput(), true, true,
true)) {
return false;
}
}
if (this.canFitStack(recipe.getOutput(), this.outputStackSlot, true)) {
return true;
}
}
return false; return false;
} }
private void resetCrafter() { // @Override
this.currentRecipe = null; // public String getName() {
this.crafingTickTime = -1; // return null;
this.finalTickTime = -1; // }
this.neededPower = -1; //
this.hasStartedCrafting = false; // @Override
} // public boolean hasCustomName() {
// return false;
public boolean canFitStack(final ItemStack stack, final int slot, final boolean oreDic) {// Checks to see if it can fit the stack // }
if (stack.isEmpty()) { //
return true; // @Override
} // public ITextComponent getDisplayName() {
if (this.inventory.getStackInSlot(slot).isEmpty()) { // return null;
return true; // }
}
if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + this.inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
return true;
}
}
return false;
}
// IToolDrop
@Override @Override
public String getName() { public ItemStack getToolDrop(EntityPlayer p0) {
return null; return new ItemStack(ModBlocks.FUSION_CONTROL_COMPUTER, 1);
}
@Override
public boolean hasCustomName() {
return false;
}
@Override
public ITextComponent getDisplayName() {
return null;
} }
// IInventoryProvider
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return this.inventory; return this.inventory;
} }
// IContainerProvider
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("fusionreactor").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).syncEnergyValue()
.syncIntegerValue(this::getCoilStatus, this::setCoilStatus)
.syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime)
.syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime)
.syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this);
}
public int getCoilStatus() { public int getCoilStatus() {
return this.coilStatus; return this.coilStatus;
} }
@ -349,29 +403,4 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
public void setNeededPower(final int neededPower) { public void setNeededPower(final int neededPower) {
this.neededPower = 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)));
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 88, 17).slot(1, 88, 53).outputSlot(2, 148, 35).syncEnergyValue()
.syncIntegerValue(this::getCoilStatus, this::setCoilStatus)
.syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime)
.syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime)
.syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create(this);
}
@Override
public ItemStack getToolDrop(EntityPlayer p0) {
return new ItemStack(ModBlocks.FUSION_CONTROL_COMPUTER, 1);
}
@Override
public boolean canBeUpgraded() {
return false;
}
} }