Fix NPE in Crusher ritual (#739)
Also adds a utility for spawning an itemstack at a specific block location
This commit is contained in:
parent
b684aebdaa
commit
d70f423a10
2 changed files with 69 additions and 4 deletions
|
@ -44,6 +44,8 @@ import WayofTime.bloodmagic.tile.TileInventory;
|
|||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
public static NBTTagCompound getPersistentDataTag(EntityPlayer player)
|
||||
|
@ -686,6 +688,59 @@ public class Utils
|
|||
return (state instanceof IFluidBlock || state.getMaterial().isLiquid());
|
||||
}
|
||||
|
||||
public static boolean spawnStackAtBlock(World world, BlockPos pos, @Nullable EnumFacing pushDirection, ItemStack stack)
|
||||
{
|
||||
EntityItem entityItem = new EntityItem(world);
|
||||
BlockPos spawnPos = new BlockPos(pos);
|
||||
double velocity = 0.15D;
|
||||
if (pushDirection != null)
|
||||
{
|
||||
spawnPos.offset(pushDirection);
|
||||
|
||||
switch (pushDirection) {
|
||||
case DOWN:
|
||||
{
|
||||
entityItem.motionY = -velocity;
|
||||
entityItem.setPosition(spawnPos.getX() + 0.5D, spawnPos.getY() - 1.0D, spawnPos.getZ() + 0.5D);
|
||||
break;
|
||||
}
|
||||
case UP:
|
||||
{
|
||||
entityItem.motionY = velocity;
|
||||
entityItem.setPosition(spawnPos.getX() + 0.5D, spawnPos.getY() + 1.0D, spawnPos.getZ() + 0.5D);
|
||||
break;
|
||||
}
|
||||
case NORTH:
|
||||
{
|
||||
entityItem.motionZ = -velocity;
|
||||
entityItem.setPosition(spawnPos.getX() + 0.5D, spawnPos.getY() + 0.5D, spawnPos.getZ() - 1.0D);
|
||||
break;
|
||||
}
|
||||
case SOUTH:
|
||||
{
|
||||
entityItem.motionZ = velocity;
|
||||
entityItem.setPosition(spawnPos.getX() + 0.5D, spawnPos.getY() + 0.5D, spawnPos.getZ() + 1.0D);
|
||||
break;
|
||||
}
|
||||
case WEST:
|
||||
{
|
||||
entityItem.motionX = -velocity;
|
||||
entityItem.setPosition(spawnPos.getX() - 1.0D, spawnPos.getY() + 0.5D, spawnPos.getZ() + 0.5D);
|
||||
break;
|
||||
}
|
||||
case EAST:
|
||||
{
|
||||
entityItem.motionX = velocity;
|
||||
entityItem.setPosition(spawnPos.getX() + 1.0D, spawnPos.getY() + 0.5D, spawnPos.getZ() + 0.5D);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entityItem.setEntityItemStack(stack);
|
||||
return world.spawnEntityInWorld(entityItem);
|
||||
}
|
||||
|
||||
public static boolean swapLocations(World initialWorld, BlockPos initialPos, World finalWorld, BlockPos finalPos)
|
||||
{
|
||||
TileEntity initialTile = initialWorld.getTileEntity(initialPos);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue