diff --git a/src/main/java/techreborn/api/recipe/RecyclerRecipe.java b/src/main/java/techreborn/api/recipe/RecyclerRecipe.java new file mode 100644 index 000000000..8cf4068d9 --- /dev/null +++ b/src/main/java/techreborn/api/recipe/RecyclerRecipe.java @@ -0,0 +1,22 @@ +package techreborn.api.recipe; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import techreborn.api.ScrapboxList; +import techreborn.init.ModItems; +import techreborn.items.ItemParts; +import techreborn.lib.Reference; +//THIS is only here to trick JEI into showing recipes for the recycler +public class RecyclerRecipe extends BaseRecipe { + + public RecyclerRecipe(ItemStack input) { + super(Reference.recyclerRecipe, 0, 0); + inputs.add(input); + addOutput(ItemParts.getPartByName("scrap")); + } + + @Override + public String getUserFreindlyName() { + return "Recycler"; + } +} diff --git a/src/main/java/techreborn/client/gui/GuiRecycler.java b/src/main/java/techreborn/client/gui/GuiRecycler.java index 06f55447e..bd1ba028c 100644 --- a/src/main/java/techreborn/client/gui/GuiRecycler.java +++ b/src/main/java/techreborn/client/gui/GuiRecycler.java @@ -39,6 +39,7 @@ public class GuiRecycler extends GuiContainer { int j = 0; j = compressor.gaugeProgressScaled(24); +// System.out.println(compressor.gaugeProgressScaled(10)); if (j > 0) { this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16); } diff --git a/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java b/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java index b6b8fb711..6a4a46ac5 100644 --- a/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java +++ b/src/main/java/techreborn/compat/jei/RecipeCategoryUids.java @@ -20,4 +20,5 @@ public class RecipeCategoryUids { public static final String EXTRACTOR = "TechReborn.Extractor"; public static final String COMPRESSOR = "TechReborn.Compressor"; public static final String SCRAPBOX = "TechReborn.Scrapbox"; + public static final String RECYCLER = "TechReborn.Recycler"; } diff --git a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java index 9c07201cf..336b2d1fb 100644 --- a/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java +++ b/src/main/java/techreborn/compat/jei/TechRebornJeiPlugin.java @@ -46,6 +46,8 @@ import techreborn.compat.jei.industrialGrinder.IndustrialGrinderRecipeCategory; import techreborn.compat.jei.industrialGrinder.IndustrialGrinderRecipeHandler; import techreborn.compat.jei.industrialSawmill.IndustrialSawmillRecipeCategory; import techreborn.compat.jei.industrialSawmill.IndustrialSawmillRecipeHandler; +import techreborn.compat.jei.recycler.RecyclerRecipeCategory; +import techreborn.compat.jei.recycler.RecyclerRecipeHandler; import techreborn.compat.jei.rollingMachine.RollingMachineRecipeCategory; import techreborn.compat.jei.rollingMachine.RollingMachineRecipeHandler; import techreborn.compat.jei.rollingMachine.RollingMachineRecipeMaker; @@ -77,7 +79,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin { new GrinderRecipeCategory(guiHelper), new ExtractorRecipeCategory(guiHelper), new CompressorRecipeCategory(guiHelper), - new ScrapboxRecipeCategory(guiHelper) + new ScrapboxRecipeCategory(guiHelper), + new RecyclerRecipeCategory(guiHelper) ); registry.addRecipeHandlers( @@ -96,7 +99,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin { new GrinderRecipeHandler(jeiHelpers), new ExtractorRecipeHandler(jeiHelpers), new CompressorRecipeHandler(jeiHelpers), - new ScrapboxRecipeHandler(jeiHelpers) + new ScrapboxRecipeHandler(jeiHelpers), + new RecyclerRecipeHandler(jeiHelpers) ); registry.addRecipes(RecipeHandler.recipeList); @@ -134,7 +138,7 @@ public class TechRebornJeiPlugin extends BlankModPlugin { registry.addRecipeClickArea(GuiCompressor.class, 78, 36, 24, 16, RecipeCategoryUids.COMPRESSOR); registry.addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, VanillaRecipeCategoryUid.FUEL); registry.addRecipeClickArea(GuiElectricFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, VanillaRecipeCategoryUid.FUEL); - + registry.addRecipeClickArea(GuiRecycler.class, 78, 36, 24, 16, RecipeCategoryUids.RECYCLER); IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry(); diff --git a/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeCategory.java b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeCategory.java new file mode 100644 index 000000000..0b30a72f5 --- /dev/null +++ b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeCategory.java @@ -0,0 +1,60 @@ +package techreborn.compat.jei.recycler; + +import javax.annotation.Nonnull; + +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.gui.IDrawable; +import mezz.jei.api.gui.IGuiItemStackGroup; +import mezz.jei.api.gui.IRecipeLayout; +import mezz.jei.api.recipe.BlankRecipeCategory; +import mezz.jei.api.recipe.IRecipeWrapper; +import net.minecraft.util.StatCollector; +import techreborn.client.gui.GuiCompressor; +import techreborn.client.gui.GuiGrinder; +import techreborn.client.gui.GuiRecycler; +import techreborn.compat.jei.RecipeCategoryUids; +import techreborn.compat.jei.RecipeUtil; + +public class RecyclerRecipeCategory extends BlankRecipeCategory { + private static final int[] INPUT_SLOTS = {0}; + private static final int[] OUTPUT_SLOTS = {1}; + + private final IDrawable background; + private final String title; + + public RecyclerRecipeCategory(IGuiHelper guiHelper) { + background = guiHelper.createDrawable(GuiRecycler.texture, 55, 30, 82, 26); + title = StatCollector.translateToLocal("tile.techreborn.recycler.name"); + } + + @Nonnull + @Override + public String getUid() { + return RecipeCategoryUids.RECYCLER; + } + + @Nonnull + @Override + public String getTitle() { + return title; + } + + @Nonnull + @Override + public IDrawable getBackground() { + return background; + } + + @Override + public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapper recipeWrapper) { + IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks(); + guiItemStacks.init(INPUT_SLOTS[0], true, 0, 3); + + guiItemStacks.init(OUTPUT_SLOTS[0], false, 60, 4); + + if (recipeWrapper instanceof RecyclerRecipeWrapper) { + RecyclerRecipeWrapper recipe = (RecyclerRecipeWrapper) recipeWrapper; + RecipeUtil.setRecipeItems(recipeLayout, recipe, INPUT_SLOTS, OUTPUT_SLOTS, null, null); + } + } +} diff --git a/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeHandler.java b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeHandler.java new file mode 100644 index 000000000..596b7304c --- /dev/null +++ b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeHandler.java @@ -0,0 +1,43 @@ +package techreborn.compat.jei.recycler; + +import javax.annotation.Nonnull; + +import mezz.jei.api.IJeiHelpers; +import mezz.jei.api.recipe.IRecipeHandler; +import mezz.jei.api.recipe.IRecipeWrapper; +import techreborn.api.recipe.RecyclerRecipe; +import techreborn.api.recipe.machines.CompressorRecipe; +import techreborn.api.recipe.machines.GrinderRecipe; +import techreborn.compat.jei.RecipeCategoryUids; + +public class RecyclerRecipeHandler implements IRecipeHandler { + @Nonnull + private final IJeiHelpers jeiHelpers; + + public RecyclerRecipeHandler(@Nonnull IJeiHelpers jeiHelpers) { + this.jeiHelpers = jeiHelpers; + } + + @Nonnull + @Override + public Class getRecipeClass() { + return RecyclerRecipe.class; + } + + @Nonnull + @Override + public String getRecipeCategoryUid() { + return RecipeCategoryUids.RECYCLER; + } + + @Nonnull + @Override + public IRecipeWrapper getRecipeWrapper(@Nonnull RecyclerRecipe recipe) { + return new RecyclerRecipeWrapper(jeiHelpers, recipe); + } + + @Override + public boolean isRecipeValid(@Nonnull RecyclerRecipe recipe) { + return true; + } +} diff --git a/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeWrapper.java b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeWrapper.java new file mode 100644 index 000000000..900fcc58c --- /dev/null +++ b/src/main/java/techreborn/compat/jei/recycler/RecyclerRecipeWrapper.java @@ -0,0 +1,35 @@ +package techreborn.compat.jei.recycler; + +import javax.annotation.Nonnull; + +import mezz.jei.api.IGuiHelper; +import mezz.jei.api.IJeiHelpers; +import mezz.jei.api.gui.IDrawableAnimated; +import mezz.jei.api.gui.IDrawableStatic; +import net.minecraft.client.Minecraft; +import techreborn.api.recipe.RecyclerRecipe; +import techreborn.api.recipe.machines.CompressorRecipe; +import techreborn.api.recipe.machines.GrinderRecipe; +import techreborn.client.gui.GuiCompressor; +import techreborn.client.gui.GuiGrinder; +import techreborn.client.gui.GuiRecycler; +import techreborn.compat.jei.BaseRecipeWrapper; + +public class RecyclerRecipeWrapper extends BaseRecipeWrapper { + private final IDrawableAnimated progress; + + public RecyclerRecipeWrapper(@Nonnull IJeiHelpers jeiHelpers, @Nonnull RecyclerRecipe baseRecipe) { + super(baseRecipe); + IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); + IDrawableStatic progressStatic = guiHelper.createDrawable(GuiRecycler.texture, 176, 14, 20, 11); + + int ticksPerCycle = baseRecipe.tickTime(); + this.progress = guiHelper.createAnimatedDrawable(progressStatic, ticksPerCycle, IDrawableAnimated.StartDirection.LEFT, false); + } + + @Override + public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight) { + super.drawAnimations(minecraft, recipeWidth, recipeHeight); + progress.draw(minecraft, 25, 7); + } +} diff --git a/src/main/java/techreborn/init/ModRecipes.java b/src/main/java/techreborn/init/ModRecipes.java index fb013847c..ebebec0ad 100644 --- a/src/main/java/techreborn/init/ModRecipes.java +++ b/src/main/java/techreborn/init/ModRecipes.java @@ -21,11 +21,35 @@ import techreborn.api.TechRebornAPI; import techreborn.api.reactor.FusionReactorRecipe; import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.recipe.RecipeHandler; +import techreborn.api.recipe.RecyclerRecipe; import techreborn.api.recipe.ScrapboxRecipe; -import techreborn.api.recipe.machines.*; -import techreborn.blocks.*; +import techreborn.api.recipe.machines.AlloySmelterRecipe; +import techreborn.api.recipe.machines.BlastFurnaceRecipe; +import techreborn.api.recipe.machines.CentrifugeRecipe; +import techreborn.api.recipe.machines.ChemicalReactorRecipe; +import techreborn.api.recipe.machines.CompressorRecipe; +import techreborn.api.recipe.machines.ExtractorRecipe; +import techreborn.api.recipe.machines.GrinderRecipe; +import techreborn.api.recipe.machines.ImplosionCompressorRecipe; +import techreborn.api.recipe.machines.IndustrialElectrolyzerRecipe; +import techreborn.api.recipe.machines.IndustrialGrinderRecipe; +import techreborn.api.recipe.machines.IndustrialSawmillRecipe; +import techreborn.api.recipe.machines.PlateCuttingMachineRecipe; +import techreborn.api.recipe.machines.VacuumFreezerRecipe; +import techreborn.blocks.BlockMachineFrame; +import techreborn.blocks.BlockOre; +import techreborn.blocks.BlockOre2; +import techreborn.blocks.BlockStorage; +import techreborn.blocks.BlockStorage2; import techreborn.config.ConfigTechReborn; -import techreborn.items.*; +import techreborn.items.ItemCells; +import techreborn.items.ItemDusts; +import techreborn.items.ItemDustsSmall; +import techreborn.items.ItemGems; +import techreborn.items.ItemIngots; +import techreborn.items.ItemNuggets; +import techreborn.items.ItemParts; +import techreborn.items.ItemPlates; import techreborn.parts.ItemStandaloneCables; import techreborn.utils.RecipeUtils; @@ -200,6 +224,12 @@ public class ModRecipes { for (int i = 0; i < ScrapboxList.stacks.size(); i++) { RecipeHandler.addRecipe(new ScrapboxRecipe(ScrapboxList.stacks.get(i))); } + + //just for jei + //TODO find a way to get all ItemStacks in mc + for (int i = 0; i < ScrapboxList.stacks.size() ; i++) { + RecipeHandler.addRecipe(new RecyclerRecipe(ScrapboxList.stacks.get(i))); + } } static void registerDyable(Block block){ diff --git a/src/main/java/techreborn/lib/Reference.java b/src/main/java/techreborn/lib/Reference.java index 1dbd01254..2f59ae25c 100644 --- a/src/main/java/techreborn/lib/Reference.java +++ b/src/main/java/techreborn/lib/Reference.java @@ -18,4 +18,5 @@ public class Reference { public static String grinderRecipe = StatCollector.translateToLocal("tile.techreborn.grinder.name"); public static String extractorRecipe = StatCollector.translateToLocal("tile.techreborn.extractor.name"); public static String compressorRecipe = StatCollector.translateToLocal("tile.techreborn.compressor.name"); + public static String recyclerRecipe = StatCollector.translateToLocal("tile.techreborn.recycler.name"); } diff --git a/src/main/java/techreborn/tiles/teir1/TileRecycler.java b/src/main/java/techreborn/tiles/teir1/TileRecycler.java index 066099055..5531472c5 100644 --- a/src/main/java/techreborn/tiles/teir1/TileRecycler.java +++ b/src/main/java/techreborn/tiles/teir1/TileRecycler.java @@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.IChatComponent; @@ -26,9 +27,11 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv public int capacity = 1000; public int cost = 20; public int progress; - public int time = 800; + public int time = 200; public int chance = 4; public int random; + public int input1 = 0; + public int output = 1; public TileRecycler() { super(1); @@ -38,59 +41,96 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv { return (progress * scale) / time; } - + @Override - public void updateEntity() + public void updateEntity () { + boolean burning = isBurning(); boolean updateInventory = false; - if(getEnergy() > cost) + if (getEnergy() <= cost && canRecycle()) { - if(getStackInSlot(0) != null) - { - if(progress == 0) - { - int randchance = worldObj.rand.nextInt(chance); - random = randchance; + if (getEnergy() > cost) + { + updateInventory = true; + } + } + if (isBurning() && canRecycle()) + { + updateState(); - if(getStackInSlot(0).stackSize > 1) - { - decrStackSize(0, 1); - } - if(getStackInSlot(0).stackSize == 1) - { - setInventorySlotContents(0, null); - } - updateInventory = true; - } - progress++; - - if(progress >= time) - { - if(random == 1) - { - if(getStackInSlot(1) == null) - { - setInventorySlotContents(1, ItemParts.getPartByName("scrap")); - progress = 0; - updateInventory = true; - } - else if(getStackInSlot(1).stackSize >= 1) - { - getStackInSlot(1).stackSize++; - progress = 0; - updateInventory = true; - } - } - if(random != 1) - { - progress = 0; - updateInventory = true; - } - } - } + progress++; + if (progress >= time) + { + progress = 0; + recycleItems(); + updateInventory = true; + } + } + else + { + progress = 0; + updateState(); + } + if (burning != isBurning()) + { + updateInventory = true; + } + if (updateInventory) + { + markDirty(); } } - + + public void recycleItems () + { + if (this.canRecycle()) + { + ItemStack itemstack = ItemParts.getPartByName("scrap"); + int randomchance = worldObj.rand.nextInt(chance); + + if (getStackInSlot(output) == null) + { + useEnergy(cost); + if(randomchance == 1) + { + setInventorySlotContents(output, itemstack.copy()); + } + } + else if (getStackInSlot(output).isItemEqual(itemstack)) + { + useEnergy(cost); + if(randomchance == 1) + { + getStackInSlot(output).stackSize += itemstack.stackSize; + } + } + if(getStackInSlot(input1).stackSize > 1) + { + useEnergy(cost); + this.decrStackSize(input1, 1); + } + else + { + useEnergy(cost); + setInventorySlotContents(input1, null); + } + } + } + + public boolean canRecycle () + { + if (getStackInSlot(input1) != null) + { + return true; + } + return false; + } + + public boolean isBurning () + { + return getEnergy() > cost; + } + public void updateState(){ IBlockState blockState = worldObj.getBlockState(pos); if(blockState.getBlock() instanceof BlockMachineBase){