Search in sources :

Example 1 with SpindleRecipe

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);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SpindleRecipe(betterwithaddons.crafting.recipes.SpindleRecipe) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) CraftingManagerSpindle(betterwithaddons.crafting.manager.CraftingManagerSpindle) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with SpindleRecipe

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));
}
Also used : SpindleRecipe(betterwithaddons.crafting.recipes.SpindleRecipe) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 3 with SpindleRecipe

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;
}
Also used : SpindleRecipe(betterwithaddons.crafting.recipes.SpindleRecipe)

Example 4 with SpindleRecipe

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);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) SpindleRecipe(betterwithaddons.crafting.recipes.SpindleRecipe) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) CraftingManagerSpindle(betterwithaddons.crafting.manager.CraftingManagerSpindle) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

SpindleRecipe (betterwithaddons.crafting.recipes.SpindleRecipe)4 CraftingManagerSpindle (betterwithaddons.crafting.manager.CraftingManagerSpindle)2 ArrayList (java.util.ArrayList)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityItem (net.minecraft.entity.item.EntityItem)2 ItemStack (net.minecraft.item.ItemStack)2 EnumFacing (net.minecraft.util.EnumFacing)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)1