diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index d298fd572..ba19133b5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -34,6 +34,7 @@ import de.ellpeck.actuallyadditions.api.recipe.OilGenRecipe; import de.ellpeck.actuallyadditions.api.recipe.TreasureChestLoot; import de.ellpeck.actuallyadditions.api.recipe.WeightedOre; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.Ingredient; @@ -200,9 +201,22 @@ public final class ActuallyAdditionsAPI{ * @param output The itemstack to be output from the compost once conversion finishes * @param outputDisplay The block to display when there is output in the compost */ + @Deprecated public static void addCompostRecipe(ItemStack input, Block inputDisplay, ItemStack output, Block outputDisplay){ COMPOST_RECIPES.add(new CompostRecipe(input, inputDisplay, output, outputDisplay)); } + + /** + * Adds a new conversion recipe to the compost. + * + * @param input The ingredient to be input into the compost + * @param inputDisplay The state to display when there is input in the compost + * @param output The itemstack to be output from the compost once conversion finishes + * @param outputDisplay The state to display when there is output in the compost + */ + public static void addCompostRecipe(Ingredient input, IBlockState inputDisplay, ItemStack output, IBlockState outputDisplay){ + COMPOST_RECIPES.add(new CompostRecipe(input, inputDisplay, output, outputDisplay)); + } /** * Adds an item to the list of possible items to be returned when right-clicking a Ball Of Fur @@ -226,9 +240,14 @@ public final class ActuallyAdditionsAPI{ TREASURE_CHEST_LOOT.add(new TreasureChestLoot(stack, chance, minAmount, maxAmount)); } + @Deprecated public static void addEmpowererRecipe(ItemStack input, ItemStack output, ItemStack modifier1, ItemStack modifier2, ItemStack modifier3, ItemStack modifier4, int energyPerStand, int time, float[] particleColor){ EMPOWERER_RECIPES.add(new EmpowererRecipe(input, output, modifier1, modifier2, modifier3, modifier4, energyPerStand, time, particleColor)); } + + public static void addEmpowererRecipe(Ingredient input, ItemStack output, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int time, float[] particleColor){ + EMPOWERER_RECIPES.add(new EmpowererRecipe(input, output, modifier1, modifier2, modifier3, modifier4, energyPerStand, time, particleColor)); + } /** * Adds a recipe to the Atomic Reconstructor conversion lenses @@ -240,13 +259,33 @@ public final class ActuallyAdditionsAPI{ * @param type The type of lens used for the conversion. To use the default type, use method below. * Note how this always has to be the same instance of the lens type that the item also has for it to work! */ + @Deprecated public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){ RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type)); } + @Deprecated public static void addReconstructorLensConversionRecipe(ItemStack input, ItemStack output, int energyUse){ addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); } + + /** + * Adds a recipe to the Atomic Reconstructor conversion lenses + * StackSizes can only be 1 and greater ones will be ignored + * + * @param input The input as an ItemStack + * @param output The output as an ItemStack + * @param energyUse The amount of RF used per conversion + * @param type The type of lens used for the conversion. To use the default type, use method below. + * Note how this always has to be the same instance of the lens type that the item also has for it to work! + */ + public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse, LensConversion type){ + RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type)); + } + + public static void addReconstructorLensConversionRecipe(Ingredient input, ItemStack output, int energyUse){ + addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); + } /** * Adds an item and the way it is modified to the Atomic Reconstructor's color lens. diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CoffeeIngredient.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CoffeeIngredient.java index 1e779b265..6ea8227a7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CoffeeIngredient.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CoffeeIngredient.java @@ -12,29 +12,47 @@ package de.ellpeck.actuallyadditions.api.recipe; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.potion.PotionEffect; -public class CoffeeIngredient{ +public class CoffeeIngredient { - public final ItemStack ingredient; - public final int maxAmplifier; + protected final Ingredient input; + protected final int maxAmplifier; protected PotionEffect[] effects; - public CoffeeIngredient(ItemStack ingredient, PotionEffect[] effects, int maxAmplifier){ - this.ingredient = ingredient.copy(); + @Deprecated + public CoffeeIngredient(ItemStack input, PotionEffect[] effects, int maxAmplifier) { + this(Ingredient.fromStacks(input), maxAmplifier, effects); + } + + public CoffeeIngredient(Ingredient input, int maxAmplifier, PotionEffect... effects) { + this.input = input; this.effects = effects; this.maxAmplifier = maxAmplifier; } + + public boolean matches(ItemStack stack) { + return input.apply(stack); + } + + public Ingredient getInput() { + return input; + } - public PotionEffect[] getEffects(){ + public PotionEffect[] getEffects() { return this.effects; } - public boolean effect(ItemStack stack){ + public boolean effect(ItemStack stack) { return ActuallyAdditionsAPI.methodHandler.addEffectToStack(stack, this); } - public String getExtraText(){ + public String getExtraText() { return ""; } + + public int getMaxAmplifier() { + return maxAmplifier; + } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CompostRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CompostRecipe.java index c527be271..447f53cb6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CompostRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CompostRecipe.java @@ -11,20 +11,47 @@ package de.ellpeck.actuallyadditions.api.recipe; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; public class CompostRecipe{ - public final ItemStack input; - public final ItemStack output; - public final Block inputDisplay; - public final Block outputDisplay; + protected final Ingredient input; + protected final ItemStack output; + protected final IBlockState inputDisplay; + protected final IBlockState outputDisplay; - public CompostRecipe(ItemStack input, Block inputDisplay, ItemStack output, Block outputDisplay){ + @Deprecated + public CompostRecipe(ItemStack input, Block inputDisplay, ItemStack output, Block outputDisplay) { + this(Ingredient.fromStacks(input), inputDisplay.getDefaultState(), output, outputDisplay.getDefaultState()); + } + + public CompostRecipe(Ingredient input, IBlockState inputDisplay, ItemStack output, IBlockState outputDisplay){ this.input = input; this.output = output; this.inputDisplay = inputDisplay; this.outputDisplay = outputDisplay; } + + public boolean matches(ItemStack stack) { + return input.apply(stack); + } + + public Ingredient getInput() { + return input; + } + + public ItemStack getOutput() { + return output; + } + + public IBlockState getInputDisplay() { + return inputDisplay; + } + + public IBlockState getOutputDisplay() { + return outputDisplay; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java index bf2c24683..2b2c248f5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java @@ -15,25 +15,21 @@ import net.minecraft.item.crafting.Ingredient; public class CrusherRecipe { - @Deprecated //ModTweaker compat, will be removed soon. - public ItemStack outputOneStack; - - private Ingredient input; - private ItemStack outputOne; - private ItemStack outputTwo; - private int outputChance; + protected Ingredient input; + protected ItemStack outputOne; + protected ItemStack outputTwo; + protected int outputChance; - @Deprecated //ModTweaker compat, will be removed soon. + @Deprecated public CrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputChance) { this(Ingredient.fromStacks(input), outputOne, outputTwo, outputChance); } - + public CrusherRecipe(Ingredient input, ItemStack outputOne, ItemStack outputTwo, int outputChance) { this.input = input; this.outputOne = outputOne; this.outputTwo = outputTwo; this.outputChance = outputChance; - outputOneStack = outputOne; } public boolean matches(ItemStack stack) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java index f21d8a2e3..f62199321 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/EmpowererRecipe.java @@ -11,22 +11,28 @@ package de.ellpeck.actuallyadditions.api.recipe; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; -public class EmpowererRecipe{ +public class EmpowererRecipe { - public ItemStack input; - public ItemStack output; + protected final Ingredient input; + protected final ItemStack output; - public ItemStack modifier1; - public ItemStack modifier2; - public ItemStack modifier3; - public ItemStack modifier4; + protected final Ingredient modifier1; + protected final Ingredient modifier2; + protected final Ingredient modifier3; + protected final Ingredient modifier4; - public int energyPerStand; - public float[] particleColor; - public int time; + protected final int energyPerStand; + protected final float[] particleColor; + protected final int time; - public EmpowererRecipe(ItemStack input, ItemStack output, ItemStack modifier1, ItemStack modifier2, ItemStack modifier3, ItemStack modifier4, int energyPerStand, int time, float[] particleColor){ + @Deprecated + public EmpowererRecipe(ItemStack input, ItemStack output, ItemStack modifier1, ItemStack modifier2, ItemStack modifier3, ItemStack modifier4, int energyPerStand, int time, float[] particleColor) { + this(Ingredient.fromStacks(input), output, Ingredient.fromStacks(modifier1), Ingredient.fromStacks(modifier2), Ingredient.fromStacks(modifier3), Ingredient.fromStacks(modifier4), energyPerStand, time, particleColor); + } + + public EmpowererRecipe(Ingredient input, ItemStack output, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3, Ingredient modifier4, int energyPerStand, int time, float[] particleColor) { this.input = input; this.output = output; this.modifier1 = modifier1; @@ -37,4 +43,44 @@ public class EmpowererRecipe{ this.particleColor = particleColor; this.time = time; } + + public boolean matches(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { + return input.apply(base) && modifier1.apply(stand1) && modifier2.apply(stand2) && modifier3.apply(stand3) && modifier4.apply(stand4); + } + + public Ingredient getInput() { + return input; + } + + public ItemStack getOutput() { + return output; + } + + public Ingredient getStandOne() { + return modifier1; + } + + public Ingredient getStandTwo() { + return modifier2; + } + + public Ingredient getStandThree() { + return modifier3; + } + + public Ingredient getStandFour() { + return modifier4; + } + + public int getTime() { + return time; + } + + public int getEnergyPerStand() { + return energyPerStand; + } + + public float[] getParticleColors() { + return particleColor; + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java index 22ce708dd..bcbcf936a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java @@ -11,24 +11,51 @@ package de.ellpeck.actuallyadditions.api.recipe; import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; -import de.ellpeck.actuallyadditions.api.lens.LensConversion; +import de.ellpeck.actuallyadditions.api.lens.Lens; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.math.BlockPos; -public class LensConversionRecipe{ +public class LensConversionRecipe { - public final int energyUse; - public final LensConversion type; - public ItemStack inputStack; - public ItemStack outputStack; + protected final Ingredient input; + protected final ItemStack output; + protected final int energy; + protected final Lens type; - public LensConversionRecipe(ItemStack input, ItemStack output, int energyUse, LensConversion type){ - this.inputStack = input; - this.outputStack = output; - this.energyUse = energyUse; + @Deprecated + public LensConversionRecipe(ItemStack input, ItemStack output, int energy, Lens type) { + this(Ingredient.fromStacks(input), output, energy, type); + } + + public LensConversionRecipe(Ingredient input, ItemStack output, int energy, Lens type) { + this.input = input; + this.output = output; + this.energy = energy; this.type = type; } - - public void transformHook(ItemStack stack, IBlockState state, BlockPos pos, IAtomicReconstructor tile) {} + + public boolean matches(ItemStack input, Lens lens) { + return this.input.apply(input) && this.type == lens; + } + + public Ingredient getInput() { + return input; + } + + public ItemStack getOutput() { + return output; + } + + public int getEnergyUsed() { + return energy; + } + + public Lens getType() { + return type; + } + + public void transformHook(ItemStack stack, IBlockState state, BlockPos pos, IAtomicReconstructor tile) { + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java index 89e32b777..c249b2f76 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ClientRegistryHandler.java @@ -1,5 +1,7 @@ package de.ellpeck.actuallyadditions.mod; +import de.ellpeck.actuallyadditions.mod.blocks.render.ActualCompostModel; +import de.ellpeck.actuallyadditions.mod.blocks.render.CompostModel; import de.ellpeck.actuallyadditions.mod.blocks.render.IHasModel; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.util.FluidStateMapper; @@ -7,6 +9,8 @@ import net.minecraft.block.Block; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.ModelBakeEvent; import net.minecraftforge.client.event.ModelRegistryEvent; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fluids.Fluid; @@ -48,4 +52,11 @@ public class ClientRegistryHandler{ registerCustomFluidBlockRenderer(InitFluids.fluidCrystalOil); registerCustomFluidBlockRenderer(InitFluids.fluidEmpoweredOil); } + + @SubscribeEvent + public void onModelBake(ModelBakeEvent e) { + ModelResourceLocation mrl = new ModelResourceLocation(new ResourceLocation(ActuallyAdditions.MODID, "block_compost"), "normal"); + CompostModel.compostBase = e.getModelRegistry().getObject(mrl); + e.getModelRegistry().putObject(mrl, new ActualCompostModel()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCompost.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCompost.java index 1418bffb1..5ed2f8f44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCompost.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCompost.java @@ -10,6 +10,10 @@ package de.ellpeck.actuallyadditions.mod.blocks; +import java.util.List; + +import org.apache.commons.lang3.tuple.Pair; + import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost; @@ -19,6 +23,8 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; @@ -27,6 +33,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; @@ -35,21 +42,22 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.property.ExtendedBlockState; +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.util.List; - -public class BlockCompost extends BlockContainerBase implements IHudDisplay{ +public class BlockCompost extends BlockContainerBase implements IHudDisplay { protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D); protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D); protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D); protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D); - private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1-0.0625, 11*0.0625, 1-0.0625); + private static final AxisAlignedBB AABB = new AxisAlignedBB(0.0625, 0, 0.0625, 1 - 0.0625, 11 * 0.0625, 1 - 0.0625); - public BlockCompost(String name){ + public BlockCompost(String name) { super(Material.WOOD, name); this.setHarvestLevel("axe", 0); this.setHardness(0.5F); @@ -58,12 +66,12 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{ } @Override - public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){ + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return AABB; } @Override - public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List collidingBoxes, Entity entityIn, boolean someBool){ + public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List collidingBoxes, Entity entityIn, boolean someBool) { addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH); @@ -72,41 +80,40 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{ } @Override - public boolean isOpaqueCube(IBlockState state){ + public boolean isOpaqueCube(IBlockState state) { return false; } @Override - public boolean isFullCube(IBlockState state){ + public boolean isFullCube(IBlockState state) { return false; } @Override - public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing f6, float f7, float f8, float f9){ + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing f6, float f7, float f8, float f9) { ItemStack stackPlayer = player.getHeldItem(hand); - if(!world.isRemote){ + if (!world.isRemote) { TileEntity tile = world.getTileEntity(pos); - if(tile instanceof TileEntityCompost){ - TileEntityCompost compost = (TileEntityCompost)tile; + if (tile instanceof TileEntityCompost) { + TileEntityCompost compost = (TileEntityCompost) tile; ItemStack slot = compost.inv.getStackInSlot(0); CompostRecipe recipeIn = TileEntityCompost.getRecipeForInput(slot); - if(!StackUtil.isValid(slot) || recipeIn != null){ - if(StackUtil.isValid(stackPlayer)){ + if (!StackUtil.isValid(slot) || recipeIn != null) { + if (StackUtil.isValid(stackPlayer)) { CompostRecipe recipeHand = TileEntityCompost.getRecipeForInput(stackPlayer); - if(recipeHand != null && (recipeIn == null || recipeIn == recipeHand)){ + if (recipeHand != null && (recipeIn == null || recipeIn == recipeHand)) { int maxAdd = stackPlayer.getCount(); - if(!StackUtil.isValid(slot)){ + if (!StackUtil.isValid(slot)) { ItemStack stackToAdd = stackPlayer.copy(); stackToAdd.setCount(maxAdd); compost.inv.setStackInSlot(0, stackToAdd); player.inventory.decrStackSize(player.inventory.currentItem, maxAdd); return true; - } - else{ + } else { ItemStack stackIn = slot.copy(); - if(stackIn.getCount() < recipeHand.input.getMaxStackSize()){ - int sizeAdded = Math.min(maxAdd, recipeHand.input.getMaxStackSize()-stackIn.getCount()); + if (stackIn.getCount() < slot.getMaxStackSize()) { + int sizeAdded = Math.min(maxAdd, slot.getMaxStackSize() - stackIn.getCount()); stackIn.grow(sizeAdded); compost.inv.setStackInSlot(0, stackIn); player.inventory.decrStackSize(player.inventory.currentItem, sizeAdded); @@ -115,15 +122,13 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{ } } } - } - else{ - if(!StackUtil.isValid(stackPlayer)){ + } else { + if (!StackUtil.isValid(stackPlayer)) { player.setHeldItem(hand, slot.copy()); compost.inv.setStackInSlot(0, StackUtil.getEmpty()); return true; - } - else if(ItemUtil.canBeStacked(stackPlayer, slot)){ - int addedStackSize = Math.min(slot.getCount(), stackPlayer.getMaxStackSize()-stackPlayer.getCount()); + } else if (ItemUtil.canBeStacked(stackPlayer, slot)) { + int addedStackSize = Math.min(slot.getCount(), stackPlayer.getMaxStackSize() - stackPlayer.getCount()); ItemStack stackToAdd = stackPlayer.copy(); stackToAdd.grow(addedStackSize); player.setHeldItem(hand, stackToAdd); @@ -132,41 +137,86 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{ } } + tile.markDirty(); + world.notifyBlockUpdate(pos, getDefaultState(), getDefaultState(), 3); } - } - else{ + } else { return true; } return false; } - @Override - public TileEntity createNewTileEntity(World world, int meta){ + public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityCompost(); } @Override - public EnumRarity getRarity(ItemStack stack){ + public EnumRarity getRarity(ItemStack stack) { return EnumRarity.UNCOMMON; } @Override @SideOnly(Side.CLIENT) - public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ + public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution) { TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos()); - if(tile instanceof TileEntityCompost){ - ItemStack slot = ((TileEntityCompost)tile).inv.getStackInSlot(0); + if (tile instanceof TileEntityCompost) { + ItemStack slot = ((TileEntityCompost) tile).inv.getStackInSlot(0); String strg; - if(!StackUtil.isValid(slot)){ + if (!StackUtil.isValid(slot)) { strg = "Empty"; - } - else{ + } else { strg = slot.getDisplayName(); - AssetUtil.renderStackToGui(slot, resolution.getScaledWidth()/2+15, resolution.getScaledHeight()/2-29, 1F); + AssetUtil.renderStackToGui(slot, resolution.getScaledWidth() / 2 + 15, resolution.getScaledHeight() / 2 - 29, 1F); } - minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW+""+TextFormatting.ITALIC+strg, resolution.getScaledWidth()/2+35, resolution.getScaledHeight()/2-25, StringUtil.DECIMAL_COLOR_WHITE); + minecraft.fontRenderer.drawStringWithShadow(TextFormatting.YELLOW + "" + TextFormatting.ITALIC + strg, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, StringUtil.DECIMAL_COLOR_WHITE); } } + + @Override + protected BlockStateContainer createBlockState() { + return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[] { COMPOST_PROP }); + } + + @Override + public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { + TileEntity te = world.getTileEntity(pos); + if (te instanceof TileEntityCompost && state instanceof IExtendedBlockState) { + TileEntityCompost compost = (TileEntityCompost) te; + return ((IExtendedBlockState) state).withProperty(COMPOST_PROP, Pair.of(compost.getCurrentDisplay(), compost.getHeight())); + } + return state; + } + + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.CUTOUT; + } + + public static CompostProperty COMPOST_PROP = new CompostProperty(); + + @SuppressWarnings("rawtypes") + private static class CompostProperty implements IUnlistedProperty { + + @Override + public String getName() { + return "compost"; + } + + @Override + public boolean isValid(Pair value) { + return true; + } + + @Override + public Class getType() { + return Pair.class; + } + + @Override + public String valueToString(Pair value) { + return ""; + } + + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java index b36d9a1a9..68ee9bf6e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockEmpowerer.java @@ -57,7 +57,7 @@ public class BlockEmpowerer extends BlockContainerBase{ if(empowerer != null){ ItemStack stackThere = empowerer.inv.getStackInSlot(0); if(StackUtil.isValid(heldItem)){ - if(!StackUtil.isValid(stackThere) && !TileEntityEmpowerer.getRecipesForInput(heldItem).isEmpty()){ + if(!StackUtil.isValid(stackThere) && TileEntityEmpowerer.isPossibleInput(heldItem)){ ItemStack toPut = heldItem.copy(); toPut.grow(1); empowerer.inv.setStackInSlot(0, toPut); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ActualCompostModel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ActualCompostModel.java new file mode 100644 index 000000000..0efcca4e5 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/ActualCompostModel.java @@ -0,0 +1,63 @@ +package de.ellpeck.actuallyadditions.mod.blocks.render; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; + +import de.ellpeck.actuallyadditions.mod.blocks.BlockCompost; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.property.IExtendedBlockState; + +public class ActualCompostModel implements IBakedModel { + + public static final Map, IBakedModel> MODELS = new HashMap<>(); + + @SuppressWarnings("unchecked") + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + if (state instanceof IExtendedBlockState) { + Pair data = ((IExtendedBlockState) state).getValue(BlockCompost.COMPOST_PROP); + if (data == null || data.getRight() <= 0) return CompostModel.compostBase.getQuads(state, side, rand); + IBakedModel model = MODELS.get(data); + if (model == null) { + model = new CompostModel(data.getLeft(), data.getRight()); + MODELS.put(data, model); + } + return model.getQuads(state, side, rand); + } + return CompostModel.compostBase.getQuads(state, side, rand); + } + + @Override + public boolean isAmbientOcclusion() { + return CompostModel.compostBase.isAmbientOcclusion(); + } + + @Override + public boolean isGui3d() { + return false; + } + + @Override + public boolean isBuiltInRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return CompostModel.compostBase.getParticleTexture(); + } + + @Override + public ItemOverrideList getOverrides() { + return ItemOverrideList.NONE; + } + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/CompostModel.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/CompostModel.java new file mode 100644 index 000000000..665029226 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/CompostModel.java @@ -0,0 +1,94 @@ +package de.ellpeck.actuallyadditions.mod.blocks.render; + +import java.util.EnumMap; +import java.util.List; + +import javax.annotation.Nullable; +import javax.vecmath.Vector3f; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.model.TRSRTransformation; + +public class CompostModel implements IBakedModel { + public static IBakedModel compostBase; + private final IBakedModel display; + private final ImmutableList general; + private final ImmutableMap> faces; + + public CompostModel(IBlockState flowerState, float height) { + this.display = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(flowerState); + + TRSRTransformation transform = TRSRTransformation.blockCenterToCorner(new TRSRTransformation(new Vector3f(0, -.218F, 0), null, new Vector3f(0.75F, height / 1.81F, 0.75F), null)); + + ImmutableList.Builder builder; + EnumMap> faces = new EnumMap<>(EnumFacing.class); + + for (EnumFacing face : EnumFacing.values()) { + builder = ImmutableList.builder(); + if (!display.isBuiltInRenderer()) { + for (BakedQuad quad : display.getQuads(flowerState, face, 0)) { + Transformer transformer = new Transformer(transform, quad.getFormat()); + quad.pipe(transformer); + builder.add(transformer.build()); + } + builder.addAll(compostBase.getQuads(null, face, 0)); + } + faces.put(face, builder.build()); + } + + if (!display.isBuiltInRenderer()) { + builder = ImmutableList.builder(); + for (BakedQuad quad : display.getQuads(flowerState, null, 0)) { + Transformer transformer = new Transformer(transform, quad.getFormat()); + quad.pipe(transformer); + builder.add(transformer.build()); + } + builder.addAll(compostBase.getQuads(null, null, 0)); + this.general = builder.build(); + } else general = ImmutableList.of(); + + this.faces = Maps.immutableEnumMap(faces); + } + + @Override + public List getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { + if (side == null) return general; + return faces.get(side); + } + + @Override + public boolean isAmbientOcclusion() { + return compostBase.isAmbientOcclusion() && display.isAmbientOcclusion(); + } + + @Override + public boolean isGui3d() { + return false; + } + + @Override + public boolean isBuiltInRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return compostBase.getParticleTexture(); + } + + @Override + public ItemOverrideList getOverrides() { + return ItemOverrideList.NONE; + } + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderCompost.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderCompost.java deleted file mode 100644 index 1fd4a90bb..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderCompost.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file ("RenderCompost.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - -package de.ellpeck.actuallyadditions.mod.blocks.render; - -import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; -import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost; -import de.ellpeck.actuallyadditions.mod.util.AssetUtil; -import de.ellpeck.actuallyadditions.mod.util.StackUtil; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class RenderCompost extends TileEntitySpecialRenderer{ - - @Override - public void render(TileEntityCompost compost, double x, double y, double z, float partialTicks, int destroyStage, float f){ - if(compost instanceof TileEntityCompost){ - ItemStack slot = compost.inv.getStackInSlot(0); - - if(StackUtil.isValid(slot)){ - Block display = null; - int maxAmount = 0; - for(CompostRecipe aRecipe : ActuallyAdditionsAPI.COMPOST_RECIPES){ - if(slot.isItemEqual(aRecipe.input)){ - display = aRecipe.inputDisplay; - maxAmount = aRecipe.input.getMaxStackSize(); - break; - } - else if(slot.isItemEqual(aRecipe.output)){ - display = aRecipe.outputDisplay; - maxAmount = aRecipe.output.getMaxStackSize(); - break; - } - } - if(display != null){ - float i = (float)slot.getCount()/(float)maxAmount; - GlStateManager.pushMatrix(); - GlStateManager.translate((float)x+0.5F, (float)y+(i/3F)+0.01F, (float)z+0.5F); - //Hehe - if("ShadowfactsDev".equals(Minecraft.getMinecraft().player.getName())){ - GlStateManager.translate(0F, 1F, 0F); - } - GlStateManager.scale(1.5F, i, 1.5F); - AssetUtil.renderBlockInWorld(display, 0); - GlStateManager.popMatrix(); - } - } - } - } - -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java index 025b3f1d6..7bf28ae98 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java @@ -64,7 +64,7 @@ public class RenderEmpowerer extends TileEntitySpecialRenderer= 3) { + Vector4f vec = new Vector4f(data); + vec.setW(1.0f); + transformation.transform(vec); + data = new float[4]; + vec.get(data); + } else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { + Vector3f vec = new Vector3f(data); + normalTransformation.transform(vec); + vec.normalize(); + data = new float[4]; + vec.get(data); + } + super.put(element, data); + } + + public UnpackedBakedQuad build() { + return ((UnpackedBakedQuad.Builder) parent).build(); + } +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java index 4e5c87b43..907262b09 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java @@ -47,6 +47,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.Ingredient; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidUtil; @@ -185,7 +186,7 @@ public final class InitBooklet{ //Reconstruction chaptersIntroduction[7] = new BookletChapter("reconstructorLenses", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.LENS.ordinal()), new PageTextOnly(1)).setImportant(); new BookletChapter("additionalRecipes", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(Items.LEATHER), new PageReconstructor(1, LensRecipeHandler.recipeSoulSand).setNoText(), new PageReconstructor(2, LensRecipeHandler.recipeLeather).setNoText(), new PageReconstructor(3, LensRecipeHandler.recipeNetherWart).setNoText(), new PageReconstructor(4, LensRecipeHandler.recipePrismarine).setNoText()).setSpecial(); - new BookletChapter("bookSplitting", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(Items.ENCHANTED_BOOK), new PageTextOnly(1), new PageReconstructor(2, new LensConversionRecipe(new ItemStack(Items.ENCHANTED_BOOK), new ItemStack(Items.ENCHANTED_BOOK), 0, ActuallyAdditionsAPI.lensDefaultConversion)).setNoText()); + new BookletChapter("bookSplitting", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(Items.ENCHANTED_BOOK), new PageTextOnly(1), new PageReconstructor(2, new LensConversionRecipe(Ingredient.fromItem(Items.ENCHANTED_BOOK), new ItemStack(Items.ENCHANTED_BOOK), 0, ActuallyAdditionsAPI.lensDefaultConversion)).setNoText()); new BookletChapter("lensColor", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(InitItems.itemColorLens), new PageTextOnly(1), new PageReconstructor(2, LensRecipeHandler.recipeColorLens).setNoText()); new BookletChapter("lensDeath", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(InitItems.itemDamageLens), new PageTextOnly(1), new PageReconstructor(2, LensRecipeHandler.recipeDamageLens).setNoText()); new BookletChapter("lensMoreDeath", ActuallyAdditionsAPI.entryReconstruction, new ItemStack(InitItems.itemMoreDamageLens), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeLensMoreDeath).setNoText()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCoffeeMachine.java index 242de69c0..5cb602152 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCoffeeMachine.java @@ -27,10 +27,14 @@ public class PageCoffeeMachine extends BookletPage{ private final CoffeeIngredient ingredient; private final ItemStack outcome; + private int counter = 0; + private int rotate = 0; + private final ItemStack[] stacks; public PageCoffeeMachine(int localizationKey, CoffeeIngredient ingredient){ super(localizationKey); this.ingredient = ingredient; + this.stacks = ingredient.getInput().getMatchingStacks(); this.outcome = new ItemStack(InitItems.itemCoffee); ActuallyAdditionsAPI.methodHandler.addEffectToStack(this.outcome, this.ingredient); @@ -48,6 +52,8 @@ public class PageCoffeeMachine extends BookletPage{ gui.renderSplitScaledAsciiString("Hover over this to see the effect!", startX+5, startY+51, 0, false, gui.getSmallFontSize(), 35); PageTextOnly.renderTextToPage(gui, this, startX+6, startY+90); + + if(counter++ % 50 == 0) gui.addOrModifyItemRenderer(stacks[rotate++ % stacks.length], startX+5+82, startY+10+1, 1F, true); } @Override @@ -55,7 +61,7 @@ public class PageCoffeeMachine extends BookletPage{ public void initGui(GuiBookletBase gui, int startX, int startY){ super.initGui(gui, startX, startY); - gui.addOrModifyItemRenderer(this.ingredient.ingredient, startX+5+82, startY+10+1, 1F, true); + gui.addOrModifyItemRenderer(stacks[0], startX+5+82, startY+10+1, 1F, true); gui.addOrModifyItemRenderer(this.outcome, startX+5+36, startY+10+42, 1F, false); gui.addOrModifyItemRenderer(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CUP.ordinal()), startX+5+37, startY+10+1, 1F, true); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java index 0ed1f1057..de17fb76f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java @@ -48,7 +48,7 @@ public class PageCrusherRecipe extends BookletPage{ PageTextOnly.renderTextToPage(gui, this, startX+6, startY+100); - if(counter++ % 50 == 0)gui.addOrModifyItemRenderer(stacks[rotate++ % stacks.length], startX+38+18, startY+6+1, 1F, true); + if(counter++ % 50 == 0) gui.addOrModifyItemRenderer(stacks[rotate++ % stacks.length], startX+38+18, startY+6+1, 1F, true); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageEmpowerer.java index 157b544e0..58a8e63b0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageEmpowerer.java @@ -25,10 +25,24 @@ import java.util.List; public class PageEmpowerer extends BookletPage{ private final EmpowererRecipe recipe; + private int counter = 0; + private int rotate = 0; + ItemStack[] inputs; + ItemStack[] stand1; + ItemStack[] stand2; + ItemStack[] stand3; + ItemStack[] stand4; public PageEmpowerer(int localizationKey, EmpowererRecipe recipe){ super(localizationKey); this.recipe = recipe; + if(recipe != null) { + this.inputs = recipe.getInput().getMatchingStacks(); + this.stand1 = recipe.getStandOne().getMatchingStacks(); + this.stand2 = recipe.getStandTwo().getMatchingStacks(); + this.stand3 = recipe.getStandThree().getMatchingStacks(); + this.stand4 = recipe.getStandFour().getMatchingStacks(); + } } @Override @@ -42,6 +56,7 @@ public class PageEmpowerer extends BookletPage{ gui.renderScaledAsciiString("("+StringUtil.localize("booklet."+ActuallyAdditions.MODID+".empowererRecipe")+")", startX+6, startY+85, 0, false, gui.getMediumFontSize()); PageTextOnly.renderTextToPage(gui, this, startX+6, startY+100); + if(recipe != null) updateInputs(gui, startX, startY); } @Override @@ -50,13 +65,25 @@ public class PageEmpowerer extends BookletPage{ super.initGui(gui, startX, startY); if(this.recipe != null){ - gui.addOrModifyItemRenderer(this.recipe.modifier1, startX+5+26, startY+10+1, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.modifier2, startX+5+1, startY+10+26, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.modifier3, startX+5+51, startY+10+26, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.modifier4, startX+5+26, startY+10+51, 1F, true); + gui.addOrModifyItemRenderer(stand1[0], startX+5+26, startY+10+1, 1F, true); + gui.addOrModifyItemRenderer(stand2[0], startX+5+1, startY+10+26, 1F, true); + gui.addOrModifyItemRenderer(stand3[0], startX+5+51, startY+10+26, 1F, true); + gui.addOrModifyItemRenderer(stand4[0], startX+5+26, startY+10+51, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.input, startX+5+26, startY+10+26, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.output, startX+5+96, startY+10+26, 1F, false); + gui.addOrModifyItemRenderer(inputs[0], startX+5+26, startY+10+26, 1F, true); + gui.addOrModifyItemRenderer(this.recipe.getOutput(), startX+5+96, startY+10+26, 1F, false); + } + } + + private void updateInputs(GuiBookletBase gui, int startX, int startY) { + if(counter++ % 50 == 0) { + rotate++; + gui.addOrModifyItemRenderer(stand1[rotate % stand1.length], startX+5+26, startY+10+1, 1F, true); + gui.addOrModifyItemRenderer(stand2[rotate % stand2.length], startX+5+1, startY+10+26, 1F, true); + gui.addOrModifyItemRenderer(stand3[rotate % stand3.length], startX+5+51, startY+10+26, 1F, true); + gui.addOrModifyItemRenderer(stand4[rotate % stand4.length], startX+5+26, startY+10+51, 1F, true); + + gui.addOrModifyItemRenderer(inputs[rotate % inputs.length], startX+5+26, startY+10+26, 1F, true); } } @@ -65,7 +92,7 @@ public class PageEmpowerer extends BookletPage{ super.getItemStacksForPage(list); if(this.recipe != null){ - list.add(this.recipe.output); + list.add(this.recipe.getOutput()); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java index 772a879cf..da35f3aeb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java @@ -27,10 +27,15 @@ public class PageReconstructor extends BookletPage{ private final LensConversionRecipe recipe; private boolean isWildcard; + private int counter = 0; + private int rotate = 0; + private ItemStack[] stacks; + public PageReconstructor(int localizationKey, LensConversionRecipe recipe){ super(localizationKey); this.recipe = recipe; + if(recipe != null) this.stacks = recipe.getInput().getMatchingStacks(); } @Override @@ -44,6 +49,9 @@ public class PageReconstructor extends BookletPage{ gui.renderScaledAsciiString("("+StringUtil.localize("booklet."+ActuallyAdditions.MODID+".reconstructorRecipe")+")", startX+6, startY+63, 0, false, gui.getMediumFontSize()); PageTextOnly.renderTextToPage(gui, this, startX+6, startY+88); + if(this.recipe != null){ + if(counter++ % 50 == 0) gui.addOrModifyItemRenderer(stacks[rotate++ % stacks.length], startX+30+1, startY+10+13, 1F, true); + } } @Override @@ -52,8 +60,8 @@ public class PageReconstructor extends BookletPage{ super.initGui(gui, startX, startY); if(this.recipe != null){ - gui.addOrModifyItemRenderer(this.recipe.inputStack, startX+30+1, startY+10+13, 1F, true); - gui.addOrModifyItemRenderer(this.recipe.outputStack, startX+30+47, startY+10+13, 1F, false); + gui.addOrModifyItemRenderer(stacks[0], startX+30+1, startY+10+13, 1F, true); + gui.addOrModifyItemRenderer(this.recipe.getOutput(), startX+30+47, startY+10+13, 1F, false); } } @@ -62,7 +70,7 @@ public class PageReconstructor extends BookletPage{ super.getItemStacksForPage(list); if(this.recipe != null){ - ItemStack copy = this.recipe.outputStack.copy(); + ItemStack copy = this.recipe.getOutput().copy(); if(this.isWildcard){ copy.setItemDamage(Util.WILDCARD); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java index 15879896c..28a3ff0af 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java @@ -16,11 +16,16 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; -import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.*; +import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.CactusFarmerBehavior; +import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.DefaultFarmerBehavior; +import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.MelonPumpkinFarmerBehavior; +import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.NetherWartFarmerBehavior; +import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.ReedFarmerBehavior; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.exu.EnderlillyFarmerBehavior; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.exu.RedOrchidFarmerBehavior; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; public final class InitCrafting{ @@ -34,8 +39,8 @@ public final class InitCrafting{ FoodCrafting.init(); ToolCrafting.init(); - ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.MASHED_FOOD.ordinal()), Blocks.LEAVES, new ItemStack(InitItems.itemFertilizer), Blocks.DIRT); - ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemCanolaSeed), Blocks.DIRT, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND); + ActuallyAdditionsAPI.addCompostRecipe(Ingredient.fromStacks(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.MASHED_FOOD.ordinal())), Blocks.LEAVES.getDefaultState(), new ItemStack(InitItems.itemFertilizer), Blocks.DIRT.getDefaultState()); + ActuallyAdditionsAPI.addCompostRecipe(Ingredient.fromItem(InitItems.itemCanolaSeed), Blocks.DIRT.getDefaultState(), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND.getDefaultState()); int[] power = ConfigIntListValues.OIL_POWER.getValue(); int[] time = ConfigIntListValues.OIL_TIME.getValue(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java index 65fa31c51..ef1e8bbb2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/ClientEvents.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.event; +import java.util.Locale; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay; import de.ellpeck.actuallyadditions.mod.config.ConfigValues; @@ -46,8 +48,6 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.oredict.OreDictionary; -import java.util.Locale; - @SideOnly(Side.CLIENT) public class ClientEvents{ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java index 6bbc6ff81..f476dea04 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java @@ -10,6 +10,10 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; +import java.io.IOException; + +import org.lwjgl.input.Keyboard; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.inventory.ContainerInputter; import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; @@ -20,18 +24,14 @@ import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.input.Keyboard; - -import java.io.IOException; @SideOnly(Side.CLIENT) -public class GuiInputter extends GuiContainer{ +public class GuiInputter extends GuiWtfMojang{ public static final int OFFSET_ADVANCED = 12+36; public static final String[] SIDES = new String[]{ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java index ab483bf7e..55a1bd5de 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCoffee.java @@ -10,6 +10,11 @@ package de.ellpeck.actuallyadditions.mod.items; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nullable; + import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; @@ -25,16 +30,13 @@ import net.minecraft.item.EnumAction; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.PotionEffect; import net.minecraft.util.StringUtils; import net.minecraft.world.World; import net.minecraftforge.fml.common.Loader; -import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.List; - public class ItemCoffee extends ItemFoodBase{ public ItemCoffee(String name){ @@ -46,29 +48,28 @@ public class ItemCoffee extends ItemFoodBase{ } public static void initIngredients(){ - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(new ItemStack(Items.MILK_BUCKET))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.fromItem(Items.MILK_BUCKET))); //Pam's Soy Milk (For Jemx because he's lactose intolerant. YER HAPPY NAO!?) if(Loader.isModLoaded("harvestcraft")){ Item item = ItemUtil.getItemFromName("harvestcraft:soymilkItem"); if(item != null){ - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(new ItemStack(item))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new MilkIngredient(Ingredient.fromItem(item))); } } - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.SUGAR), new PotionEffect[]{new PotionEffect(MobEffects.SPEED, 30, 0)}, 4)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.MAGMA_CREAM), new PotionEffect[]{new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0)}, 2)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.FISH, 1, 3), new PotionEffect[]{new PotionEffect(MobEffects.WATER_BREATHING, 10, 0)}, 2)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.GOLDEN_CARROT), new PotionEffect[]{new PotionEffect(MobEffects.NIGHT_VISION, 30, 0)}, 2)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.GHAST_TEAR), new PotionEffect[]{new PotionEffect(MobEffects.REGENERATION, 5, 0)}, 3)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.BLAZE_POWDER), new PotionEffect[]{new PotionEffect(MobEffects.STRENGTH, 15, 0)}, 4)); - ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(new ItemStack(Items.FERMENTED_SPIDER_EYE), new PotionEffect[]{new PotionEffect(MobEffects.INVISIBILITY, 25, 0)}, 2)); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.SUGAR), 4, new PotionEffect(MobEffects.SPEED, 30, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.MAGMA_CREAM), 2, new PotionEffect(MobEffects.FIRE_RESISTANCE, 20, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromStacks(new ItemStack(Items.FISH, 1, 3)), 2, new PotionEffect(MobEffects.WATER_BREATHING, 10, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.GOLDEN_CARROT), 2, new PotionEffect(MobEffects.NIGHT_VISION, 30, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.GHAST_TEAR), 3, new PotionEffect(MobEffects.REGENERATION, 5, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.BLAZE_POWDER), 4, new PotionEffect(MobEffects.STRENGTH, 15, 0))); + ActuallyAdditionsAPI.addCoffeeMachineIngredient(new CoffeeIngredient(Ingredient.fromItems(Items.FERMENTED_SPIDER_EYE), 2, new PotionEffect(MobEffects.INVISIBILITY, 25, 0))); } + @Nullable public static CoffeeIngredient getIngredientFromStack(ItemStack stack){ for(CoffeeIngredient ingredient : ActuallyAdditionsAPI.COFFEE_MACHINE_INGREDIENTS){ - if(ingredient.ingredient.copy().isItemEqual(stack)){ - return ingredient; - } + if(ingredient.getInput().apply(stack)) return ingredient; } return null; } @@ -132,8 +133,8 @@ public class ItemCoffee extends ItemFoodBase{ public static class MilkIngredient extends CoffeeIngredient{ - public MilkIngredient(ItemStack ingredient){ - super(ingredient, null, 0); + public MilkIngredient(Ingredient ingredient){ + super(ingredient, 0); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java index ba758f217..220e5ebef 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java @@ -11,8 +11,12 @@ package de.ellpeck.actuallyadditions.mod.items.lens; import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nullable; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.api.recipe.ColorLensChangerByDyeMeta; import de.ellpeck.actuallyadditions.api.recipe.IColorLensChanger; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; @@ -21,12 +25,13 @@ import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; import de.ellpeck.actuallyadditions.mod.recipe.EnchBookConversion; -import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.RecipeUtil; +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; public final class LensRecipeHandler{ @@ -47,65 +52,65 @@ public final class LensRecipeHandler{ public static void init(){ //Crystal Blocks - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.REDSTONE_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.REDSTONE.ordinal()), 400); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.REDSTONE_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.REDSTONE.ordinal()), 400); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.LAPIS_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.LAPIS.ordinal()), 400); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.LAPIS_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.LAPIS.ordinal()), 400); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.DIAMOND_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.DIAMOND.ordinal()), 600); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.DIAMOND_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.DIAMOND.ordinal()), 600); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.EMERALD_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.EMERALD.ordinal()), 1000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.EMERALD_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.EMERALD.ordinal()), 1000); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.COAL_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.COAL.ordinal()), 600); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.COAL_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.COAL.ordinal()), 600); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.IRON_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.IRON.ordinal()), 800); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.IRON_BLOCK), new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.IRON.ordinal()), 800); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); //Crystal Items - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.REDSTONE), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.REDSTONE.ordinal()), 40); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.REDSTONE), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.REDSTONE.ordinal()), 40); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.DYE, 1, 4), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.LAPIS.ordinal()), 40); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromStacks(new ItemStack(Items.DYE, 1, 4)), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.LAPIS.ordinal()), 40); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.DIAMOND), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.DIAMOND.ordinal()), 60); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.DIAMOND), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.DIAMOND.ordinal()), 60); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.EMERALD), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.EMERALD.ordinal()), 100); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.EMERALD), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.EMERALD.ordinal()), 100); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.COAL), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.COAL.ordinal()), 60); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.COAL), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.COAL.ordinal()), 60); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.IRON_INGOT), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.IRON.ordinal()), 80); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.IRON_INGOT), new ItemStack(InitItems.itemCrystal, 1, TheCrystals.IRON.ordinal()), 80); MAIN_PAGE_RECIPES.add(RecipeUtil.lastReconstructorRecipe()); //Lenses - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.LENS.ordinal()), new ItemStack(InitItems.itemColorLens), 5000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromStacks(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.LENS.ordinal())), new ItemStack(InitItems.itemColorLens), 5000); recipeColorLens = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitItems.itemColorLens), new ItemStack(InitItems.itemExplosionLens), 5000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(InitItems.itemColorLens), new ItemStack(InitItems.itemExplosionLens), 5000); recipeExplosionLens = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitItems.itemExplosionLens), new ItemStack(InitItems.itemDamageLens), 5000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(InitItems.itemExplosionLens), new ItemStack(InitItems.itemDamageLens), 5000); recipeDamageLens = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitItems.itemDamageLens), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.LENS.ordinal()), 5000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(InitItems.itemDamageLens), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.LENS.ordinal()), 5000); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitBlocks.blockLaserRelay), new ItemStack(InitBlocks.blockLaserRelayFluids), 2000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(InitBlocks.blockLaserRelay), new ItemStack(InitBlocks.blockLaserRelayFluids), 2000); recipeFluidLaser = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitBlocks.blockLaserRelayFluids), new ItemStack(InitBlocks.blockLaserRelayItem), 2000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(InitBlocks.blockLaserRelayFluids), new ItemStack(InitBlocks.blockLaserRelayItem), 2000); recipeItemLaser = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitBlocks.blockLaserRelayItem), new ItemStack(InitBlocks.blockLaserRelay), 2000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(InitBlocks.blockLaserRelayItem), new ItemStack(InitBlocks.blockLaserRelay), 2000); //Misc - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.SAND), new ItemStack(Blocks.SOUL_SAND), 20000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.SAND), new ItemStack(Blocks.SOUL_SAND), 20000); recipeSoulSand = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.ROTTEN_FLESH), new ItemStack(Items.LEATHER), 8000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.ROTTEN_FLESH), new ItemStack(Items.LEATHER), 8000); recipeLeather = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.RED_MUSHROOM), new ItemStack(Items.NETHER_WART), 150000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.RED_MUSHROOM), new ItemStack(Items.NETHER_WART), 150000); recipeNetherWart = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Items.QUARTZ), new ItemStack(Items.PRISMARINE_SHARD), 30000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(Items.QUARTZ), new ItemStack(Items.PRISMARINE_SHARD), 30000); recipePrismarine = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(InitItems.itemCanolaSeed), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CRYSTALLIZED_CANOLA_SEED.ordinal()), 2000); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromItem(InitItems.itemCanolaSeed), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CRYSTALLIZED_CANOLA_SEED.ordinal()), 2000); recipeCrystallizedCanolaSeed = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.QUARTZ_BLOCK), new ItemStack(InitBlocks.blockTestifiBucksWhiteWall), 10); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(fromBlock(Blocks.QUARTZ_BLOCK), new ItemStack(InitBlocks.blockTestifiBucksWhiteWall), 10); recipeWhiteWall = RecipeUtil.lastReconstructorRecipe(); - ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 1), new ItemStack(InitBlocks.blockTestifiBucksGreenWall), 10); + ActuallyAdditionsAPI.addReconstructorLensConversionRecipe(Ingredient.fromStacks(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 1)), new ItemStack(InitBlocks.blockTestifiBucksGreenWall), 10); recipeGreenWall = RecipeUtil.lastReconstructorRecipe(); ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(recipeEnchBook = new EnchBookConversion()); @@ -121,13 +126,22 @@ public final class LensRecipeHandler{ ActuallyAdditionsAPI.addReconstructorLensColorChangeItem(Item.getItemFromBlock(InitBlocks.blockColoredLampOn), changer); } - public static ArrayList getRecipesFor(ItemStack input){ - ArrayList possibleRecipes = new ArrayList(); - for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES){ - if(ItemUtil.areItemsEqual(recipe.inputStack, input, true)){ - possibleRecipes.add(recipe); - } - } + @Deprecated //Use lens-checking method below. + public static List getRecipesFor(ItemStack input){ + List possibleRecipes = new ArrayList<>(); + for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) + if(recipe.getInput().apply(input)) possibleRecipes.add(recipe); return possibleRecipes; } + + @Nullable + public static LensConversionRecipe findMatchingRecipe(ItemStack input, Lens lens){ + for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES) + if(recipe.matches(input, lens)) return recipe; + return null; + } + + private static Ingredient fromBlock(Block b) { + return Ingredient.fromItem(Item.getItemFromBlock(b)); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeCategory.java index 8a6c6ebb2..a5e37b972 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/coffee/CoffeeMachineRecipeCategory.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.jei.coffee; +import java.util.Arrays; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; @@ -52,7 +54,7 @@ public class CoffeeMachineRecipeCategory implements IRecipeCategory list = new ArrayList(); - list.add(this.theIngredient.ingredient); + public void getIngredients(IIngredients ingredients) { + List list = new ArrayList<>(); + for(ItemStack s : ingredient.getInput().getMatchingStacks()) + list.add(s); list.add(this.cup); list.add(this.coffeeBeans); ingredients.setInputs(ItemStack.class, list); - + ingredients.setOutput(ItemStack.class, this.theOutput); } @Override - public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ - if(this.theIngredient.getExtraText() != null){ - minecraft.fontRenderer.drawString(StringUtil.localize("container.nei."+ActuallyAdditions.MODID+".coffee.special")+":", 2, 4, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); - minecraft.fontRenderer.drawString(this.theIngredient.getExtraText(), 2, 16, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { + if (!Strings.isNullOrEmpty(this.ingredient.getExtraText())) { + minecraft.fontRenderer.drawString(StringUtil.localize("container.nei." + ActuallyAdditions.MODID + ".coffee.special") + ":", 2, 4, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + minecraft.fontRenderer.drawString(this.ingredient.getExtraText(), 2, 16, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); } - if(this.theIngredient.maxAmplifier > 0){ - minecraft.fontRenderer.drawString(StringUtil.localize("container.nei."+ActuallyAdditions.MODID+".coffee.maxAmount")+": "+this.theIngredient.maxAmplifier, 2, 28, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); + if (this.ingredient.getMaxAmplifier() > 0) { + minecraft.fontRenderer.drawString(StringUtil.localize("container.nei." + ActuallyAdditions.MODID + ".coffee.maxAmount") + ": " + this.ingredient.getMaxAmplifier(), 2, 28, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); } super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY); } @Override - public int getButtonX(){ + public int getButtonX() { return 0; } @Override - public int getButtonY(){ + public int getButtonY() { return 68; } @Override - public IBookletPage getPage(){ + public IBookletPage getPage() { return BookletUtils.findFirstPageForStack(new ItemStack(InitBlocks.blockCoffeeMachine)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeCategory.java index 7b09014bf..3afadf75d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeCategory.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.jei.compost; +import java.util.Arrays; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; @@ -19,42 +21,42 @@ import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.recipe.IRecipeCategory; -public class CompostRecipeCategory implements IRecipeCategory{ +public class CompostRecipeCategory implements IRecipeCategory { public static final String NAME = "actuallyadditions.compost"; private final IDrawable background; - public CompostRecipeCategory(IGuiHelper helper){ + public CompostRecipeCategory(IGuiHelper helper) { this.background = helper.createDrawable(AssetUtil.getGuiLocation("gui_nei_simple"), 0, 0, 96, 60); } @Override - public String getUid(){ + public String getUid() { return NAME; } @Override - public String getTitle(){ - return StringUtil.localize("container.nei."+NAME+".name"); + public String getTitle() { + return StringUtil.localize("container.nei." + NAME + ".name"); } @Override - public String getModName(){ + public String getModName() { return ActuallyAdditions.NAME; } @Override - public IDrawable getBackground(){ + public IDrawable getBackground() { return this.background; } @Override - public void setRecipe(IRecipeLayout recipeLayout, CompostRecipeWrapper wrapper, IIngredients ingredients){ + public void setRecipe(IRecipeLayout recipeLayout, CompostRecipeWrapper wrapper, IIngredients ingredients) { recipeLayout.getItemStacks().init(0, true, 4, 18); - recipeLayout.getItemStacks().set(0, wrapper.theRecipe.input); + recipeLayout.getItemStacks().set(0, Arrays.asList(wrapper.recipe.getInput().getMatchingStacks())); recipeLayout.getItemStacks().init(1, false, 66, 18); - recipeLayout.getItemStacks().set(1, wrapper.theRecipe.output); + recipeLayout.getItemStacks().set(1, wrapper.recipe.getOutput()); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeWrapper.java index 5886ca37c..3065d265f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/compost/CompostRecipeWrapper.java @@ -10,49 +10,51 @@ package de.ellpeck.actuallyadditions.mod.jei.compost; +import java.util.Arrays; + import de.ellpeck.actuallyadditions.api.booklet.IBookletPage; import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; -import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost; import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils; import de.ellpeck.actuallyadditions.mod.jei.RecipeWrapperWithButton; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityCompost; import mezz.jei.api.ingredients.IIngredients; import net.minecraft.client.Minecraft; import net.minecraft.item.ItemStack; -public class CompostRecipeWrapper extends RecipeWrapperWithButton{ +public class CompostRecipeWrapper extends RecipeWrapperWithButton { - public final CompostRecipe theRecipe; + public final CompostRecipe recipe; - public CompostRecipeWrapper(CompostRecipe recipe){ - this.theRecipe = recipe; + public CompostRecipeWrapper(CompostRecipe recipe) { + this.recipe = recipe; } @Override - public void getIngredients(IIngredients ingredients){ - ingredients.setInput(ItemStack.class, this.theRecipe.input); - ingredients.setOutput(ItemStack.class, this.theRecipe.output); + public void getIngredients(IIngredients ingredients) { + ingredients.setInputs(ItemStack.class, Arrays.asList(recipe.getInput().getMatchingStacks())); + ingredients.setOutput(ItemStack.class, recipe.getOutput()); } @Override - public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { int bake_time = TileEntityCompost.COMPOST_TIME_TICKS / 20; minecraft.fontRenderer.drawString(bake_time + "s", 28, 3, 0xFFFFFF, true); //super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY); Not sure the button needs to be here. } @Override - public int getButtonX(){ + public int getButtonX() { return 32; } @Override - public int getButtonY(){ + public int getButtonY() { return 35; } @Override - public IBookletPage getPage(){ + public IBookletPage getPage() { return BookletUtils.findFirstPageForStack(new ItemStack(InitBlocks.blockCompost)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/empowerer/EmpowererRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/empowerer/EmpowererRecipeCategory.java index 7522c836d..369956291 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/empowerer/EmpowererRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/empowerer/EmpowererRecipeCategory.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.jei.empowerer; +import java.util.Arrays; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; @@ -52,21 +54,21 @@ public class EmpowererRecipeCategory implements IRecipeCategory inputs = new ArrayList<>(); + for(ItemStack s : theRecipe.getInput().getMatchingStacks()) + inputs.add(s); + for(ItemStack s : theRecipe.getStandOne().getMatchingStacks()) + inputs.add(s); + for(ItemStack s : theRecipe.getStandTwo().getMatchingStacks()) + inputs.add(s); + for(ItemStack s : theRecipe.getStandThree().getMatchingStacks()) + inputs.add(s); + for(ItemStack s : theRecipe.getStandFour().getMatchingStacks()) + inputs.add(s); + + ingredients.setInputs(ItemStack.class, inputs); + ingredients.setOutput(ItemStack.class, this.theRecipe.getOutput()); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java index 53f26f633..1a06859e2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.jei.reconstructor; +import java.util.Arrays; + import de.ellpeck.actuallyadditions.api.booklet.IBookletPage; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; @@ -25,68 +27,68 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; -public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton{ - - public static final IRecipeWrapperFactory FACTORY = (recipe) -> { - if(recipe instanceof EnchBookConversion) return new EnchBookWrapper((EnchBookConversion) recipe); - return new ReconstructorRecipeWrapper(recipe); - }; +public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton { + + public static final IRecipeWrapperFactory FACTORY = (recipe) -> { + if (recipe instanceof EnchBookConversion) return new EnchBookWrapper((EnchBookConversion) recipe); + return new ReconstructorRecipeWrapper(recipe); + }; public final LensConversionRecipe theRecipe; - public ReconstructorRecipeWrapper(LensConversionRecipe recipe){ + public ReconstructorRecipeWrapper(LensConversionRecipe recipe) { this.theRecipe = recipe; } @Override - public void getIngredients(IIngredients ingredients){ - ingredients.setInput(ItemStack.class, this.theRecipe.inputStack); - ingredients.setOutput(ItemStack.class, this.theRecipe.outputStack); + public void getIngredients(IIngredients ingredients) { + ingredients.setInputs(ItemStack.class, Arrays.asList(this.theRecipe.getInput().getMatchingStacks())); + ingredients.setOutput(ItemStack.class, this.theRecipe.getOutput()); } @Override - public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ - minecraft.fontRenderer.drawString(this.theRecipe.energyUse+" CF", 55, 0, 0xFFFFFF, true); + public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) { + minecraft.fontRenderer.drawString(this.theRecipe.getEnergyUsed() + " CF", 55, 0, 0xFFFFFF, true); super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY); } @Override - public int getButtonX(){ + public int getButtonX() { return 3; } @Override - public int getButtonY(){ + public int getButtonY() { return 40; } @Override - public IBookletPage getPage(){ + public IBookletPage getPage() { return BookletUtils.findFirstPageForStack(new ItemStack(InitBlocks.blockAtomicReconstructor)); } - + public static class EnchBookWrapper extends ReconstructorRecipeWrapper { - private static final ItemStack BOOK = new ItemStack(Items.ENCHANTED_BOOK); - private static final ItemStack OUT = new ItemStack(Items.ENCHANTED_BOOK); - - static { - OUT.setStackDisplayName("Split Book"); - NBTTagCompound t = OUT.getTagCompound().getCompoundTag("display"); - NBTTagList l = new NBTTagList(); - l.appendTag(new NBTTagString("Book will be split based on enchantments!")); - t.setTag("Lore", l); - } - - public EnchBookWrapper(EnchBookConversion recipe) { - super(recipe); - } - - @Override - public void getIngredients(IIngredients ingredients){ - ingredients.setInput(ItemStack.class, BOOK); - ingredients.setOutput(ItemStack.class, OUT); - } + private static final ItemStack BOOK = new ItemStack(Items.ENCHANTED_BOOK); + private static final ItemStack OUT = new ItemStack(Items.ENCHANTED_BOOK); + + static { + OUT.setStackDisplayName("Split Book"); + NBTTagCompound t = OUT.getTagCompound().getCompoundTag("display"); + NBTTagList l = new NBTTagList(); + l.appendTag(new NBTTagString("Book will be split based on enchantments!")); + t.setTag("Lore", l); + } + + public EnchBookWrapper(EnchBookConversion recipe) { + super(recipe); + } + + @Override + public void getIngredients(IIngredients ingredients) { + ingredients.setInput(ItemStack.class, BOOK); + ingredients.setOutput(ItemStack.class, OUT); + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java index 0156f8cb2..ae9df0bd4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/apiimpl/MethodHandler.java @@ -61,7 +61,7 @@ public class MethodHandler implements IMethodHandler{ for(PotionEffect effect : effects){ PotionEffect effectHas = this.getSameEffectFromStack(stack, effect); if(effectHas != null){ - if(effectHas.getAmplifier() < ingredient.maxAmplifier-1){ + if(effectHas.getAmplifier() < ingredient.getMaxAmplifier()-1){ this.addEffectProperties(stack, effect, false, true); worked = true; } @@ -168,10 +168,9 @@ public class MethodHandler implements IMethodHandler{ BlockPos pos = new BlockPos(hitBlock.getX()+reachX, hitBlock.getY()+reachY, hitBlock.getZ()+reachZ); if(!tile.getWorldObject().isAirBlock(pos)){ IBlockState state = tile.getWorldObject().getBlockState(pos); - List recipes = LensRecipeHandler.getRecipesFor(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state))); - for(LensConversionRecipe recipe : recipes){ - if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){ - ItemStack output = recipe.outputStack; + LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)), tile.getLens()); + if(recipe != null && tile.getEnergy() >= recipe.getEnergyUsed()){ + ItemStack output = recipe.getOutput(); if(StackUtil.isValid(output)){ tile.getWorldObject().playEvent(2001, pos, Block.getStateId(state)); recipe.transformHook(ItemStack.EMPTY, state, pos, tile); @@ -186,14 +185,13 @@ public class MethodHandler implements IMethodHandler{ tile.getWorldObject().setBlockToAir(pos); } - tile.extractEnergy(recipe.energyUse); + tile.extractEnergy(recipe.getEnergyUsed()); break; } } } } } - } } //Converting the Items @@ -201,10 +199,9 @@ public class MethodHandler implements IMethodHandler{ for(EntityItem item : items){ ItemStack stack = item.getItem(); if(!item.isDead && StackUtil.isValid(stack)){ - List recipes = LensRecipeHandler.getRecipesFor(stack); - for(LensConversionRecipe recipe : recipes){ - if(recipe != null && recipe.type == tile.getLens()){ - int itemsPossible = Math.min(tile.getEnergy()/recipe.energyUse, stack.getCount()); + LensConversionRecipe recipe = LensRecipeHandler.findMatchingRecipe(stack, tile.getLens()); + if(recipe != null){ + int itemsPossible = Math.min(tile.getEnergy()/recipe.getEnergyUsed(), stack.getCount()); if(itemsPossible > 0){ recipe.transformHook(item.getItem(), null, item.getPosition(), tile); @@ -218,18 +215,17 @@ public class MethodHandler implements IMethodHandler{ tile.getWorldObject().spawnEntity(inputLeft); } - ItemStack outputCopy = recipe.outputStack.copy(); + ItemStack outputCopy = recipe.getOutput().copy(); outputCopy.setCount(itemsPossible); EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy); tile.getWorldObject().spawnEntity(newItem); - tile.extractEnergy(recipe.energyUse*itemsPossible); + tile.extractEnergy(recipe.getEnergyUsed()*itemsPossible); break; } } } - } } return !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java index da4642cbe..8e4d21620 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java @@ -16,8 +16,8 @@ import java.util.List; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ClientRegistryHandler; +import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderBatteryBox; -import de.ellpeck.actuallyadditions.mod.blocks.render.RenderCompost; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderEmpowerer; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderLaserRelay; @@ -43,14 +43,17 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntitySmileyCloud; import de.ellpeck.actuallyadditions.mod.util.IColorProvidingBlock; import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.play.client.CPacketPlayerDigging; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.MinecraftForge; @@ -81,7 +84,7 @@ public class ClientProxy implements IProxy{ new ClientEvents(); - ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost()); + //ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAtomicReconstructor.class, new RenderReconstructorLens()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySmileyCloud.class, new RenderSmileyCloud()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDisplayStand.class, new RenderDisplayStand()); @@ -110,6 +113,18 @@ public class ClientProxy implements IProxy{ Minecraft.getMinecraft().getItemColors().registerItemColorHandler(((IColorProvidingItem)block).getItemColor(), block); } } + + IBlockColor color = (state, world, pos, tint) -> { + if (world != null && pos != null) { + TileEntity tileentity = world.getTileEntity(pos); + if (tileentity instanceof TileEntityCompost && ((TileEntityCompost) tileentity).getCurrentDisplay().getBlock() != state.getBlock()) { + IBlockState iblockstate = ((TileEntityCompost) tileentity).getCurrentDisplay(); + return Minecraft.getMinecraft().getBlockColors().colorMultiplier(iblockstate, world, pos, tint); + } + } + return -1; + }; + Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(color, InitBlocks.blockCompost); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java index f962cf885..77137c8f8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EmpowererHandler.java @@ -10,6 +10,9 @@ package de.ellpeck.actuallyadditions.mod.recipe; +import java.util.ArrayList; +import java.util.List; + import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; @@ -17,46 +20,52 @@ import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; import de.ellpeck.actuallyadditions.mod.util.RecipeUtil; +import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.oredict.OreIngredient; -import java.util.ArrayList; -import java.util.List; - -public final class EmpowererHandler{ +public final class EmpowererHandler { public static final ArrayList MAIN_PAGE_RECIPES = new ArrayList(); public static EmpowererRecipe recipeEmpoweredCanolaSeed; - public static void init(){ - addCrystalEmpowering(TheCrystals.REDSTONE, "dyeRed", new ItemStack(Items.NETHERBRICK), new ItemStack(Items.REDSTONE), new ItemStack(Items.BRICK)); - addCrystalEmpowering(TheCrystals.LAPIS, "dyeCyan", new ItemStack(Items.PRISMARINE_SHARD), new ItemStack(Items.PRISMARINE_SHARD), new ItemStack(Items.PRISMARINE_SHARD)); - addCrystalEmpowering(TheCrystals.DIAMOND, "dyeLightBlue", new ItemStack(Items.CLAY_BALL), new ItemStack(Items.CLAY_BALL), new ItemStack(Blocks.CLAY)); - addCrystalEmpowering(TheCrystals.IRON, "dyeGray", new ItemStack(Items.SNOWBALL), new ItemStack(Blocks.STONE_BUTTON), new ItemStack(Blocks.COBBLESTONE)); + public static void init() { + addCrystalEmpowering(TheCrystals.REDSTONE, "dyeRed", Ingredient.fromItem(Items.NETHERBRICK), Ingredient.fromItem(Items.REDSTONE), Ingredient.fromItem(Items.BRICK)); + addCrystalEmpowering(TheCrystals.LAPIS, "dyeCyan", Ingredient.fromItem(Items.PRISMARINE_SHARD), Ingredient.fromItem(Items.PRISMARINE_SHARD), Ingredient.fromItem(Items.PRISMARINE_SHARD)); + addCrystalEmpowering(TheCrystals.DIAMOND, "dyeLightBlue", Ingredient.fromItem(Items.CLAY_BALL), Ingredient.fromItem(Items.CLAY_BALL), fromBlock(Blocks.CLAY)); + addCrystalEmpowering(TheCrystals.IRON, "dyeGray", Ingredient.fromItem(Items.SNOWBALL), fromBlock(Blocks.STONE_BUTTON), fromBlock(Blocks.COBBLESTONE)); - addCrystalEmpowering(TheCrystals.COAL, "dyeBlack", new ItemStack(Items.COAL, 1, 1), new ItemStack(Items.FLINT), new ItemStack(Blocks.STONE)); + addCrystalEmpowering(TheCrystals.COAL, "dyeBlack", igd(new ItemStack(Items.COAL, 1, 1)), Ingredient.fromItem(Items.FLINT), fromBlock(Blocks.STONE)); List balls = OreDictionary.getOres("slimeball"); - for(ItemStack ball : balls){ - addCrystalEmpowering(TheCrystals.EMERALD, "dyeLime", new ItemStack(Blocks.TALLGRASS, 1, 1), new ItemStack(Blocks.SAPLING), ball.copy()); + for (ItemStack ball : balls) { + addCrystalEmpowering(TheCrystals.EMERALD, "dyeLime", igd(new ItemStack(Blocks.TALLGRASS, 1, 1)), igd(new ItemStack(Blocks.SAPLING)), igd(ball.copy())); } - ItemStack seed = new ItemStack(InitItems.itemCanolaSeed); - ActuallyAdditionsAPI.addEmpowererRecipe(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CRYSTALLIZED_CANOLA_SEED.ordinal()), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.EMPOWERED_CANOLA_SEED.ordinal()), seed, seed, seed, seed, 1000, 30, new float[]{1F, 91F/255F, 76F/255F}); + Ingredient seed = Ingredient.fromItem(InitItems.itemCanolaSeed); + ActuallyAdditionsAPI.addEmpowererRecipe(Ingredient.fromStacks(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.CRYSTALLIZED_CANOLA_SEED.ordinal())), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.EMPOWERED_CANOLA_SEED.ordinal()), seed, seed, seed, seed, 1000, 30, new float[] { 1F, 91F / 255F, 76F / 255F }); recipeEmpoweredCanolaSeed = RecipeUtil.lastEmpowererRecipe(); } - private static void addCrystalEmpowering(TheCrystals type, String dye, ItemStack modifier1, ItemStack modifier2, ItemStack modifier3){ + private static void addCrystalEmpowering(TheCrystals type, String dye, Ingredient modifier1, Ingredient modifier2, Ingredient modifier3) { float[] color = type.conversionColorParticles; - List dyes = OreDictionary.getOres(dye); - for(ItemStack dyeStack : dyes){ - ActuallyAdditionsAPI.addEmpowererRecipe(new ItemStack(InitItems.itemCrystal, 1, type.ordinal()), new ItemStack(InitItems.itemCrystalEmpowered, 1, type.ordinal()), dyeStack, modifier1, modifier2, modifier3, 5000, 50, color); - MAIN_PAGE_RECIPES.add(RecipeUtil.lastEmpowererRecipe()); - ActuallyAdditionsAPI.addEmpowererRecipe(new ItemStack(InitBlocks.blockCrystal, 1, type.ordinal()), new ItemStack(InitBlocks.blockCrystalEmpowered, 1, type.ordinal()), dyeStack, modifier1, modifier2, modifier3, 50000, 500, color); - MAIN_PAGE_RECIPES.add(RecipeUtil.lastEmpowererRecipe()); - } + ActuallyAdditionsAPI.addEmpowererRecipe(Ingredient.fromStacks(new ItemStack(InitItems.itemCrystal, 1, type.ordinal())), new ItemStack(InitItems.itemCrystalEmpowered, 1, type.ordinal()), new OreIngredient(dye), modifier1, modifier2, modifier3, 5000, 50, color); + MAIN_PAGE_RECIPES.add(RecipeUtil.lastEmpowererRecipe()); + ActuallyAdditionsAPI.addEmpowererRecipe(Ingredient.fromStacks(new ItemStack(InitBlocks.blockCrystal, 1, type.ordinal())), new ItemStack(InitBlocks.blockCrystalEmpowered, 1, type.ordinal()), new OreIngredient(dye), modifier1, modifier2, modifier3, 50000, 500, color); + MAIN_PAGE_RECIPES.add(RecipeUtil.lastEmpowererRecipe()); + } + + private static Ingredient igd(ItemStack s) { + return Ingredient.fromStacks(s); + } + + private static Ingredient fromBlock(Block b) { + return Ingredient.fromItem(Item.getItemFromBlock(b)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EnchBookConversion.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EnchBookConversion.java index 8f0d97895..cf71abbbb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EnchBookConversion.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/EnchBookConversion.java @@ -13,12 +13,13 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.math.BlockPos; public class EnchBookConversion extends LensConversionRecipe { public EnchBookConversion() { - super(new ItemStack(Items.ENCHANTED_BOOK), ItemStack.EMPTY, 155000, ActuallyAdditionsAPI.lensDefaultConversion); + super(Ingredient.fromItem(Items.ENCHANTED_BOOK), ItemStack.EMPTY, 155000, ActuallyAdditionsAPI.lensDefaultConversion); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java index 5d84738b8..f4d55b054 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCompost.java @@ -12,88 +12,110 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe; +import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -public class TileEntityCompost extends TileEntityInventoryBase{ +public class TileEntityCompost extends TileEntityInventoryBase { public static final int COMPOST_TIME_TICKS = 3000; - public int conversionTime; + protected int conversionTime; + protected CompostRecipe recipe; - public TileEntityCompost(){ + public TileEntityCompost() { super(1, "compost"); } - public static CompostRecipe getRecipeForInput(ItemStack input){ - if(StackUtil.isValid(input)){ - for(CompostRecipe recipe : ActuallyAdditionsAPI.COMPOST_RECIPES){ - if(input.isItemEqual(recipe.input)){ - return recipe; - } + public static CompostRecipe getRecipeForInput(ItemStack input) { + if (StackUtil.isValid(input)) { + for (CompostRecipe recipe : ActuallyAdditionsAPI.COMPOST_RECIPES) { + if (recipe.matches(input)) return recipe; } } return null; } @Override - public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ + public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { super.writeSyncableNBT(compound, type); - if(type != NBTType.SAVE_BLOCK){ + if (type != NBTType.SAVE_BLOCK) { compound.setInteger("ConversionTime", this.conversionTime); } } @Override - public boolean shouldSyncSlots(){ + public boolean shouldSyncSlots() { return true; } @Override - public void readSyncableNBT(NBTTagCompound compound, NBTType type){ + public void readSyncableNBT(NBTTagCompound compound, NBTType type) { super.readSyncableNBT(compound, type); - if(type != NBTType.SAVE_BLOCK){ + if (type != NBTType.SAVE_BLOCK) { this.conversionTime = compound.getInteger("ConversionTime"); } + if (type == NBTType.SYNC) this.world.markBlockRangeForRenderUpdate(this.pos, this.pos.up()); } @Override - public void updateEntity(){ + public void updateEntity() { super.updateEntity(); - if(!this.world.isRemote){ + if (!this.world.isRemote) { boolean theFlag = this.conversionTime > 0; ItemStack input = inv.getStackInSlot(0); - if(StackUtil.isValid(input)){ - CompostRecipe recipe = getRecipeForInput(input); - if(recipe != null){ + if (StackUtil.isValid(input)) { + if (recipe == null || !recipe.matches(input)) recipe = getRecipeForInput(input); + if (recipe != null) { this.conversionTime++; - if(this.conversionTime >= COMPOST_TIME_TICKS){ - ItemStack output = recipe.output.copy(); + if (this.conversionTime >= COMPOST_TIME_TICKS) { + ItemStack output = recipe.getOutput().copy(); output.setCount(input.getCount()); this.inv.setStackInSlot(0, output); this.conversionTime = 0; this.markDirty(); } - } - else{ + } else { this.conversionTime = 0; } } - if(theFlag != this.conversionTime > 0){ + if (theFlag != this.conversionTime > 0) { this.markDirty(); } } } @Override - public boolean canInsert(int i, ItemStack stack, boolean automation){ + public boolean canInsert(int i, ItemStack stack, boolean automation) { return getRecipeForInput(stack) != null; } @Override - public boolean canExtract(int slot, ItemStack stack, boolean automation){ + public boolean canExtract(int slot, ItemStack stack, boolean automation) { return getRecipeForInput(stack) == null; } + + public IBlockState getCurrentDisplay() { + ItemStack input = inv.getStackInSlot(0); + CompostRecipe displayRecipe = recipe; + if (displayRecipe == null || !displayRecipe.matches(input)) displayRecipe = getRecipeForInput(input); + + if (displayRecipe == null) for (CompostRecipe r : ActuallyAdditionsAPI.COMPOST_RECIPES) { + if (ItemUtil.areItemsEqual(input, r.getOutput(), true)) return r.getOutputDisplay(); + else if (r.getInput().apply(input)) return r.getInputDisplay(); + } + + if(displayRecipe != null) return displayRecipe.getInputDisplay(); + return Blocks.AIR.getDefaultState(); + } + + public float getHeight() { + ItemStack input = inv.getStackInSlot(0); + if (input.isEmpty()) return 0; + return (float) input.getCount() / input.getMaxStackSize(); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java index e4a7be709..336a76395 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraftforge.energy.IEnergyStorage; @@ -100,4 +101,8 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I public IEnergyStorage getEnergyStorage(EnumFacing facing){ return this.storage; } + + public ItemStack getStack() { + return this.inv.getStackInSlot(0); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java index 98f1ddb84..41781b076 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java @@ -10,9 +10,13 @@ package de.ellpeck.actuallyadditions.mod.tile; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nullable; + import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; -import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -22,153 +26,143 @@ import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class TileEntityEmpowerer extends TileEntityInventoryBase{ +public class TileEntityEmpowerer extends TileEntityInventoryBase { public int processTime; public int recipeForRenderIndex = -1; private int lastRecipe; - public TileEntityEmpowerer(){ + public TileEntityEmpowerer() { super(1, "empowerer"); } - public static List getRecipesForInput(ItemStack input){ + @Deprecated //Use findMatchingRecipe + public static List getRecipesForInput(ItemStack input) { List recipesThatWork = new ArrayList(); - if(StackUtil.isValid(input)){ - for(EmpowererRecipe recipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES){ - if(StackUtil.isValid(recipe.input) && recipe.input.isItemEqual(input)){ + if (StackUtil.isValid(input)) { + for (EmpowererRecipe recipe : ActuallyAdditionsAPI.EMPOWERER_RECIPES) { + if (recipe.getInput().apply(input)) { recipesThatWork.add(recipe); } } } return recipesThatWork; } + + public static boolean isPossibleInput(ItemStack stack) { + for(EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) if(r.getInput().apply(stack)) return true; + return false; + } + + @Nullable + public static EmpowererRecipe findMatchingRecipe(ItemStack base, ItemStack stand1, ItemStack stand2, ItemStack stand3, ItemStack stand4) { + for (EmpowererRecipe r : ActuallyAdditionsAPI.EMPOWERER_RECIPES) { + if (r.matches(base, stand1, stand2, stand3, stand4)) return r; + } + return null; + } @Override - public void updateEntity(){ + public void updateEntity() { super.updateEntity(); - if(!this.world.isRemote){ - List recipes = getRecipesForInput(this.inv.getStackInSlot(0)); - if(!recipes.isEmpty()){ - for(EmpowererRecipe recipe : recipes){ - TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time); - if(modifierStands != null){ //Meaning the display stands around match all the criteria - this.recipeForRenderIndex = ActuallyAdditionsAPI.EMPOWERER_RECIPES.indexOf(recipe); + if (!this.world.isRemote) { + TileEntityDisplayStand[] stands = this.getNearbyStands(); + if (stands != null) { + EmpowererRecipe recipe = findMatchingRecipe(this.inv.getStackInSlot(0), stands[0].getStack(), stands[1].getStack(), stands[2].getStack(), stands[3].getStack()); + if (recipe != null) { + this.recipeForRenderIndex = ActuallyAdditionsAPI.EMPOWERER_RECIPES.indexOf(recipe); - this.processTime++; - boolean done = this.processTime >= recipe.time; + this.processTime++; + boolean done = this.processTime >= recipe.getTime(); - for(TileEntityDisplayStand stand : modifierStands){ - stand.storage.extractEnergyInternal(recipe.energyPerStand/recipe.time, false); + for (TileEntityDisplayStand stand : stands) { + stand.storage.extractEnergyInternal(recipe.getEnergyPerStand() / recipe.getTime(), false); - if(done){ - stand.inv.getStackInSlot(0).shrink(1); - } + if (done) { + stand.inv.getStackInSlot(0).shrink(1); } - - if(this.processTime%5 == 0 && this.world instanceof WorldServer){ - ((WorldServer)this.world).spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 2, 0, 0, 0, 0.1D); - } - - if(done){ - ((WorldServer)this.world).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 100, 0, 0, 0, 0.25D); - - this.inv.setStackInSlot(0, recipe.output.copy()); - this.markDirty(); - - this.processTime = 0; - this.recipeForRenderIndex = -1; - } - - break; } - } - } - else{ - this.processTime = 0; - this.recipeForRenderIndex = -1; - } - if(this.lastRecipe != this.recipeForRenderIndex){ - this.lastRecipe = this.recipeForRenderIndex; - this.sendUpdate(); + if (this.processTime % 5 == 0 && this.world instanceof WorldServer) { + ((WorldServer) this.world).spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, false, this.pos.getX() + 0.5, this.pos.getY() + 1.1, this.pos.getZ() + 0.5, 2, 0, 0, 0, 0.1D); + } + + if (done) { + ((WorldServer) this.world).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX() + 0.5, this.pos.getY() + 1.1, this.pos.getZ() + 0.5, 100, 0, 0, 0, 0.25D); + + this.inv.setStackInSlot(0, recipe.getOutput().copy()); + this.markDirty(); + + this.processTime = 0; + this.recipeForRenderIndex = -1; + } + } else { + this.processTime = 0; + this.recipeForRenderIndex = -1; + } + + if (this.lastRecipe != this.recipeForRenderIndex) { + this.lastRecipe = this.recipeForRenderIndex; + this.sendUpdate(); + } } } } - private TileEntityDisplayStand[] getFittingModifiers(EmpowererRecipe recipe, int powerDivider){ - TileEntityDisplayStand[] modifierStands = new TileEntityDisplayStand[4]; - List itemsStillNeeded = new ArrayList(Arrays.asList(recipe.modifier1, recipe.modifier2, recipe.modifier3, recipe.modifier4)); + private TileEntityDisplayStand[] getNearbyStands() { + TileEntityDisplayStand[] stands = new TileEntityDisplayStand[4]; - for(int i = 0; i < EnumFacing.HORIZONTALS.length; i++){ + for (int i = 0; i < EnumFacing.HORIZONTALS.length; i++) { EnumFacing facing = EnumFacing.HORIZONTALS[i]; BlockPos offset = this.pos.offset(facing, 3); TileEntity tile = this.world.getTileEntity(offset); - - if(tile instanceof TileEntityDisplayStand){ - TileEntityDisplayStand stand = (TileEntityDisplayStand)tile; - ItemStack standItem = stand.inv.getStackInSlot(0); - int containPlace = ItemUtil.getPlaceAt(itemsStillNeeded, standItem, true); - if(stand.storage.getEnergyStored() >= recipe.energyPerStand/powerDivider && containPlace != -1){ - modifierStands[i] = stand; - itemsStillNeeded.remove(containPlace); - } - else{ - return null; - } - } - else{ - return null; - } + if (tile instanceof TileEntityDisplayStand) stands[i] = (TileEntityDisplayStand) tile; + else return null; } - return modifierStands; + return stands; } @Override - public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ + public void writeSyncableNBT(NBTTagCompound compound, NBTType type) { super.writeSyncableNBT(compound, type); - if(type == NBTType.SAVE_TILE){ + if (type == NBTType.SAVE_TILE) { compound.setInteger("ProcessTime", this.processTime); } - if(type == NBTType.SYNC){ + if (type == NBTType.SYNC) { compound.setInteger("RenderIndex", this.recipeForRenderIndex); } } @Override - public void readSyncableNBT(NBTTagCompound compound, NBTType type){ + public void readSyncableNBT(NBTTagCompound compound, NBTType type) { super.readSyncableNBT(compound, type); - if(type == NBTType.SAVE_TILE){ + if (type == NBTType.SAVE_TILE) { this.processTime = compound.getInteger("ProcessTime"); } - if(type == NBTType.SYNC){ + if (type == NBTType.SYNC) { this.recipeForRenderIndex = compound.getInteger("RenderIndex"); } } @Override - public boolean shouldSyncSlots(){ + public boolean shouldSyncSlots() { return true; } @Override - public boolean canInsert(int index, ItemStack stack, boolean automation){ + public boolean canInsert(int index, ItemStack stack, boolean automation) { return !automation || !getRecipesForInput(stack).isEmpty(); } @Override - public boolean canExtract(int index, ItemStack stack, boolean automation){ + public boolean canExtract(int index, ItemStack stack, boolean automation) { return !automation || getRecipesForInput(stack).isEmpty(); } @Override - public int getMaxStackSize(int slot){ + public int getMaxStackSize(int slot) { return 1; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java index 54c30103c..75e9458dd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java @@ -144,6 +144,7 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements } else{ int theSlot = StackUtil.findFirstFilled(this.inv); + if(theSlot == -1) return; inv.setStackInSlot(theSlot, WorldUtil.useItemAtSide(WorldUtil.getDirectionBySidesInOrder(this.side), this.world, this.boundPosition, inv.getStackInSlot(theSlot))); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index 1c0b72fec..58fe2b0c5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -10,18 +10,25 @@ package de.ellpeck.actuallyadditions.mod.util; +import org.lwjgl.opengl.GL11; + import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.particle.ParticleBeam; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.particle.Particle; -import net.minecraft.client.renderer.*; +import net.minecraft.client.renderer.BufferBuilder; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager.DestFactor; import net.minecraft.client.renderer.GlStateManager.SourceFactor; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.RenderItem; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType; import net.minecraft.client.renderer.texture.TextureManager; @@ -31,13 +38,14 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import org.lwjgl.opengl.GL11; public final class AssetUtil{ @@ -83,6 +91,20 @@ public final class AssetUtil{ GlStateManager.popMatrix(); } } + + @SideOnly(Side.CLIENT) + public static void renderStateInWorld(IBlockState state, IBlockAccess world, BlockPos pos, float brightness){ + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE); + IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state); + GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F); + int i = Minecraft.getMinecraft().getBlockColors().colorMultiplier(state, world, pos, 0); + + float r = (float) (i >> 16 & 255) / 255F; + float g = (float) (i >> 8 & 255) / 255F; + float b = (float) (i & 255) / 255F; + + Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightnessColor(state, model, brightness, r, g, b); + } @SideOnly(Side.CLIENT) public static void renderItemWithoutScrewingWithColors(ItemStack stack){