From 53b72eaaa06603c5027831785acccd40d7c3e726 Mon Sep 17 00:00:00 2001 From: Robert Seifert Date: Sat, 20 Apr 2013 07:36:23 -0400 Subject: [PATCH] pulled classes out of other mods These were in the same dark file package however were in different repos. As time goes I'll try to collect the rest of the files. For the moment many of this libraries class are hiding in my other mods both current and dead. --- .../dark/helpers/ConnectionHelper.java | 84 ++++++++++ src/minecraft/dark/helpers/DebugToPlayer.java | 52 +++++++ .../dark/helpers/ItemFindingHelper.java | 145 ++++++++++++++++++ src/minecraft/dark/helpers/MetaGroup.java | 46 ++++++ 4 files changed, 327 insertions(+) create mode 100644 src/minecraft/dark/helpers/ConnectionHelper.java create mode 100644 src/minecraft/dark/helpers/DebugToPlayer.java create mode 100644 src/minecraft/dark/helpers/ItemFindingHelper.java create mode 100644 src/minecraft/dark/helpers/MetaGroup.java diff --git a/src/minecraft/dark/helpers/ConnectionHelper.java b/src/minecraft/dark/helpers/ConnectionHelper.java new file mode 100644 index 00000000..140aad1a --- /dev/null +++ b/src/minecraft/dark/helpers/ConnectionHelper.java @@ -0,0 +1,84 @@ +package dark.helpers; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.vector.Vector3; + +public class ConnectionHelper +{ + /** + * Used to find all tileEntities sounding the location you will have to filter for selective + * tileEntities + * + * @param world - the world being searched threw + * @param x + * @param y + * @param z + * @return an array of up to 6 tileEntities + */ + public static TileEntity[] getSurroundingTileEntities(TileEntity ent) + { + return getSurroundingTileEntities(ent.worldObj, ent.xCoord, ent.yCoord, ent.zCoord); + + } + + public static TileEntity[] getSurroundingTileEntities(World world, int x, int y, int z) + { + TileEntity[] list = new TileEntity[6]; + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + list[direction.ordinal()] = world.getBlockTileEntity(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); + } + return list; + } + + public static int[] getSurroundingBlocks(TileEntity ent) + { + return getSurroundingBlocks(ent.worldObj, ent.xCoord, ent.yCoord, ent.zCoord); + } + + public static int[] getSurroundingBlocks(World world, Vector3 v) + { + return ConnectionHelper.getSurroundingBlocks(world, v.intX(), v.intY(), v.intZ()); + } + + public static int[] getSurroundingBlocks(World world, int x, int y, int z) + { + int[] list = new int[6]; + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + int id = world.getBlockId(x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ); + list[direction.ordinal()] = id; + } + return list; + } + + /** + * Used to find which of 4 Corners this block is in a group of blocks 0 = not a corner 1-4 = a + * corner of some direction + */ + public static int corner(TileEntity entity) + { + TileEntity[] en = getSurroundingTileEntities(entity.worldObj, entity.xCoord, entity.yCoord, entity.zCoord); + if (en[4] != null && en[2] != null && en[5] == null && en[3] == null) + { + return 3; + } + if (en[2] != null && en[5] != null && en[3] == null && en[4] == null) + { + return 4; + } + if (en[5] != null && en[3] != null && en[4] == null && en[2] == null) + { + return 1; + } + if (en[3] != null && en[4] != null && en[2] == null && en[5] == null) + { + return 2; + } + + return 0; + + } +} diff --git a/src/minecraft/dark/helpers/DebugToPlayer.java b/src/minecraft/dark/helpers/DebugToPlayer.java new file mode 100644 index 00000000..37873898 --- /dev/null +++ b/src/minecraft/dark/helpers/DebugToPlayer.java @@ -0,0 +1,52 @@ +package dark.helpers; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class DebugToPlayer +{ + /** + * Sends a message to the closest player + * + * @param range - range + * @param msg - display message under 200 chars + */ + public static void SendToClosest(World world, int x, int y, int z, int range, String msg) + { + EntityPlayer player = world.getClosestPlayer(x, y, z, range); + if (player != null) + { + msg = trimForDisplay(msg); + player.sendChatToPlayer("Debug: " + msg); + } + } + + /** + * Sends a debug message to the player using the tileEntity as the center + * + * @param r - range + * @param msg - display message under 200 chars + */ + public static void SendToClosest(TileEntity ent, int r, String msg) + { + if (ent != null) + { + DebugToPlayer.SendToClosest(ent.worldObj, ent.xCoord, ent.yCoord, ent.zCoord, r, msg); + } + } + + /** + * cleans up the display text and adds the [Debug] prefix too the text + * + * @param msg - display string under 200 chars + * @return + */ + public static String trimForDisplay(String msg) + { + // TODO trim the length to under 255 to prevent crashing + msg = msg.trim(); + msg = "[Debug] " + msg; + return msg; + } +} diff --git a/src/minecraft/dark/helpers/ItemFindingHelper.java b/src/minecraft/dark/helpers/ItemFindingHelper.java new file mode 100644 index 00000000..f3a696b2 --- /dev/null +++ b/src/minecraft/dark/helpers/ItemFindingHelper.java @@ -0,0 +1,145 @@ +package dark.helpers; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import universalelectricity.core.vector.Vector3; + +public class ItemFindingHelper +{ + + /** + * gets all EntityItems in a location using a start and end point + */ + public static List findAllItemIn(World world, Vector3 start, Vector3 end) + { + return world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(start.x, start.y, start.z, end.x, end.x, end.x)); + } + + /** + * Gets all EntityItems in an area and sorts them by a list of itemStacks + * + * @param world - world being worked in + * @param start - start point + * @param end - end point + * @param disiredItems - list of item that are being looked for + * @return a list of EntityItem that match the itemStacks desired + */ + public static List findSelectItems(World world, Vector3 start, Vector3 end, List disiredItems) + { + List entityItems = ItemFindingHelper.findAllItemIn(world, start, end); + return filterEntityItemsList(entityItems, disiredItems); + } + + /** + * filters an EntityItem List to a List of Items + */ + public static List filterEntityItemsList(List entityItems, List disiredItems) + { + List newItemList = new ArrayList(); + + for (EntityItem entityItem : entityItems) + { + for (ItemStack itemStack : disiredItems) + { + if (entityItem.getEntityItem().itemID == itemStack.itemID && entityItem.getEntityItem().getItemDamage() == itemStack.getItemDamage() && !newItemList.contains(entityItem)) + { + newItemList.add(entityItem); + break; + } + } + } + return newItemList; + } + + /** + * filters out EnittyItems from an Entity list + */ + public static List filterOutEntityItems(List entities) + { + List newEntityList = new ArrayList(); + + for (Entity entity : entities) + { + if (entity instanceof EntityItem) + { + newEntityList.add((EntityItem) entity); + } + + } + return newEntityList; + } + + /** + * filter a list of itemStack to another list of itemStacks + * + * @param totalItems - full list of items being filtered + * @param desiredItems - list the of item that are being filtered too + * @return a list of item from the original that are wanted + */ + public static List filterItems(List totalItems, List desiredItems) + { + List newItemList = new ArrayList(); + + for (ItemStack entityItem : totalItems) + { + for (ItemStack itemStack : desiredItems) + { + if (entityItem.itemID == itemStack.itemID && entityItem.getItemDamage() == itemStack.getItemDamage() && !newItemList.contains(entityItem)) + { + newItemList.add(entityItem); + break; + } + } + } + return newItemList; + } + + /** + * Drops an item stack at the exact center of the location without any velocity or random throw + * angle + * + * @param world - world to drop the item in + * @param x y z - location vector + * @param stack - itemstack to drop + * @return if the item was spawned in the world + */ + public static boolean dropItemStackExact(World world, double x, double y, double z, ItemStack stack) + { + if (!world.isRemote && stack != null) + { + EntityItem entity = new EntityItem(world, x, y, z, stack); + entity.delayBeforeCanPickup = 10; + return world.spawnEntityInWorld(entity); + } + return false; + } + + /** + * grabs all the items that the block can drop then pass them onto dropBlockAsItem_do + * + * @param world + * @param x + * @param y + * @param z + */ + public static void dropBlockAsItem(World world, int x, int y, int z) + { + if (!world.isRemote) + { + int meta = world.getBlockMetadata(x, y, z); + int id = world.getBlockId(x, y, z); + ArrayList items = Block.blocksList[id].getBlockDropped(world, x, y, z, meta, 0); + + for (ItemStack item : items) + { + dropItemStackExact(world, x + .5, y + .5, z + .5, item); + } + } + } +} diff --git a/src/minecraft/dark/helpers/MetaGroup.java b/src/minecraft/dark/helpers/MetaGroup.java new file mode 100644 index 00000000..49e7d46e --- /dev/null +++ b/src/minecraft/dark/helpers/MetaGroup.java @@ -0,0 +1,46 @@ +package dark.helpers; + + +public class MetaGroup +{ + public static int getFacingMeta(int metaData) + { + int meta = metaData % 4; + int newMeta = 0; + switch (meta) + { + case 0: + newMeta = 2; + break; + case 1: + newMeta = 5; + break; + case 2: + newMeta = 3; + break; + case 3: + newMeta = 4; + } + + return newMeta; + } + + public static int getGrouping(int meta) + { + if ((meta >= 0) && (meta <= 3)) + return 0; + if ((meta >= 4) && (meta <= 7)) + return 1; + if ((meta >= 8) && (meta <= 11)) + return 2; + if ((meta >= 12) && (meta <= 15)) + return 3; + return 0; + } + + public static int getGroupStartMeta(int grouping) + { + return grouping * 4; + } + +} \ No newline at end of file