Finish up on recycler and temp jei handler

This commit is contained in:
gigabit101 2016-03-07 14:07:52 +00:00
parent 007f9266e5
commit 080b633493
10 changed files with 290 additions and 53 deletions

View file

@ -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";
}
}

View file

@ -39,6 +39,7 @@ public class GuiRecycler extends GuiContainer {
int j = 0; int j = 0;
j = compressor.gaugeProgressScaled(24); j = compressor.gaugeProgressScaled(24);
// System.out.println(compressor.gaugeProgressScaled(10));
if (j > 0) { if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16); this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
} }

View file

@ -20,4 +20,5 @@ public class RecipeCategoryUids {
public static final String EXTRACTOR = "TechReborn.Extractor"; public static final String EXTRACTOR = "TechReborn.Extractor";
public static final String COMPRESSOR = "TechReborn.Compressor"; public static final String COMPRESSOR = "TechReborn.Compressor";
public static final String SCRAPBOX = "TechReborn.Scrapbox"; public static final String SCRAPBOX = "TechReborn.Scrapbox";
public static final String RECYCLER = "TechReborn.Recycler";
} }

View file

@ -46,6 +46,8 @@ import techreborn.compat.jei.industrialGrinder.IndustrialGrinderRecipeCategory;
import techreborn.compat.jei.industrialGrinder.IndustrialGrinderRecipeHandler; import techreborn.compat.jei.industrialGrinder.IndustrialGrinderRecipeHandler;
import techreborn.compat.jei.industrialSawmill.IndustrialSawmillRecipeCategory; import techreborn.compat.jei.industrialSawmill.IndustrialSawmillRecipeCategory;
import techreborn.compat.jei.industrialSawmill.IndustrialSawmillRecipeHandler; 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.RollingMachineRecipeCategory;
import techreborn.compat.jei.rollingMachine.RollingMachineRecipeHandler; import techreborn.compat.jei.rollingMachine.RollingMachineRecipeHandler;
import techreborn.compat.jei.rollingMachine.RollingMachineRecipeMaker; import techreborn.compat.jei.rollingMachine.RollingMachineRecipeMaker;
@ -77,7 +79,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
new GrinderRecipeCategory(guiHelper), new GrinderRecipeCategory(guiHelper),
new ExtractorRecipeCategory(guiHelper), new ExtractorRecipeCategory(guiHelper),
new CompressorRecipeCategory(guiHelper), new CompressorRecipeCategory(guiHelper),
new ScrapboxRecipeCategory(guiHelper) new ScrapboxRecipeCategory(guiHelper),
new RecyclerRecipeCategory(guiHelper)
); );
registry.addRecipeHandlers( registry.addRecipeHandlers(
@ -96,7 +99,8 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
new GrinderRecipeHandler(jeiHelpers), new GrinderRecipeHandler(jeiHelpers),
new ExtractorRecipeHandler(jeiHelpers), new ExtractorRecipeHandler(jeiHelpers),
new CompressorRecipeHandler(jeiHelpers), new CompressorRecipeHandler(jeiHelpers),
new ScrapboxRecipeHandler(jeiHelpers) new ScrapboxRecipeHandler(jeiHelpers),
new RecyclerRecipeHandler(jeiHelpers)
); );
registry.addRecipes(RecipeHandler.recipeList); 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(GuiCompressor.class, 78, 36, 24, 16, RecipeCategoryUids.COMPRESSOR);
registry.addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, VanillaRecipeCategoryUid.FUEL); 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(GuiElectricFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING, VanillaRecipeCategoryUid.FUEL);
registry.addRecipeClickArea(GuiRecycler.class, 78, 36, 24, 16, RecipeCategoryUids.RECYCLER);
IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry(); IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry();

View file

@ -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);
}
}
}

View file

@ -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<RecyclerRecipe> {
@Nonnull
private final IJeiHelpers jeiHelpers;
public RecyclerRecipeHandler(@Nonnull IJeiHelpers jeiHelpers) {
this.jeiHelpers = jeiHelpers;
}
@Nonnull
@Override
public Class<RecyclerRecipe> 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;
}
}

View file

@ -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<RecyclerRecipe> {
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);
}
}

View file

@ -21,11 +21,35 @@ import techreborn.api.TechRebornAPI;
import techreborn.api.reactor.FusionReactorRecipe; import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper; import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.api.recipe.RecipeHandler; import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.RecyclerRecipe;
import techreborn.api.recipe.ScrapboxRecipe; import techreborn.api.recipe.ScrapboxRecipe;
import techreborn.api.recipe.machines.*; import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.blocks.*; 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.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.parts.ItemStandaloneCables;
import techreborn.utils.RecipeUtils; import techreborn.utils.RecipeUtils;
@ -200,6 +224,12 @@ public class ModRecipes {
for (int i = 0; i < ScrapboxList.stacks.size(); i++) { for (int i = 0; i < ScrapboxList.stacks.size(); i++) {
RecipeHandler.addRecipe(new ScrapboxRecipe(ScrapboxList.stacks.get(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){ static void registerDyable(Block block){

View file

@ -18,4 +18,5 @@ public class Reference {
public static String grinderRecipe = StatCollector.translateToLocal("tile.techreborn.grinder.name"); public static String grinderRecipe = StatCollector.translateToLocal("tile.techreborn.grinder.name");
public static String extractorRecipe = StatCollector.translateToLocal("tile.techreborn.extractor.name"); public static String extractorRecipe = StatCollector.translateToLocal("tile.techreborn.extractor.name");
public static String compressorRecipe = StatCollector.translateToLocal("tile.techreborn.compressor.name"); public static String compressorRecipe = StatCollector.translateToLocal("tile.techreborn.compressor.name");
public static String recyclerRecipe = StatCollector.translateToLocal("tile.techreborn.recycler.name");
} }

View file

@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent; import net.minecraft.util.IChatComponent;
@ -26,9 +27,11 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
public int capacity = 1000; public int capacity = 1000;
public int cost = 20; public int cost = 20;
public int progress; public int progress;
public int time = 800; public int time = 200;
public int chance = 4; public int chance = 4;
public int random; public int random;
public int input1 = 0;
public int output = 1;
public TileRecycler() { public TileRecycler() {
super(1); super(1);
@ -40,55 +43,92 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
} }
@Override @Override
public void updateEntity() public void updateEntity ()
{ {
boolean burning = isBurning();
boolean updateInventory = false; boolean updateInventory = false;
if(getEnergy() > cost) if (getEnergy() <= cost && canRecycle())
{ {
if(getStackInSlot(0) != null) if (getEnergy() > cost)
{ {
if(progress == 0) updateInventory = true;
{ }
int randchance = worldObj.rand.nextInt(chance);
random = randchance;
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;
}
}
}
} }
if (isBurning() && canRecycle())
{
updateState();
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(){ public void updateState(){