Fix #960, Use itemDamage for wood items instead of NBT

This commit is contained in:
mezz committed 2015-11-11 00:09:17 -08:00
1 parent 90c9050e80
commit d4cd0aaf7e
26 files changed
+185 -343

No files matched your search

@@ -14,10 +14,10 @@ import java.util.EnumMap;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import forestry.api.arboriculture.EnumWoodType;
import forestry.api.arboriculture.IWoodItemAccess;
import forestry.arboriculture.items.ItemBlockWood;
public class WoodItemAccess implements IWoodItemAccess {
private static final EnumMap<EnumWoodType, ItemStack> logs = new EnumMap<>(EnumWoodType.class);
@@ -32,11 +32,8 @@ public class WoodItemAccess implements IWoodItemAccess {
private static final EnumMap<EnumWoodType, ItemStack> stairsFireproof = new EnumMap<>(EnumWoodType.class);
private static ItemStack getStack(EnumWoodType woodType, Block block) {
NBTTagCompound woodNBT = new NBTTagCompound();
woodType.saveToCompound(woodNBT);
ItemStack itemStack = new ItemStack(block);
itemStack.setTagCompound(woodNBT);
ItemBlockWood.saveToItemStack(woodType, itemStack);
return itemStack;
}
@@ -24,7 +24,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
@@ -124,10 +123,7 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntity
/* PROPERTIES */
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
return TileWood.getPickBlock(this, world, x, y, z);
}
/* DROP HANDLING */
@@ -22,7 +22,6 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
@@ -92,10 +91,7 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEnti
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = super.getPickBlock(target, world, x, y, z);
NBTTagCompound stairsNBT = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(stairsNBT);
return itemStack;
return TileWood.getPickBlock(this, world, x, y, z);
}
/* ICONS */
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
@@ -24,7 +23,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
@@ -121,10 +119,7 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
/* PROPERTIES */
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
return TileWood.getPickBlock(this, world, x, y, z);
}
/* DROP HANDLING */
@@ -19,7 +19,6 @@ import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
@@ -78,10 +77,7 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, IW
@Override
public final ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
ItemStack itemStack = new ItemStack(this);
NBTTagCompound nbt = TileWood.getTagCompound(world, x, y, z);
itemStack.setTagCompound(nbt);
return itemStack;
return TileWood.getPickBlock(this, world, x, y, z);
}
/* DROP HANDLING */
@@ -13,8 +13,10 @@ package forestry.arboriculture.items;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
@@ -32,13 +34,14 @@ import forestry.core.items.ItemBlockForestry;
import forestry.core.utils.StringUtil;
public class ItemBlockWood extends ItemBlockForestry {
private static final String LEGACY_WOOD_TYPE_KEY = "WoodType";
public ItemBlockWood(Block block) {
super(block);
}
public static boolean placeWood(ItemStack stack, @Nullable EntityPlayer player, World world, int x, int y, int z, int metadata) {
EnumWoodType woodType = EnumWoodType.getFromCompound(stack.getTagCompound());
EnumWoodType woodType = getWoodType(stack);
Block block = Block.getBlockFromItem(stack.getItem());
boolean placed = world.setBlock(x, y, z, block, metadata, Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
@@ -66,6 +69,56 @@ public class ItemBlockWood extends ItemBlockForestry {
return true;
}
public static void saveToItemStack(EnumWoodType woodType, ItemStack itemStack) {
itemStack.setItemDamage(woodType.ordinal());
}
public static EnumWoodType getWoodType(ItemStack stack) {
EnumWoodType woodType = convertLegacyWood(stack);
if (woodType == null) {
int typeOrdinal = stack.getItemDamage();
woodType = getFromOrdinal(typeOrdinal);
}
return woodType;
}
// legacy handling of wood that has wood type saved to NBT
private static EnumWoodType convertLegacyWood(ItemStack itemStack) {
if (!itemStack.hasTagCompound()) {
return null;
}
NBTTagCompound compound = itemStack.getTagCompound();
if (!compound.hasKey(LEGACY_WOOD_TYPE_KEY)) {
return null;
}
int typeOrdinal = compound.getInteger(LEGACY_WOOD_TYPE_KEY);
EnumWoodType woodType = getFromOrdinal(typeOrdinal);
if (woodType != null) {
compound.removeTag(LEGACY_WOOD_TYPE_KEY);
if (compound.hasNoTags()) {
itemStack.setTagCompound(null);
}
saveToItemStack(woodType, itemStack);
}
return woodType;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity player, int p_77663_4_, boolean p_77663_5_) {
super.onUpdate(stack, world, player, p_77663_4_, p_77663_5_);
convertLegacyWood(stack);
}
private static EnumWoodType getFromOrdinal(int ordinal) {
if (ordinal >= 0 && ordinal < EnumWoodType.VALUES.length) {
return EnumWoodType.VALUES[ordinal];
}
return null;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
return placeWood(stack, player, world, x, y, z, metadata);
@@ -78,7 +131,7 @@ public class ItemBlockWood extends ItemBlockForestry {
return super.getItemStackDisplayName(itemstack);
}
EnumWoodType woodType = EnumWoodType.getFromCompound(itemstack.getTagCompound());
EnumWoodType woodType = getWoodType(itemstack);
if (woodType == null) {
return super.getItemStackDisplayName(itemstack);
}
@@ -107,7 +160,7 @@ public class ItemBlockWood extends ItemBlockForestry {
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(ItemStack stack, int pass) {
EnumWoodType woodType = EnumWoodType.getFromCompound(stack.getTagCompound());
EnumWoodType woodType = getWoodType(stack);
if (woodType == null) {
return super.getIcon(stack, pass);
}
@@ -21,6 +21,7 @@ import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
import forestry.api.arboriculture.EnumWoodType;
import forestry.arboriculture.items.ItemBlockWood;
public class RenderFenceItem implements IItemRenderer {
@Override
@@ -61,7 +62,7 @@ public class RenderFenceItem implements IItemRenderer {
private static void renderItem(RenderBlocks renderer, ItemStack itemStack, float x, float y, float z) {
Tessellator tess = Tessellator.instance;
EnumWoodType woodType = EnumWoodType.getFromCompound(itemStack.getTagCompound());
EnumWoodType woodType = ItemBlockWood.getWoodType(itemStack);
IIcon plankIcon = IconProviderWood.getPlankIcon(woodType);
Block block = Block.getBlockFromItem(itemStack.getItem());
@@ -68,7 +68,7 @@ public class RenderLogItem implements IItemRenderer {
return;
}
EnumWoodType woodType = EnumWoodType.getFromCompound(itemStack.getTagCompound());
EnumWoodType woodType = ItemBlockWood.getWoodType(itemStack);
IIcon barkIcon = IconProviderWood.getBarkIcon(woodType);
IIcon heartIcon = IconProviderWood.getHeartIcon(woodType);
@@ -68,7 +68,7 @@ public class RenderPlankItem implements IItemRenderer {
return;
}
EnumWoodType woodType = EnumWoodType.getFromCompound(itemStack.getTagCompound());
EnumWoodType woodType = ItemBlockWood.getWoodType(itemStack);
IIcon plankIcon = IconProviderWood.getPlankIcon(woodType);
if (plankIcon == null) {
@@ -58,7 +58,7 @@ public class RenderSlabItem implements IItemRenderer {
return;
}
EnumWoodType woodType = EnumWoodType.getFromCompound(itemStack.getTagCompound());
EnumWoodType woodType = ItemBlockWood.getWoodType(itemStack);
IIcon plankIcon = IconProviderWood.getPlankIcon(woodType);
if (plankIcon == null) {
@@ -70,7 +70,7 @@ public class RenderStairItem implements IItemRenderer {
return;
}
EnumWoodType woodType = EnumWoodType.getFromCompound(itemStack.getTagCompound());
EnumWoodType woodType = ItemBlockWood.getWoodType(itemStack);
IIcon texture = IconProviderWood.getPlankIcon(woodType);
for (int i = 0; i < 2; ++i) {
@@ -23,6 +23,7 @@ import net.minecraft.world.World;
import forestry.api.arboriculture.EnumWoodType;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.items.ItemBlockWood;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.IStreamable;
@@ -85,15 +86,16 @@ public class TileWood extends TileEntity implements IStreamable {
}
}
public static NBTTagCompound getTagCompound(IBlockAccess world, int x, int y, int z) {
public static ItemStack getPickBlock(Block block, IBlockAccess world, int x, int y, int z) {
TileWood wood = getWoodTile(world, x, y, z);
NBTTagCompound nbttagcompound = new NBTTagCompound();
if (wood == null) {
return nbttagcompound;
return null;
}
EnumWoodType woodType = wood.getWoodType();
woodType.saveToCompound(nbttagcompound);
return nbttagcompound;
ItemStack itemStack = new ItemStack(block);
ItemBlockWood.saveToItemStack(woodType, itemStack);
return itemStack;
}
public static TileWood getWoodTile(IBlockAccess world, int x, int y, int z) {
@@ -103,12 +105,8 @@ public class TileWood extends TileEntity implements IStreamable {
public static <T extends Block & IWoodTyped> ArrayList<ItemStack> getDrops(T block, World world, int x, int y, int z) {
ArrayList<ItemStack> drops = new ArrayList<>();
TileWood wood = getWoodTile(world, x, y, z);
if (wood != null) {
ItemStack stack = new ItemStack(block);
NBTTagCompound compound = new NBTTagCompound();
wood.getWoodType().saveToCompound(compound);
stack.setTagCompound(compound);
ItemStack stack = getPickBlock(block, world, x, y, z);
if (stack != null) {
drops.add(stack);
}
@@ -21,7 +21,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry;
@@ -37,7 +36,6 @@ import forestry.core.config.ForestryBlock;
import forestry.core.config.ForestryItem;
import forestry.core.fluids.Fluids;
import forestry.core.gui.ContainerDummy;
import forestry.core.inventory.InventoryPlain;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
@@ -79,26 +77,6 @@ public abstract class RecipeUtil {
return oreDictNames;
}
public static NBTTagCompound getCraftingNbt(IInventory inventoryCrafting) {
NBTTagCompound craftingNbt = null;
for (int i = 0; i < inventoryCrafting.getSizeInventory(); i++) {
ItemStack stackInSlot = inventoryCrafting.getStackInSlot(i);
if (stackInSlot == null || !stackInSlot.hasTagCompound()) {
continue;
}
NBTTagCompound tagCompound = stackInSlot.getTagCompound();
// if there are multiple NBT they must all match
if (craftingNbt != null && !craftingNbt.equals(tagCompound)) {
return null;
} else {
craftingNbt = tagCompound;
}
}
return craftingNbt;
}
public static Object[] getCraftingRecipeAsArray(IDescriptiveRecipe recipe) {
try {
@@ -263,41 +241,12 @@ public abstract class RecipeUtil {
GameRegistry.addSmelting(res, prod, xp);
}
public static ItemStack getCraftingResult(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
return getCraftingResult(recipe.getRecipeOutput(), recipe.preserveNBT(), inventoryCrafting);
}
public static ItemStack getCraftingResult(ItemStack result, boolean preserveNBT, IInventory inventoryCrafting) {
result = result.copy();
if (preserveNBT) {
NBTTagCompound craftingNbt = getCraftingNbt(inventoryCrafting);
if (craftingNbt == null) {
return null;
}
result.setTagCompound(craftingNbt);
}
return result;
}
public static boolean matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
ItemStack[][] resources = getResources(inventoryCrafting);
Object[] recipeIngredients = recipe.getIngredients();
int width = recipe.getWidth();
int height = recipe.getHeight();
if (!matches(recipeIngredients, width, height, resources)) {
return false;
}
if (recipe.preserveNBT()) {
if (getCraftingNbt(inventoryCrafting) == null) {
return false;
}
}
return true;
return matches(recipeIngredients, width, height, resources);
}
private static ItemStack[][] getResources(IInventory inventoryCrafting) {
@@ -34,8 +34,6 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe {
private final Object[] ingredients;
private final ItemStack product;
private boolean preserveNBT = false;
public ShapedRecipeCustom(int width, int height, Object[] ingredients, ItemStack product) {
this.width = width;
this.height = height;
@@ -43,16 +41,6 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe {
this.product = product;
}
public ShapedRecipeCustom setPreserveNBT() {
this.preserveNBT = true;
return this;
}
@Override
public boolean preserveNBT() {
return preserveNBT;
}
@Override
public int getWidth() {
return width;
@@ -73,6 +61,11 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe {
return ingredients;
}
@Override
public boolean preserveNBT() {
return false;
}
@Override
public boolean matches(InventoryCrafting inventoryCrafting, World world) {
return RecipeUtil.matches(this, inventoryCrafting);
@@ -86,7 +79,7 @@ public class ShapedRecipeCustom implements IDescriptiveRecipe {
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
return RecipeUtil.getCraftingResult(this, inventoryCrafting);
return getRecipeOutput().copy();
}
@Override
@@ -8,7 +8,6 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
@@ -31,22 +30,12 @@ public class ShapelessRecipeCustom implements IRecipe {
private final List<ItemStack> ingredients;
private final ItemStack product;
private boolean preservesNbt = false;
private ShapelessRecipeCustom(ItemStack product, ItemStack... ingredients) {
this.ingredients = Arrays.asList(ingredients);
this.product = product;
}
public ShapelessRecipeCustom setPreserveNBT() {
this.preservesNbt = true;
return this;
}
public boolean preservesNbt() {
return preservesNbt;
}
@Override
public boolean matches(InventoryCrafting inventoryCrafting, World world) {
ArrayList<ItemStack> arraylist = new ArrayList<>(this.ingredients);
@@ -73,33 +62,12 @@ public class ShapelessRecipeCustom implements IRecipe {
}
}
if (!arraylist.isEmpty()) {
return false;
}
if (preservesNbt) {
if (RecipeUtil.getCraftingNbt(inventoryCrafting) == null) {
return false;
}
}
return true;
return arraylist.isEmpty();
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting) {
ItemStack result = product.copy();
if (preservesNbt) {
NBTTagCompound craftingNbt = RecipeUtil.getCraftingNbt(inventoryCrafting);
if (craftingNbt == null) {
return null;
}
result.setTagCompound(craftingNbt);
}
return result;
return product.copy();
}
@Override
@@ -1,21 +0,0 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.core.recipes.nei;
import codechicken.nei.PositionedStack;
public interface INBTMatchingCachedRecipe {
Iterable<PositionedStack> getIngredients();
boolean preservesNBT();
PositionedStack getResult();
}
@@ -23,9 +23,7 @@ import codechicken.nei.PositionedStack;
public class NEIHandlerShapedCustom extends RecipeHandlerBase {
public class CachedShapedCustomRecipe extends CachedBaseRecipe implements INBTMatchingCachedRecipe {
private final boolean preservesNbt;
public class CachedShapedCustomRecipe extends CachedBaseRecipe {
public List<PositionedStack> inputs = new ArrayList<>();
public PositionedStack output;
@@ -37,7 +35,6 @@ public class NEIHandlerShapedCustom extends RecipeHandlerBase {
ItemStack output = recipe.getRecipeOutput();
this.output = new PositionedStack(output, 119, 24);
}
this.preservesNbt = recipe.preserveNBT();
}
public void setIngredients(int width, int height, Object[] items) {
@@ -68,11 +65,6 @@ public class NEIHandlerShapedCustom extends RecipeHandlerBase {
return this.getCycledIngredients(NEIHandlerShapedCustom.this.cycleticks / 20, this.inputs);
}
@Override
public boolean preservesNBT() {
return preservesNbt;
}
@Override
public PositionedStack getResult() {
return this.output;
@@ -85,7 +77,6 @@ public class NEIHandlerShapedCustom extends RecipeHandlerBase {
for (Object recipe : CraftingManager.getInstance().getRecipeList()) {
if (recipe instanceof ShapedRecipeCustom && NEIServerUtils.areStacksSameTypeCrafting(((ShapedRecipeCustom) recipe).getRecipeOutput(), result)) {
CachedShapedCustomRecipe crecipe = new CachedShapedCustomRecipe((ShapedRecipeCustom) recipe);
NEIUtils.setResultPermutationNBT(crecipe, result);
this.arecipes.add(crecipe);
}
}
@@ -97,7 +88,6 @@ public class NEIHandlerShapedCustom extends RecipeHandlerBase {
if (recipe instanceof ShapedRecipeCustom) {
CachedShapedCustomRecipe crecipe = new CachedShapedCustomRecipe((ShapedRecipeCustom) recipe);
if (crecipe.inputs != null && crecipe.contains(crecipe.inputs, ingredient)) {
NEIUtils.setIngredientPermutationNBT(crecipe, ingredient);
this.arecipes.add(crecipe);
}
}
@@ -24,9 +24,7 @@ import codechicken.nei.PositionedStack;
public class NEIHandlerShapelessCustom extends RecipeHandlerBase {
private static final int[][] OUTPUTS = new int[][]{{0, 0}, {1, 0}, {2, 0}, {0, 1}, {1, 1}, {2, 1}, {0, 2}, {1, 2}, {2, 2}};
public class CachedShapelessCustomRecipe extends CachedBaseRecipe implements INBTMatchingCachedRecipe {
private final boolean preservesNbt;
public class CachedShapelessCustomRecipe extends CachedBaseRecipe {
public List<PositionedStack> inputs = new ArrayList<>();
public PositionedStack output;
@@ -38,7 +36,6 @@ public class NEIHandlerShapelessCustom extends RecipeHandlerBase {
ItemStack output = recipe.getRecipeOutput();
this.output = new PositionedStack(output, 119, 24);
}
this.preservesNbt = recipe.preservesNbt();
}
public void setIngredients(List<ItemStack> items) {
@@ -59,11 +56,6 @@ public class NEIHandlerShapelessCustom extends RecipeHandlerBase {
return this.getCycledIngredients(NEIHandlerShapelessCustom.this.cycleticks / 20, this.inputs);
}
@Override
public boolean preservesNBT() {
return preservesNbt;
}
@Override
public PositionedStack getResult() {
return this.output;
@@ -76,7 +68,6 @@ public class NEIHandlerShapelessCustom extends RecipeHandlerBase {
for (Object recipe : CraftingManager.getInstance().getRecipeList()) {
if (recipe instanceof ShapelessRecipeCustom && NEIServerUtils.areStacksSameTypeCrafting(((ShapelessRecipeCustom) recipe).getRecipeOutput(), result)) {
CachedShapelessCustomRecipe crecipe = new CachedShapelessCustomRecipe((ShapelessRecipeCustom) recipe);
NEIUtils.setResultPermutationNBT(crecipe, result);
this.arecipes.add(crecipe);
}
}
@@ -88,7 +79,6 @@ public class NEIHandlerShapelessCustom extends RecipeHandlerBase {
if (recipe instanceof ShapelessRecipeCustom) {
CachedShapelessCustomRecipe crecipe = new CachedShapelessCustomRecipe((ShapelessRecipeCustom) recipe);
if (crecipe.inputs != null && crecipe.contains(crecipe.inputs, ingredient)) {
NEIUtils.setIngredientPermutationNBT(crecipe, ingredient);
this.arecipes.add(crecipe);
}
}
@@ -17,7 +17,6 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fluids.Fluid;
@@ -26,9 +25,6 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fluids.IFluidContainerItem;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
public class NEIUtils {
public static String translate(String unlocalized) {
@@ -78,46 +74,4 @@ public class NEIUtils {
}
return fluidStack1.getFluid() == fluidStack2.getFluid();
}
public static void setIngredientPermutationNBT(INBTMatchingCachedRecipe recipe, ItemStack ingredient) {
Iterable<PositionedStack> ingredients = recipe.getIngredients();
for (PositionedStack stack : ingredients) {
for (int i = 0; i < stack.items.length; i++) {
if (NEIServerUtils.areStacksSameTypeCrafting(ingredient, stack.items[i])) {
stack.item = stack.items[i];
stack.item.setItemDamage(ingredient.getItemDamage());
if (ingredient.hasTagCompound()) {
NBTTagCompound ingredientNbt = (NBTTagCompound) ingredient.getTagCompound().copy();
stack.item.setTagCompound(ingredientNbt);
if (recipe.preservesNBT()) {
recipe.getResult().item.setTagCompound(ingredientNbt);
}
}
stack.items = new ItemStack[]{stack.item};
stack.setPermutationToRender(0);
break;
}
}
}
}
public static void setResultPermutationNBT(INBTMatchingCachedRecipe recipe, ItemStack result) {
PositionedStack recipeResult = recipe.getResult();
if (recipe.preservesNBT()) {
NBTTagCompound resultNbt = result.getTagCompound();
recipeResult.item.setTagCompound((NBTTagCompound) resultNbt.copy());
Iterable<PositionedStack> ingredients = recipe.getIngredients();
for (PositionedStack stack : ingredients) {
if (stack.item.hasTagCompound()) {
stack.item.setTagCompound((NBTTagCompound) resultNbt.copy());
}
stack.items = new ItemStack[]{stack.item};
stack.setPermutationToRender(0);
}
}
}
}
@@ -65,7 +65,7 @@ public class FabricatorRecipe implements IFabricatorRecipe {
@Override
public boolean preservesNbt() {
return internal.preserveNBT();
return false;
}
@Override
@@ -81,17 +81,11 @@ public class FabricatorRecipe implements IFabricatorRecipe {
@Override
public ItemStack getCraftingResult(IInventory craftingInventory) {
return RecipeUtil.getCraftingResult(internal, craftingInventory);
return internal.getRecipeOutput().copy();
}
@Override
public ItemStack getRecipeOutput() {
return internal.getRecipeOutput();
}
public FabricatorRecipe setPreserveNBT() {
internal.setPreserveNBT();
return this;
}
}
@@ -16,11 +16,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
@@ -30,7 +28,6 @@ import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFabricatorRecipe;
import forestry.api.recipes.IFabricatorSmeltingRecipe;
import forestry.api.recipes.RecipeManagers;
import forestry.core.recipes.nei.INBTMatchingCachedRecipe;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
@@ -43,17 +40,13 @@ import codechicken.nei.recipe.GuiRecipe;
public class NEIHandlerFabricator extends RecipeHandlerBase {
public class CachedFabricatorRecipe extends CachedBaseRecipe implements INBTMatchingCachedRecipe {
private final boolean preservesNbt;
public class CachedFabricatorRecipe extends CachedBaseRecipe {
public List<PositionedStack> smeltingInput = new ArrayList<>();
public PositionedFluidTank tank;
public List<PositionedStack> inputs = new ArrayList<>();
public PositionedStack output;
public CachedFabricatorRecipe(IFabricatorRecipe recipe, boolean genPerms) {
this.preservesNbt = recipe.preservesNbt();
if (recipe.getLiquid() != null) {
this.tank = new PositionedFluidTank(recipe.getLiquid(), 2000, new Rectangle(21, 37, 16, 16));
List<ItemStack> smeltingInput = new ArrayList<>();
@@ -106,35 +99,6 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
}
}
@Override
public List<PositionedStack> getCycledIngredients(int cycle, List<PositionedStack> ingredients) {
if (preservesNbt) {
// cycle ingredients and output together
Random random = new Random(cycle);
cycle = Math.abs(random.nextInt());
NBTTagCompound nbt = null;
for (PositionedStack ingredient : ingredients) {
ingredient.setPermutationToRender(cycle % ingredient.items.length);
if (ingredient.item.hasTagCompound()) {
nbt = ingredient.item.getTagCompound();
}
}
output.setPermutationToRender(cycle % output.items.length);
if (nbt != null) {
output.item.setTagCompound((NBTTagCompound) nbt.copy());
}
} else {
return super.getCycledIngredients(cycle, ingredients);
}
return ingredients;
}
@Override
public boolean preservesNBT() {
return preservesNbt;
}
@Override
public PositionedStack getResult() {
return this.output;
@@ -210,7 +174,6 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) {
if (NEIServerUtils.areStacksSameTypeCrafting(recipe.getRecipeOutput(), result)) {
CachedFabricatorRecipe crecipe = new CachedFabricatorRecipe(recipe, true);
NEIUtils.setResultPermutationNBT(crecipe, result);
this.arecipes.add(crecipe);
}
}
@@ -223,7 +186,6 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
CachedFabricatorRecipe crecipe = new CachedFabricatorRecipe(recipe);
if (crecipe.inputs != null && crecipe.contains(crecipe.inputs, ingred) || crecipe.smeltingInput != null && crecipe.contains(crecipe.smeltingInput, ingred)) {
crecipe.generatePermutations();
NEIUtils.setIngredientPermutationNBT(crecipe, ingred);
crecipe.setIngredientPermutation(crecipe.smeltingInput, ingred);
this.arecipes.add(crecipe);
}
@@ -246,7 +208,7 @@ public class NEIHandlerFabricator extends RecipeHandlerBase {
if (new Rectangle(20, 9, 18, 18).contains(relMouse)) {
for (IFabricatorSmeltingRecipe smelting : FabricatorSmeltingRecipeManager.recipes) {
if (NEIServerUtils.areStacksSameTypeCrafting(smelting.getResource(), itemStack) && smelting.getProduct() != null) {
currenttip.add(EnumChatFormatting.GRAY.toString() + NEIUtils.translate("handler.forestry.fabricator.worth") + " " + smelting.getProduct().amount + " mB");
currenttip.add(EnumChatFormatting.GRAY + NEIUtils.translate("handler.forestry.fabricator.worth") + " " + smelting.getProduct().amount + " mB");
}
}
}
@@ -28,7 +28,6 @@ import forestry.api.recipes.IFermenterRecipe;
import forestry.api.recipes.IVariableFermentable;
import forestry.api.recipes.RecipeManagers;
import forestry.core.config.Constants;
import forestry.core.recipes.nei.INBTMatchingCachedRecipe;
import forestry.core.recipes.nei.NEIUtils;
import forestry.core.recipes.nei.PositionedFluidTank;
import forestry.core.recipes.nei.RecipeHandlerBase;
@@ -49,7 +48,7 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
API.setGuiOffset(guiClass, 5, 15);
}
public class CachedFermenterRecipe extends CachedBaseRecipe implements INBTMatchingCachedRecipe {
public class CachedFermenterRecipe extends CachedBaseRecipe {
public List<PositionedFluidTank> tanks = new ArrayList<>();
public PositionedStack resource;
@@ -87,11 +86,6 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
return this.getCycledIngredients(NEIHandlerFermenter.this.cycleticks / 40, this.inputItems);
}
@Override
public boolean preservesNBT() {
return false;
}
@Override
public PositionedStack getResult() {
return null;
@@ -183,7 +177,6 @@ public class NEIHandlerFermenter extends RecipeHandlerBase {
for (ItemStack stack : NEIUtils.getItemVariations(recipe.getResource())) {
if (stack.hasTagCompound() && NEIServerUtils.areStacksSameType(stack, ingred) || !stack.hasTagCompound() && NEIServerUtils.areStacksSameTypeCrafting(stack, ingred)) {
CachedFermenterRecipe crecipe = new CachedFermenterRecipe(recipe, stack, true);
NEIUtils.setIngredientPermutationNBT(crecipe, ingred);
this.arecipes.add(crecipe);
}
}
@@ -42,7 +42,6 @@ import forestry.core.items.ICraftingPlan;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
import forestry.core.recipes.RecipeUtil;
import forestry.core.tiles.ICrafter;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
@@ -195,7 +194,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
return null;
}
return RecipeUtil.getCraftingResult(myRecipe.getRecipeOutput(), myRecipe.preservesNbt(), craftingInventory);
return myRecipe.getRecipeOutput().copy();
}
/* ICrafter */
@@ -277,35 +277,92 @@ public class PluginArboriculture extends ForestryPlugin {
RecipeUtil.addSmelting(ForestryBlock.logs.getWildcard(), new ItemStack(Items.coal, 1, 1), 0.15F);
ShapelessRecipeCustom.buildRecipe(ForestryBlock.planks.getItemStack(4), ForestryBlock.logs.getWildcard()).setPreserveNBT();
ShapelessRecipeCustom.buildRecipe(ForestryBlock.planksFireproof.getItemStack(4), ForestryBlock.logsFireproof.getWildcard()).setPreserveNBT();
for (EnumWoodType woodType : EnumWoodType.VALUES) {
// Fabricator recipes
if (PluginManager.Module.FACTORY.isEnabled() && PluginManager.Module.APICULTURE.isEnabled()) {
ItemStack planks = TreeManager.woodItemAccess.getPlanks(woodType, false);
ItemStack logs = TreeManager.woodItemAccess.getLog(woodType, false);
ItemStack slabs = TreeManager.woodItemAccess.getSlab(woodType, false);
ItemStack fences = TreeManager.woodItemAccess.getFence(woodType, false);
ItemStack stairs = TreeManager.woodItemAccess.getStairs(woodType, false);
// Fireproof log recipe
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), ForestryBlock.logsFireproof.getItemStack(), new Object[]{
" # ",
ItemStack fireproofPlanks = TreeManager.woodItemAccess.getPlanks(woodType, true);
ItemStack fireproofLogs = TreeManager.woodItemAccess.getLog(woodType, true);
ItemStack fireproofSlabs = TreeManager.woodItemAccess.getSlab(woodType, true);
ItemStack fireproofFences = TreeManager.woodItemAccess.getFence(woodType, true);
ItemStack fireproofStairs = TreeManager.woodItemAccess.getStairs(woodType, true);
planks.stackSize = 4;
logs.stackSize = 1;
ShapelessRecipeCustom.buildRecipe(planks.copy(), logs.copy());
fireproofPlanks.stackSize = 4;
fireproofLogs.stackSize = 1;
ShapelessRecipeCustom.buildRecipe(fireproofPlanks.copy(), fireproofLogs.copy());
slabs.stackSize = 6;
planks.stackSize = 1;
ShapedRecipeCustom.buildPriorityRecipe(slabs.copy(),
"###",
'#', planks.copy());
fireproofSlabs.stackSize = 6;
fireproofPlanks.stackSize = 1;
ShapedRecipeCustom.buildPriorityRecipe(fireproofSlabs.copy(),
"###",
'#', fireproofPlanks.copy());
fences.stackSize = 3;
planks.stackSize = 1;
ShapedRecipeCustom.buildRecipe(fences.copy(),
"#X#",
" # ",
'#', ForestryItem.refractoryWax,
'X', ForestryBlock.logs.getWildcard()}).setPreserveNBT());
// Fireproof plank recipe
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), ForestryBlock.planksFireproof.getItemStack(5), new Object[]{
"X#X",
"#X#",
"X#X",
'#', ForestryItem.refractoryWax,
'X', ForestryBlock.planks.getWildcard()}).setPreserveNBT());
'#', planks.copy(), 'X', "stickWood");
fireproofFences.stackSize = 3;
fireproofPlanks.stackSize = 1;
ShapedRecipeCustom.buildRecipe(fireproofFences.copy(),
"#X#",
"#X#",
'#', fireproofPlanks.copy(), 'X', "stickWood");
stairs.stackSize = 4;
planks.stackSize = 1;
ShapedRecipeCustom.buildPriorityRecipe(stairs.copy(),
"# ",
"## ",
"###",
'#', planks.copy());
fireproofStairs.stackSize = 4;
fireproofPlanks.stackSize = 1;
ShapedRecipeCustom.buildPriorityRecipe(fireproofStairs.copy(),
"# ",
"## ",
"###",
'#', fireproofPlanks.copy());
// Fabricator recipes
if (PluginManager.Module.FACTORY.isEnabled() && PluginManager.Module.APICULTURE.isEnabled()) {
logs.stackSize = 1;
fireproofLogs.stackSize = 1;
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), fireproofLogs.copy(), new Object[]{
" # ",
"#X#",
" # ",
'#', ForestryItem.refractoryWax,
'X', logs.copy()}));
planks.stackSize = 1;
fireproofPlanks.stackSize = 5;
RecipeManagers.fabricatorManager.addRecipe(new FabricatorRecipe(null, Fluids.GLASS.getFluid(500), fireproofPlanks.copy(), new Object[]{
"X#X",
"#X#",
"X#X",
'#', ForestryItem.refractoryWax,
'X', planks.copy()}));
}
}
ShapedRecipeCustom.buildPriorityRecipe(ForestryBlock.slabs.getItemStack(6), "###", '#', ForestryBlock.planks.getWildcard()).setPreserveNBT();
ShapedRecipeCustom.buildPriorityRecipe(ForestryBlock.slabsFireproof.getItemStack(6), "###", '#', ForestryBlock.planksFireproof.getWildcard()).setPreserveNBT();
ShapedRecipeCustom.buildRecipe(ForestryBlock.fences.getItemStack(3), "#X#", "#X#", '#', ForestryBlock.planks.getWildcard(), 'X', "stickWood").setPreserveNBT();
ShapedRecipeCustom.buildRecipe(ForestryBlock.fencesFireproof.getItemStack(3), "#X#", "#X#", '#', ForestryBlock.planksFireproof.getWildcard(), 'X', "stickWood").setPreserveNBT();
if (PluginManager.Module.FACTORY.isEnabled()) {
// Treealyzer
RecipeManagers.carpenterManager.addRecipe(100, Fluids.WATER.getFluid(2000), null, ForestryItem.treealyzer.getItemStack(), "X#X", "X#X", "RDR",
@@ -329,19 +386,6 @@ public class PluginArboriculture extends ForestryPlugin {
RecipeUtil.addFermenterRecipes(ForestryItem.sapling.getItemStack(), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
}
// Stairs
ShapedRecipeCustom.buildPriorityRecipe(ForestryBlock.stairs.getItemStack(4),
"# ",
"## ",
"###",
'#', ForestryBlock.planks.getWildcard()).setPreserveNBT();
ShapedRecipeCustom.buildPriorityRecipe(ForestryBlock.stairsFireproof.getItemStack(4),
"# ",
"## ",
"###",
'#', ForestryBlock.planksFireproof.getWildcard()).setPreserveNBT();
// Grafter
RecipeUtil.addRecipe(ForestryItem.grafter.getItemStack(),
" B",
@@ -292,29 +292,24 @@ public class PluginFarming extends ForestryPlugin {
protected void registerRecipes() {
ItemStack basic = ForestryBlock.farm.getItemStack(1, 0);
ItemStack gearbox = ForestryBlock.farm.getItemStack(1, 2);
ItemStack hatch = ForestryBlock.farm.getItemStack(1, 3);
ItemStack valve = ForestryBlock.farm.getItemStack(1, 4);
ItemStack control = ForestryBlock.farm.getItemStack(1, 5);
for (EnumFarmBlockTexture block : EnumFarmBlockTexture.values()) {
NBTTagCompound compound = new NBTTagCompound();
block.saveToCompound(compound);
basic.setTagCompound((NBTTagCompound) compound.copy());
ShapedRecipeCustom.buildRecipe(basic.copy(), "I#I", "WCW", '#', block.getBase(), 'W', "slabWood", 'C', ForestryItem.tubes.getItemStack(1, 1), 'I', "ingotCopper");
ShapedRecipeCustom.buildRecipe(gearbox, " # ", "TTT", '#', basic, 'T', "gearTin");
ShapedRecipeCustom.buildRecipe(hatch, " # ", "TDT", '#', basic, 'T', "gearTin", 'D', Blocks.trapdoor);
ShapedRecipeCustom.buildRecipe(valve, " # ", "XTX", '#', basic, 'T', "gearTin", 'X', "blockGlass");
ShapedRecipeCustom.buildRecipe(control, " # ", "XTX", '#', basic, 'T', ForestryItem.tubes.getItemStack(1, 4), 'X', "dustRedstone");
}
// use wildcard (null) NBT for the basic ingredient so that any basic type can be used
ItemStack basicWildcard = ForestryBlock.farm.getItemStack(1, 0);
ItemStack gearbox = ForestryBlock.farm.getItemStack(1, 2);
ShapedRecipeCustom.buildRecipe(gearbox, " # ", "TTT", '#', basicWildcard, 'T', "gearTin").setPreserveNBT();
ItemStack hatch = ForestryBlock.farm.getItemStack(1, 3);
ShapedRecipeCustom.buildRecipe(hatch, " # ", "TDT", '#', basicWildcard, 'T', "gearTin", 'D', Blocks.trapdoor).setPreserveNBT();
ItemStack valve = ForestryBlock.farm.getItemStack(1, 4);
ShapedRecipeCustom.buildRecipe(valve, " # ", "XTX", '#', basicWildcard, 'T', "gearTin", 'X', "blockGlass").setPreserveNBT();
ItemStack control = ForestryBlock.farm.getItemStack(1, 5);
ShapedRecipeCustom.buildRecipe(control, " # ", "XTX", '#', basicWildcard, 'T', ForestryItem.tubes.getItemStack(1, 4), 'X', "dustRedstone").setPreserveNBT();
// Circuits
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual");