summaryrefslogtreecommitdiff
path: root/java/darkknight/jewelrycraft/util/BlockUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/darkknight/jewelrycraft/util/BlockUtils.java')
-rw-r--r--java/darkknight/jewelrycraft/util/BlockUtils.java115
1 files changed, 65 insertions, 50 deletions
diff --git a/java/darkknight/jewelrycraft/util/BlockUtils.java b/java/darkknight/jewelrycraft/util/BlockUtils.java
index 385c175..18cb9eb 100644
--- a/java/darkknight/jewelrycraft/util/BlockUtils.java
+++ b/java/darkknight/jewelrycraft/util/BlockUtils.java
@@ -13,13 +13,18 @@ import net.minecraftforge.common.util.ForgeDirection;
public class BlockUtils
{
-
public static final ForgeDirection DEFAULT_BLOCK_DIRECTION = ForgeDirection.WEST;
+ /**
+ * This method is used to get the direction an entity is facing (NORTH, SOUTH, EAST or WEST) based on the entity's rotationYaw.
+ *
+ * @param entity the living entity
+ * @return a direction
+ */
public static ForgeDirection get2dOrientation(EntityLivingBase entity)
{
int l = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 0x3;
- switch (l)
+ switch(l)
{
case 0:
return ForgeDirection.SOUTH;
@@ -31,12 +36,17 @@ public class BlockUtils
return ForgeDirection.EAST;
}
return ForgeDirection.SOUTH;
-
}
+ /**
+ * This gets a float value depending on a direction
+ *
+ * @param direction the forge direction
+ * @return value depending on direction
+ */
public static float getRotationFromDirection(ForgeDirection direction)
{
- switch (direction)
+ switch(direction)
{
case NORTH:
return 0F;
@@ -55,16 +65,29 @@ public class BlockUtils
}
}
+ /**
+ * This method is used to get the direction an entity is looking at (UP or DOWN) based on the entitiy's rotationPitch
+ *
+ * @param entity the living entity
+ * @return a forge direction
+ */
public static ForgeDirection get3dOrientation(EntityLivingBase entity)
{
- if (entity.rotationPitch > 45.5F)
- {
- return ForgeDirection.DOWN;
- }
- else if (entity.rotationPitch < -45.5F) { return ForgeDirection.UP; }
+ if (entity.rotationPitch > 45.5F) return ForgeDirection.DOWN;
+ else if (entity.rotationPitch < -45.5F) return ForgeDirection.UP;
return get2dOrientation(entity);
}
+ /**
+ * This spawns the item specified and returns the EntityItem it created
+ *
+ * @param worldObj the world
+ * @param x position of the item to drop on the X axis
+ * @param y position of the item to drop on the Y axis
+ * @param z position of the item to drop on the Z axis
+ * @param stack the item to spawn
+ * @return the EntityItem of the stack
+ */
public static EntityItem dropItemStackInWorld(World worldObj, double x, double y, double z, ItemStack stack)
{
float f = 0.7F;
@@ -73,14 +96,22 @@ public class BlockUtils
float d2 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
EntityItem entityitem = new EntityItem(worldObj, x + d0, y + d1, z + d2, stack);
entityitem.delayBeforeCanPickup = 10;
- if (stack.hasTagCompound())
- {
- entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
- }
+ if (stack.hasTagCompound()) entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
worldObj.spawnEntityInWorld(entityitem);
return entityitem;
}
+ /**
+ * It spawns the item with momentum in a certain direction
+ *
+ * @param world the world to spawn the item
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ * @param direction the direction towards which it should eject
+ * @param stack the item to spawn
+ * @return the spawned EntityItem
+ */
public static EntityItem ejectItemInDirection(World world, double x, double y, double z, ForgeDirection direction, ItemStack stack)
{
EntityItem item = BlockUtils.dropItemStackInWorld(world, x, y, z, stack);
@@ -90,51 +121,35 @@ public class BlockUtils
return item;
}
+ /**
+ * Drops the content of an inventory with doubles as coordinates
+ *
+ * @param inventory the inventory the items are contained in
+ * @param world the world in which to spawn
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ */
public static void dropInventory(IInventory inventory, World world, double x, double y, double z)
{
- if (inventory == null) { return; }
- for (int i = 0; i < inventory.getSizeInventory(); ++i)
- {
+ if (inventory == null) return;
+ for(int i = 0; i < inventory.getSizeInventory(); ++i){
ItemStack itemStack = inventory.getStackInSlot(i);
- if (itemStack != null)
- {
- dropItemStackInWorld(world, x, y, z, itemStack);
- }
+ if (itemStack != null) dropItemStackInWorld(world, x, y, z, itemStack);
}
}
+ /**
+ * Drops the content of an inventory with integer as coordinates
+ *
+ * @param inventory the inventory the items are contained in
+ * @param world the world in which to spawn
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ */
public static void dropInventory(IInventory inventory, World world, int x, int y, int z)
{
dropInventory(inventory, world, x + 0.5, y + 0.5, z + 0.5);
}
-
- public static TileEntity getTileInDirection(TileEntity tile, ForgeDirection direction)
- {
- int targetX = tile.xCoord + direction.offsetX;
- int targetY = tile.yCoord + direction.offsetY;
- int targetZ = tile.zCoord + direction.offsetZ;
- return tile.getWorldObj().getTileEntity(targetX, targetY, targetZ);
- }
-
- public static int getFirstNonAirBlockFromTop(World world, int x, int z)
- {
- int y;
- for (y = world.getActualHeight(); world.isAirBlock(x, y - 1, z) && y > 0; y--)
- {
- }
- return y;
- }
-
- public static boolean isBlockHit(MovingObjectPosition mop, TileEntity tile)
- {
- if (tile == null) return false;
- return isBlockHit(mop, tile.xCoord, tile.yCoord, tile.zCoord);
- }
-
- public static boolean isBlockHit(MovingObjectPosition mop, int x, int y, int z)
- {
- if (mop == null) return false;
- return mop.blockX == x && mop.blockY == y && mop.blockZ == z;
- }
-
} \ No newline at end of file