merged connection and itemWorld helper
This commit is contained in:
parent
7b6fac6a42
commit
f54dc2fec4
3 changed files with 65 additions and 71 deletions
|
@ -21,7 +21,7 @@ import net.minecraftforge.event.Cancelable;
|
||||||
import net.minecraftforge.event.Event;
|
import net.minecraftforge.event.Event;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
import com.dark.helpers.ItemWorldHelper;
|
import com.dark.helpers.DarksHelper;
|
||||||
|
|
||||||
/** An event triggered by entities or tiles that create lasers
|
/** An event triggered by entities or tiles that create lasers
|
||||||
*
|
*
|
||||||
|
@ -265,7 +265,7 @@ public class LaserEvent extends Event
|
||||||
items = event.items;
|
items = event.items;
|
||||||
for (ItemStack stack : items)
|
for (ItemStack stack : items)
|
||||||
{
|
{
|
||||||
ItemWorldHelper.dropItemStack(world, vec.translate(0.5), stack, false);
|
DarksHelper.dropItemStack(world, vec.translate(0.5), stack, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
package com.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, Vector3 vec)
|
|
||||||
{
|
|
||||||
return getSurroundingTileEntities(world, vec.intX(), vec.intY(), vec.intZ());
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 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);
|
|
||||||
TileEntity north = en[ForgeDirection.NORTH.ordinal()];
|
|
||||||
TileEntity south = en[ForgeDirection.SOUTH.ordinal()];
|
|
||||||
TileEntity east = en[ForgeDirection.EAST.ordinal()];
|
|
||||||
TileEntity west = en[ForgeDirection.WEST.ordinal()];
|
|
||||||
|
|
||||||
if (west != null && north != null && east == null && south == null)
|
|
||||||
{
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
if (north != null && east != null && south == null && west == null)
|
|
||||||
{
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
if (east != null && south != null && west == null && north == null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (south != null && west != null && north == null && east == null)
|
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,14 +8,75 @@ import net.minecraft.command.IEntitySelector;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.AxisAlignedBB;
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
public class ItemWorldHelper
|
/** Class full of generic re-usable methods
|
||||||
|
*
|
||||||
|
* @author DarkGuardsman */
|
||||||
|
public class DarksHelper
|
||||||
{
|
{
|
||||||
|
/** 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, Vector3 vec)
|
||||||
|
{
|
||||||
|
return getSurroundingTileEntities(world, vec.intX(), vec.intY(), vec.intZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 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);
|
||||||
|
TileEntity north = en[ForgeDirection.NORTH.ordinal()];
|
||||||
|
TileEntity south = en[ForgeDirection.SOUTH.ordinal()];
|
||||||
|
TileEntity east = en[ForgeDirection.EAST.ordinal()];
|
||||||
|
TileEntity west = en[ForgeDirection.WEST.ordinal()];
|
||||||
|
|
||||||
|
if (west != null && north != null && east == null && south == null)
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
if (north != null && east != null && south == null && west == null)
|
||||||
|
{
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
if (east != null && south != null && west == null && north == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (south != null && west != null && north == null && east == null)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** gets all EntityItems in a location using a start and end point */
|
/** gets all EntityItems in a location using a start and end point */
|
||||||
public static List<EntityItem> findAllItemsIn(World world, Vector3 start, Vector3 end)
|
public static List<EntityItem> findAllItemsIn(World world, Vector3 start, Vector3 end)
|
||||||
{
|
{
|
||||||
|
@ -37,7 +98,7 @@ public class ItemWorldHelper
|
||||||
* @return a list of EntityItem that match the itemStacks desired */
|
* @return a list of EntityItem that match the itemStacks desired */
|
||||||
public static List<EntityItem> findSelectItems(World world, Vector3 start, Vector3 end, List<ItemStack> disiredItems)
|
public static List<EntityItem> findSelectItems(World world, Vector3 start, Vector3 end, List<ItemStack> disiredItems)
|
||||||
{
|
{
|
||||||
List<EntityItem> entityItems = ItemWorldHelper.findAllItemsIn(world, start, end);
|
List<EntityItem> entityItems = findAllItemsIn(world, start, end);
|
||||||
return filterEntityItemsList(entityItems, disiredItems);
|
return filterEntityItemsList(entityItems, disiredItems);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue