Updated scrapboxinator to crafter and new GUI.

This commit is contained in:
drcrazy 2018-01-19 18:07:21 +03:00
parent e0eb725878
commit 44b6f20357
8 changed files with 103 additions and 185 deletions

View file

@ -22,11 +22,12 @@
* SOFTWARE. * SOFTWARE.
*/ */
package techreborn.api.recipe; package techreborn.api.recipe.machines;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import techreborn.api.Reference; import techreborn.api.Reference;
import techreborn.api.TechRebornAPI; import techreborn.api.TechRebornAPI;
import techreborn.api.recipe.BaseRecipe;
//THIS is only here to trick JEI into showing recipes for the recycler //THIS is only here to trick JEI into showing recipes for the recycler
public class RecyclerRecipe extends BaseRecipe { public class RecyclerRecipe extends BaseRecipe {

View file

@ -22,18 +22,21 @@
* SOFTWARE. * SOFTWARE.
*/ */
package techreborn.api.recipe; package techreborn.api.recipe.machines;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import techreborn.api.Reference; import techreborn.api.Reference;
import techreborn.api.TechRebornAPI; import techreborn.api.TechRebornAPI;
import techreborn.api.recipe.BaseRecipe;
public class ScrapboxRecipe extends BaseRecipe { public class ScrapboxRecipe extends BaseRecipe {
public ScrapboxRecipe(ItemStack output) { public ScrapboxRecipe(ItemStack output, int tickTime, int euPerTick) {
super(Reference.scrapboxRecipe, 0, 0); super(Reference.scrapboxRecipe, tickTime, euPerTick);
addInput(new ItemStack(TechRebornAPI.getItem("SCRAP_BOX"))); if (output != null) {
addOutput(output); addInput(new ItemStack(TechRebornAPI.getItem("SCRAP_BOX")));
addOutput(output);
}
} }
@Override @Override

View file

@ -24,62 +24,39 @@
package techreborn.client.gui; package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import techreborn.tiles.TileScrapboxinator; import techreborn.tiles.TileScrapboxinator;
public class GuiScrapboxinator extends GuiContainer { public class GuiScrapboxinator extends GuiBase {
public static final ResourceLocation texture = new ResourceLocation("techreborn", TileScrapboxinator tile;
"textures/gui/scrapboxinator.png");
TileScrapboxinator scrapboxinator; public GuiScrapboxinator(final EntityPlayer player, final TileScrapboxinator tile) {
super(player, tile, tile.createContainer(player));
public GuiScrapboxinator(final EntityPlayer player, final TileScrapboxinator scrapboxinator) { this.tile = tile;
super(scrapboxinator.createContainer(player));
this.xSize = 176;
this.ySize = 167;
this.scrapboxinator = scrapboxinator;
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) { protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
this.drawDefaultBackground(); super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
this.mc.getTextureManager().bindTexture(GuiScrapboxinator.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);
int j = 0; // Battery slot
this.drawSlot(8, 72, layer);
// Scrapboxes input slot
this.drawSlot(55, 45, layer);
// Output slot
this.drawOutputSlot(101, 45, layer);
j = this.scrapboxinator.gaugeProgressScaled(24); this.builder.drawJEIButton(this, 150, 4, layer);
// System.out.println(compressor.gaugeProgressScaled(10));
if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
}
j = this.scrapboxinator.getEnergyScaled(12);
if (j > 0) {
this.drawTexturedModalRect(k + 24, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
}
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) { protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
final String name = I18n.format("tile.techreborn:scrapboxinator.name"); super.drawGuiContainerForegroundLayer(mouseX, mouseY);
this.fontRenderer.drawString(name, this.xSize / 2 - this.fontRenderer.getStringWidth(name) / 2, 6, final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
4210752);
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2,
4210752);
}
@Override this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 76, 48, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.builder.drawMultiEnergyBar(this, 9, 19, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
} }
} }

View file

@ -38,7 +38,7 @@ import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod; import stanhebben.zenscript.annotations.ZenMethod;
import techreborn.api.Reference; import techreborn.api.Reference;
import techreborn.api.recipe.BaseRecipe; import techreborn.api.recipe.BaseRecipe;
import techreborn.api.recipe.ScrapboxRecipe; import techreborn.api.recipe.machines.ScrapboxRecipe;
import techreborn.compat.crafttweaker.CTGeneric.Remove; import techreborn.compat.crafttweaker.CTGeneric.Remove;
/** /**
@ -49,7 +49,7 @@ public class CTScrapbox {
@ZenMethod @ZenMethod
public static void addScrapboxDrop(IIngredient input) { public static void addScrapboxDrop(IIngredient input) {
RecipeHandler.addRecipe(new ScrapboxRecipe(CraftTweakerMC.getItemStack(input))); RecipeHandler.addRecipe(new ScrapboxRecipe(CraftTweakerMC.getItemStack(input), 20, 2));
} }
@ZenMethod @ZenMethod

View file

@ -53,7 +53,6 @@ import techreborn.api.generator.FluidGeneratorRecipe;
import techreborn.api.generator.GeneratorRecipeHelper; import techreborn.api.generator.GeneratorRecipeHelper;
import techreborn.api.reactor.FusionReactorRecipe; import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.ScrapboxRecipe;
import techreborn.api.recipe.machines.*; import techreborn.api.recipe.machines.*;
import techreborn.blocks.cable.EnumCableType; import techreborn.blocks.cable.EnumCableType;
import techreborn.client.gui.*; import techreborn.client.gui.*;
@ -311,6 +310,7 @@ public class TechRebornJeiPlugin implements IModPlugin {
addRecipeClickArea(GuiAlloySmelter.class, 150, 4, 18, 18, RecipeCategoryUids.ALLOY_SMELTER); addRecipeClickArea(GuiAlloySmelter.class, 150, 4, 18, 18, RecipeCategoryUids.ALLOY_SMELTER);
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);
//OLD ONES //OLD ONES
addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER, addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER,

View file

@ -25,17 +25,13 @@
package techreborn.compat.jei.scrapbox; package techreborn.compat.jei.scrapbox;
import mezz.jei.api.IJeiHelpers; import mezz.jei.api.IJeiHelpers;
import techreborn.api.recipe.ScrapboxRecipe; import techreborn.api.recipe.machines.ScrapboxRecipe;
import techreborn.compat.jei.BaseRecipeWrapper; import techreborn.compat.jei.BaseRecipeWrapper;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
public class ScrapboxRecipeWrapper extends BaseRecipeWrapper<ScrapboxRecipe> { public class ScrapboxRecipeWrapper extends BaseRecipeWrapper<ScrapboxRecipe> {
public ScrapboxRecipeWrapper( public ScrapboxRecipeWrapper(@Nonnull IJeiHelpers jeiHelpers, @Nonnull ScrapboxRecipe baseRecipe) {
@Nonnull
IJeiHelpers jeiHelpers,
@Nonnull
ScrapboxRecipe baseRecipe) {
super(baseRecipe); super(baseRecipe);
} }
} }

View file

@ -30,7 +30,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import reborncore.api.recipe.RecipeHandler; import reborncore.api.recipe.RecipeHandler;
import techreborn.api.recipe.ScrapboxRecipe; import techreborn.api.recipe.machines.ScrapboxRecipe;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.init.ModItems; import techreborn.init.ModItems;
import techreborn.items.DynamicCell; import techreborn.items.DynamicCell;
@ -220,7 +220,7 @@ public class ScrapboxRecipes extends RecipeMethods {
if(output == null || output.isEmpty()){ if(output == null || output.isEmpty()){
return; return;
} }
RecipeHandler.addRecipe(new ScrapboxRecipe(output)); RecipeHandler.addRecipe(new ScrapboxRecipe(output, 20, 2));
} }
static void registerDyable(Item item) { static void registerDyable(Item item) {

View file

@ -24,22 +24,19 @@
package techreborn.tiles; package techreborn.tiles;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import reborncore.api.IToolDrop; import reborncore.api.IToolDrop;
import reborncore.api.recipe.IBaseRecipeType; import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.recipe.RecipeHandler;
import reborncore.api.tile.IInventoryProvider; import reborncore.api.tile.IInventoryProvider;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.RebornRegistry;
import reborncore.common.registration.impl.ConfigRegistry; import reborncore.common.registration.impl.ConfigRegistry;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import techreborn.api.Reference; import techreborn.api.recipe.ScrapboxRecipeCrafter;
import techreborn.client.container.IContainerProvider; import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer; import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder; import techreborn.client.container.builder.ContainerBuilder;
@ -49,129 +46,57 @@ import techreborn.lib.ModInfo;
@RebornRegistry(modID = ModInfo.MOD_ID) @RebornRegistry(modID = ModInfo.MOD_ID)
public class TileScrapboxinator extends TilePowerAcceptor public class TileScrapboxinator extends TilePowerAcceptor
implements IToolDrop, IInventoryProvider, IContainerProvider { implements IToolDrop, IInventoryProvider, IContainerProvider, IRecipeCrafterProvider {
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxInput", comment = "Scrapboxinator Max Input (Value in EU)") @ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxInput", comment = "Scrapboxinator Max Input (Value in EU)")
public static int maxInput = 32; public static int maxInput = 32;
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxEnergy", comment = "Scrapboxinator Max Energy (Value in EU)") @ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorMaxEnergy", comment = "Scrapboxinator Max Energy (Value in EU)")
public static int maxEnergy = 1000; public static int maxEnergy = 1000;
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorEnergyCost", comment = "Scrapboxinator Energy Cost (Value in EU)")
public static int cost = 20;
@ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorRunTime", comment = "Scrapboxinator Run Time")
public static int runTime = 10;
// @ConfigRegistry(config = "machines", category = "scrapboxinator", key = "ScrapboxinatorWrenchDropRate", comment = "Scrapboxinator Wrench Drop Rate")
public static float wrenchDropRate = 1.0F;
public Inventory inventory = new Inventory(6, "TileScrapboxinator", 64, this); public Inventory inventory = new Inventory(3, "TileScrapboxinator", 64, this);
public RecipeCrafter crafter;
public int progress;
public int input1 = 0;
public int output = 1;
public TileScrapboxinator() { public TileScrapboxinator() {
super(); super();
final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 };
this.crafter = new ScrapboxRecipeCrafter(this, this.inventory, inputs, outputs);
} }
public int gaugeProgressScaled(final int scale) { public int getProgressScaled(final int scale) {
return this.progress * scale / runTime; if (this.crafter.currentTickTime != 0 && this.crafter.currentNeededTicks > 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
}
return 0;
} }
// TilePowerAcceptor
@Override @Override
public void update() { public void update() {
final boolean burning = this.isBurning(); if (!this.world.isRemote) {
boolean updateInventory = false; super.update();
if (this.getEnergy() <= cost && this.canOpen()) { this.charge(2);
if (this.getEnergy() > cost) { }
updateInventory = true;
}
}
if (this.isBurning() && this.canOpen() && !this.isEmpty()) {
this.updateState();
this.progress++;
if (this.progress >= runTime) {
this.progress = 0;
this.recycleItems();
updateInventory = true;
}
} else {
if(this.isEmpty()) {
progress = 0;
}
this.updateState();
}
if (burning != this.isBurning()) {
updateInventory = true;
}
if (updateInventory) {
this.markDirty();
}
} }
public void recycleItems() { @Override
if (this.canOpen() && !this.world.isRemote) { public void readFromNBT(final NBTTagCompound tagCompound) {
List<IBaseRecipeType> scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe); super.readFromNBT(tagCompound);
int random = world.rand.nextInt(scrapboxRecipeList.size()); this.crafter.readFromNBT(tagCompound);
ItemStack out = scrapboxRecipeList.get(random).getOutput(0);
if (this.getStackInSlot(this.output).isEmpty()) {
this.useEnergy(cost);
this.setInventorySlotContents(this.output, out);
}
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.useEnergy(cost);
this.decrStackSize(this.input1, 1);
} else {
this.useEnergy(cost);
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
}
}
}
public boolean canOpen() {
List<IBaseRecipeType> scrapboxRecipeList = RecipeHandler.getRecipeClassFromName(Reference.scrapboxRecipe);
return !this.getStackInSlot(this.input1).isEmpty() && this.getStackInSlot(this.output).isEmpty()
&& scrapboxRecipeList.size() > 0;
}
public boolean isBurning() {
return this.getEnergy() > cost;
}
public void updateState() {
final IBlockState blockState = this.world.getBlockState(this.pos);
if (blockState.getBlock() instanceof BlockMachineBase) {
final BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if (blockState.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
}
} }
@Override @Override
public ItemStack getToolDrop(final EntityPlayer entityPlayer) { public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
return new ItemStack(ModBlocks.SCRAPBOXINATOR, 1); super.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
return tagCompound;
} }
public boolean isComplete() {
return false;
}
@Override @Override
public double getBaseMaxPower() { public double getBaseMaxPower() {
return maxEnergy; return maxEnergy;
} }
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@Override @Override
public double getBaseMaxOutput() { public double getBaseMaxOutput() {
return 0; return 0;
@ -181,30 +106,46 @@ public class TileScrapboxinator extends TilePowerAcceptor
public double getBaseMaxInput() { public double getBaseMaxInput() {
return maxInput; return maxInput;
} }
@Override
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
// TileLegacyMachineBase
@Override
public boolean canBeUpgraded() {
return false;
}
// IToolDrop
@Override
public ItemStack getToolDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.SCRAPBOXINATOR, 1);
}
//IInvetoryProvider
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return this.inventory; return this.inventory;
} }
@Override // IContainerProvider
public boolean canBeUpgraded() {
return false;
}
public int getProgress() {
return this.progress;
}
public void setProgress(final int progress) {
this.progress = progress;
}
@Override @Override
public BuiltContainer createContainer(final EntityPlayer player) { public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("scrapboxinator").player(player.inventory).inventory(8, 84).hotbar(8, 142) return new ContainerBuilder("scrapboxinator").player(player.inventory).inventory().hotbar().addInventory()
.addInventory().tile(this).filterSlot(0, 56, 34, stack -> stack.getItem() == ModItems.SCRAP_BOX) .tile(this).filterSlot(0, 55, 45, stack -> stack.getItem() == ModItems.SCRAP_BOX).outputSlot(1, 101, 45)
.outputSlot(1, 116, 35).syncEnergyValue().syncIntegerValue(this::getProgress, this::setProgress) .energySlot(2, 8, 72).syncEnergyValue().syncCrafterValue().addInventory().create(this);
.addInventory().create(this);
} }
}
// IRecipeCrafterProvider
@Override
public RecipeCrafter getRecipeCrafter() {
return this.crafter;
}
}