Updated reactor GUI. Closes #1422
This commit is contained in:
parent
2e115242a2
commit
a6df9441ec
5 changed files with 325 additions and 300 deletions
|
@ -42,6 +42,7 @@ public class ClientMultiBlocks {
|
|||
checkMachine();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void checkCoils() {
|
||||
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))
|
||||
|
@ -52,6 +53,7 @@ public class ClientMultiBlocks {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private static boolean isCoil(int x, int y, int z) {
|
||||
reactor.addComponent(new BlockPos(x, y, z), ModBlocks.FUSION_COIL.getDefaultState());
|
||||
return true;
|
||||
|
|
|
@ -24,123 +24,116 @@
|
|||
|
||||
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.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
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.client.resources.I18n;
|
||||
import reborncore.client.multiblock.Multiblock;
|
||||
import reborncore.client.multiblock.MultiblockRenderEvent;
|
||||
import reborncore.client.multiblock.MultiblockSet;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import techreborn.client.ClientMultiBlocks;
|
||||
import techreborn.client.gui.widget.GuiButtonHologram;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.proxies.ClientProxy;
|
||||
import techreborn.tiles.fusionReactor.TileFusionControlComputer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiFusionReactor extends GuiContainer {
|
||||
|
||||
public static final ResourceLocation texture = new ResourceLocation("techreborn",
|
||||
"textures/gui/fusion_reactor.png");
|
||||
|
||||
public class GuiFusionReactor extends GuiBase {
|
||||
TileFusionControlComputer tile;
|
||||
|
||||
public GuiFusionReactor(final EntityPlayer player, final TileFusionControlComputer fusion) {
|
||||
super(fusion.createContainer(player));
|
||||
this.tile = fusion;
|
||||
public GuiFusionReactor(final EntityPlayer player, final TileFusionControlComputer tile) {
|
||||
super(player, tile, tile.createContainer(player));
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
|
||||
final String name = I18n.format("tile.techreborn:fusion_control_computer.name");
|
||||
this.fontRenderer.drawString(name, 87, 6, 4210752);
|
||||
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8,
|
||||
this.ySize - 96 + 2, 4210752);
|
||||
protected void drawGuiContainerBackgroundLayer(final float partialTicks, final int mouseX, final int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
|
||||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
|
||||
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(this.tile.getEnergy()), 11, 8,
|
||||
16448255);
|
||||
this.fontRenderer.drawString("Coils: " + (this.tile.getCoilStatus() == 1 ? "Yes" : "No"), 11, 16,
|
||||
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.drawSlot(34, 47, layer);
|
||||
this.drawSlot(126, 47, layer);
|
||||
this.drawOutputSlot(80, 47, layer);
|
||||
|
||||
this.builder.drawJEIButton(this, 150, 4, layer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
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();
|
||||
final BlockPos coordinates = new BlockPos(
|
||||
this.tile.getPos().getX()
|
||||
- EnumFacing.getFront(this.tile.getFacingInt()).getFrontOffsetX() * 2,
|
||||
this.tile.getPos().getY() - 1, this.tile.getPos().getZ()
|
||||
- EnumFacing.getFront(this.tile.getFacingInt()).getFrontOffsetZ() * 2);
|
||||
if (coordinates.equals(MultiblockRenderEvent.anchor)) {
|
||||
ClientProxy.multiblockRenderEvent.setMultiblock(null);
|
||||
button.displayString = "B";
|
||||
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
||||
|
||||
this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 55, 51, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
|
||||
this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 105, 51, mouseX, mouseY, TRBuilder.ProgressDirection.LEFT, layer);
|
||||
this.builder.drawMultiEnergyBar(this, 9, 19, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
|
||||
if (tile.checkCoils()) {
|
||||
addHologramButton(6, 4, 212, layer);
|
||||
builder.drawHologramButton(this, 6, 4, mouseX, mouseY, layer);
|
||||
} else {
|
||||
button.displayString = "A";
|
||||
builder.drawMultiblockMissingBar(this, layer);
|
||||
addHologramButton(76, 56, 212, layer);
|
||||
builder.drawHologramButton(this, 76, 56, mouseX, mouseY, layer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_,
|
||||
final int p_146976_3_) {
|
||||
this.drawDefaultBackground();
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
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);
|
||||
|
||||
this.drawTexturedModalRect(k + 88, l + 36, 176, 0, 14, 14);
|
||||
|
||||
// progressBar
|
||||
this.drawTexturedModalRect(k + 111, l + 34, 176, 14, this.tile.getProgressScaled(), 16);
|
||||
|
||||
|
||||
public void addHologramButton(int x, int y, int id, Layer layer) {
|
||||
if (id == 0)
|
||||
buttonList.clear();
|
||||
int factorX = 0;
|
||||
int factorY = 0;
|
||||
if (layer == Layer.BACKGROUND) {
|
||||
factorX = guiLeft;
|
||||
factorY = guiTop;
|
||||
}
|
||||
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
|
||||
public void actionPerformed(final GuiButton button) throws IOException {
|
||||
super.actionPerformed(button);
|
||||
if (button.id == 212) {
|
||||
if (button.id == 212 && !GuiBase.showSlotConfig) {
|
||||
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
|
||||
// This code here makes a basic multiblock and then sets to
|
||||
// theselected one.
|
||||
final MultiblockSet set = new MultiblockSet(ClientMultiBlocks.reactor);
|
||||
// This code here makes a basic multiblock and then sets to the selected one.
|
||||
final Multiblock multiblock = new Multiblock();
|
||||
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.parent = this.tile.getPos();
|
||||
// new Location(this.fusionController.getPos().getX(),
|
||||
// this.fusionController.getPos().getY(), this.fusionController.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";
|
||||
MultiblockRenderEvent.anchor = new BlockPos(this.tile.getPos().getX(), this.tile.getPos().getY() - 1,
|
||||
this.tile.getPos().getZ());
|
||||
} else {
|
||||
ClientProxy.multiblockRenderEvent.setMultiblock(null);
|
||||
button.displayString = "B";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.renderHoveredToolTip(mouseX, mouseY);
|
||||
|
||||
public void addComponent(final int x, final int y, final int z, final IBlockState blockState, final Multiblock multiblock) {
|
||||
multiblock.addComponent(new BlockPos(x, y, z), blockState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,12 +311,12 @@ public class TechRebornJeiPlugin implements IModPlugin {
|
|||
addRecipeClickArea(GuiPlasmaGenerator.class, 150, 4, 18, 18, EFluidGenerator.PLASMA.getRecipeID());
|
||||
addRecipeClickArea(GuiDistillationTower.class, 150, 4, 18, 18, RecipeCategoryUids.DISTILLATION_TOWER);
|
||||
addRecipeClickArea(GuiScrapboxinator.class, 150, 4, 18, 18, RecipeCategoryUids.SCRAPBOX);
|
||||
addRecipeClickArea(GuiFusionReactor.class, 150, 4, 18, 18, RecipeCategoryUids.FUSION_REACTOR);
|
||||
|
||||
//OLD ONES
|
||||
addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER,
|
||||
VanillaRecipeCategoryUid.FUEL);
|
||||
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(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING,
|
||||
VanillaRecipeCategoryUid.FUEL);
|
||||
|
|
|
@ -31,8 +31,8 @@ import mezz.jei.api.gui.IRecipeLayout;
|
|||
import mezz.jei.api.ingredients.IIngredients;
|
||||
import mezz.jei.api.recipe.IRecipeCategory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import techreborn.client.gui.GuiFusionReactor;
|
||||
import techreborn.compat.jei.RecipeCategoryUids;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
|
@ -40,7 +40,8 @@ import javax.annotation.Nonnull;
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
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 inputSlotBottom = 1;
|
||||
private static final int outputSlot = 2;
|
||||
|
@ -51,7 +52,7 @@ public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReacto
|
|||
private final String title;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -87,9 +88,9 @@ public class FusionReactorRecipeCategory implements IRecipeCategory<FusionReacto
|
|||
@Nonnull
|
||||
IIngredients ingredients) {
|
||||
IGuiItemStackGroup itemStacks = recipeLayout.getItemStacks();
|
||||
itemStacks.init(inputSlotTop, true, 21, 0);
|
||||
itemStacks.init(inputSlotBottom, true, 21, 36);
|
||||
itemStacks.init(outputSlot, false, 81, 18);
|
||||
itemStacks.init(inputSlotTop, true, 23, 7);
|
||||
itemStacks.init(inputSlotBottom, true, 115, 7);
|
||||
itemStacks.init(outputSlot, false, 69, 7);
|
||||
|
||||
itemStacks.set(inputSlotTop, recipeWrapper.getTopInput());
|
||||
itemStacks.set(inputSlotBottom, recipeWrapper.getBottomInput());
|
||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.item.ItemStack;
|
|||
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.IToolDrop;
|
||||
import reborncore.api.tile.IInventoryProvider;
|
||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||
|
@ -46,7 +45,8 @@ import techreborn.init.ModBlocks;
|
|||
import techreborn.lib.ModInfo;
|
||||
|
||||
@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)")
|
||||
public static int maxInput = 8192;
|
||||
|
@ -54,10 +54,8 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
|
|||
public static int maxOutput = 1000000;
|
||||
@ConfigRegistry(config = "machines", category = "fusion_reactor", key = "FusionReactorMaxEnergy", comment = "Fusion Reactor Max Energy (Value in EU)")
|
||||
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
|
||||
public int coilStatus = 0;
|
||||
|
@ -72,6 +70,206 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
|
|||
|
||||
public TileFusionControlComputer() {
|
||||
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
|
||||
|
@ -117,16 +315,6 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
|
|||
@Override
|
||||
public NBTTagCompound writeToNBT(final NBTTagCompound 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("finalTickTime", this.finalTickTime);
|
||||
tagCompound.setInteger("neededPower", this.neededPower);
|
||||
|
@ -134,190 +322,56 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
|
|||
return tagCompound;
|
||||
}
|
||||
|
||||
public boolean checkCoils() {
|
||||
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;
|
||||
}
|
||||
|
||||
// TileLegacyMachineBase
|
||||
@Override
|
||||
public void onLoad() {
|
||||
super.onLoad();
|
||||
this.checkCoils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void resetCrafter() {
|
||||
this.currentRecipe = null;
|
||||
this.crafingTickTime = -1;
|
||||
this.finalTickTime = -1;
|
||||
this.neededPower = -1;
|
||||
this.hasStartedCrafting = 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// @Override
|
||||
// public String getName() {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean hasCustomName() {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ITextComponent getDisplayName() {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// IToolDrop
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return null;
|
||||
public ItemStack getToolDrop(EntityPlayer p0) {
|
||||
return new ItemStack(ModBlocks.FUSION_CONTROL_COMPUTER, 1);
|
||||
}
|
||||
|
||||
// IInventoryProvider
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
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() {
|
||||
return this.coilStatus;
|
||||
}
|
||||
|
@ -349,29 +403,4 @@ public class TileFusionControlComputer extends TilePowerAcceptor implements IToo
|
|||
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)));
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue