minor fixes from previous modifications

This commit is contained in:
SpaceToad 2014-08-07 09:33:03 +02:00
parent a49b37c981
commit 9475faf2a8
2 changed files with 128 additions and 28 deletions

View file

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

View file

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