use of betterwithaddons.crafting.recipes.SpindleRecipe 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);
}
}
}
}
}
use of betterwithaddons.crafting.recipes.SpindleRecipe in project BetterWithAddons by DaedalusGame.
the class Spindle method add.
@ZenMethod
public static void add(IItemStack[] outputs, @NotNull IIngredient input, boolean consumesSpindle) {
SpindleRecipe r = new SpindleRecipe(consumesSpindle, InputHelper.toObject(input), InputHelper.toStacks(outputs));
MineTweakerAPI.apply(new Add(r));
}
use of betterwithaddons.crafting.recipes.SpindleRecipe in project BetterWithAddons by DaedalusGame.
the class CraftingManagerSpindle method removeRecipe.
public boolean removeRecipe(ItemStack[] outputs, Object input) {
SpindleRecipe recipe = createRecipe(outputs, input, true);
int matchingIndex = getMatchingRecipeIndex(recipe);
if (matchingIndex >= 0) {
this.recipes.remove(matchingIndex);
return true;
}
return false;
}
use of betterwithaddons.crafting.recipes.SpindleRecipe in project BetterWithAddons by DaedalusGame.
the class BlockSpindle method spinUpBolt.
private void spinUpBolt(World world, BlockPos pos, IBlockState state) {
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.getInput());
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