use of betterwithaddons.crafting.manager.CraftingManagerSpindle in project BetterWithAddons by DaedalusGame.
the class BlockSpindle method spinUp.
@Override
public void spinUp(World world, BlockPos pos, IBlockState state, EnumFacing dir) {
List<EntityItem> list = world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)), EntitySelectors.IS_ALIVE);
EnumFacing.Axis axis = state.getValue(AXIS);
if (list.size() > 0) {
CraftingManagerSpindle manager = CraftingManagerSpindle.getInstance();
SpindleRecipe recipe = manager.getMostValidRecipe(list);
if (recipe != null) {
ItemUtil.consumeItem(list, recipe.input);
List<ItemStack> ret = recipe.getOutput();
if (ret != null && ret.size() > 0) {
List<EnumFacing> validDirections = new ArrayList<>();
for (EnumFacing facing : EnumFacing.VALUES) {
if (facing.getAxis() == axis || facing == EnumFacing.UP)
continue;
IBlockState check = world.getBlockState(pos.offset(facing));
if (check.getBlock().isReplaceable(world, pos.offset(facing)) || world.isAirBlock(pos.offset(facing)))
validDirections.add(facing);
}
for (int i = 0; i < ret.size(); i++) {
ItemStack item = ret.get(i);
if (item.isEmpty())
continue;
EnumFacing ejectdir;
if (validDirections.isEmpty())
ejectdir = axis.isVertical() ? EnumFacing.HORIZONTALS[world.rand.nextInt(4)] : EnumFacing.DOWN;
else
ejectdir = validDirections.get(world.rand.nextInt(validDirections.size()));
EntityItem result = new EntityItem(world, pos.getX() + 0.5f + ejectdir.getFrontOffsetX() * 0.2f, pos.getY() + 0.1f, pos.getZ() + 0.5f + ejectdir.getFrontOffsetZ() * 0.2f, item.copy());
result.motionX = ejectdir.getFrontOffsetX() * 0.2;
result.motionY = 0;
result.motionZ = ejectdir.getFrontOffsetZ() * 0.2;
result.setDefaultPickupDelay();
if (!world.isRemote) {
world.spawnEntity(result);
}
}
if (recipe.consumesSpindle) {
world.setBlockToAir(pos);
}
}
}
}
}
Aggregations