From 9475faf2a86046bfa452d3282b37e7f3f77bf68f Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Thu, 7 Aug 2014 09:33:03 +0200 Subject: [PATCH] minor fixes from previous modifications --- api/buildcraft/api/core/WorldBlockIndex.java | 108 ++++++++++++++++++ .../core/recipes/BuildCraftRecipe.java | 48 ++++---- 2 files changed, 128 insertions(+), 28 deletions(-) create mode 100755 api/buildcraft/api/core/WorldBlockIndex.java diff --git a/api/buildcraft/api/core/WorldBlockIndex.java b/api/buildcraft/api/core/WorldBlockIndex.java new file mode 100755 index 00000000..aedbeaf5 --- /dev/null +++ b/api/buildcraft/api/core/WorldBlockIndex.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.api.core; + +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +/** + * This class is a comparable container for block positions. TODO: should this be merged with position? + */ +public class WorldBlockIndex implements Comparable { + + public int x; + public int y; + public int z; + public int dimension; + + public WorldBlockIndex() { + + } + + /** + * Creates an index for a block located on x, y. z + */ + public WorldBlockIndex(World world, int x, int y, int z) { + + dimension = world.provider.dimensionId; + this.x = x; + this.y = y; + this.z = z; + } + + public WorldBlockIndex(NBTTagCompound c) { + dimension = c.getInteger("dimension"); + x = c.getInteger("x"); + y = c.getInteger("y"); + z = c.getInteger("z"); + } + + public WorldBlockIndex(Entity entity) { + dimension = entity.worldObj.provider.dimensionId; + x = (int) Math.floor(entity.posX); + y = (int) Math.floor(entity.posY); + z = (int) Math.floor(entity.posZ); + } + + /** + * Provides a deterministic and complete ordering of block positions. + */ + @Override + public int compareTo(WorldBlockIndex o) { + + if (o.dimension < dimension) { + return 1; + } else if (o.dimension > dimension) { + return -1; + } else if (o.x < x) { + return 1; + } else if (o.x > x) { + return -1; + } else if (o.z < z) { + return 1; + } else if (o.z > z) { + return -1; + } else if (o.y < y) { + return 1; + } else if (o.y > y) { + return -1; + } else { + return 0; + } + } + + public void writeTo(NBTTagCompound c) { + c.setInteger("dimension", dimension); + c.setInteger("x", x); + c.setInteger("y", y); + c.setInteger("z", z); + } + + @Override + public String toString() { + return "{" + dimension + ":" + x + ", " + y + ", " + z + "}"; + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof WorldBlockIndex) { + WorldBlockIndex b = (WorldBlockIndex) obj; + + return b.dimension == dimension && b.x == x && b.y == y && b.z == z; + } + + return super.equals(obj); + } + + @Override + public int hashCode() { + return (dimension * 37 + (x * 37 + y)) * 37 + z; + } +} diff --git a/common/buildcraft/core/recipes/BuildCraftRecipe.java b/common/buildcraft/core/recipes/BuildCraftRecipe.java index 37ef6201..36d5c909 100755 --- a/common/buildcraft/core/recipes/BuildCraftRecipe.java +++ b/common/buildcraft/core/recipes/BuildCraftRecipe.java @@ -8,11 +8,6 @@ */ package buildcraft.core.recipes; -import java.lang.reflect.Field; -import java.util.List; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; @@ -33,29 +28,26 @@ public class BuildCraftRecipe extends ShapedOreRecipe { @Override public boolean matches(InventoryCrafting inv, World world) { - try { - Field f = InventoryCrafting.class.getDeclaredField("eventHandler"); - - if (!f.isAccessible()) { - f.setAccessible(true); - } - - Container container = (Container) f.get(inv); - - f = Container.class.getDeclaredField("crafters"); - - if (!f.isAccessible()) { - f.setAccessible(true); - } - - List crafters = (List) f.get(container); - - for (Object p : crafters) { - EntityPlayer player = (EntityPlayer) p; - } - } catch (Throwable e) { - e.printStackTrace(); - } + /* + * This code is an experiment for forbidding crafting a recipe if the + * player doesn't have a given attribute. + * + * try { Field f = + * InventoryCrafting.class.getDeclaredField("eventHandler"); + * + * if (!f.isAccessible()) { f.setAccessible(true); } + * + * Container container = (Container) f.get(inv); + * + * f = Container.class.getDeclaredField("crafters"); + * + * if (!f.isAccessible()) { f.setAccessible(true); } + * + * List crafters = (List) f.get(container); + * + * for (Object p : crafters) { EntityPlayer player = (EntityPlayer) p; } + * } catch (Throwable e) { e.printStackTrace(); } + */ return super.matches(inv, world); }