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
|
@ -78,11 +78,14 @@ public class RitualCrushing extends Ritual
|
|||
ItemStack item = new ItemStack(block, 1, meta);
|
||||
ItemStack copyStack = ItemStack.copyItemStack(item);
|
||||
|
||||
if (tile != null)
|
||||
Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
|
||||
else
|
||||
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
||||
|
||||
if (copyStack.stackSize > 0)
|
||||
{
|
||||
world.spawnEntityInWorld(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 2, pos.getZ() + 0.5, copyStack));
|
||||
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
||||
}
|
||||
} else
|
||||
{
|
||||
|
@ -94,10 +97,17 @@ public class RitualCrushing extends Ritual
|
|||
{
|
||||
ItemStack copyStack = ItemStack.copyItemStack(item);
|
||||
|
||||
if (tile != null)
|
||||
{
|
||||
copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
|
||||
} else
|
||||
{
|
||||
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
||||
continue;
|
||||
}
|
||||
if (copyStack != null && copyStack.stackSize > 0)
|
||||
{
|
||||
world.spawnEntityInWorld(new EntityItem(world, pos.getX() + 0.5, pos.getY() + 2, pos.getZ() + 0.5, copyStack));
|
||||
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue