Search in sources :

Example 76 with IProperty

use of net.minecraft.block.properties.IProperty in project Wizardry by TeamWizardry.

the class FluidRecipeBuilder method buildFluidCrafter.

public static FluidCrafter buildFluidCrafter(String identifier, ItemStack outputItem, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp, boolean instant) {
    Ingredient outputIngredient = Ingredient.fromStacks(outputItem);
    List<Ingredient> inputs = Lists.newArrayList(extraInputs);
    return new FluidCrafter((world, pos, items) -> {
        if (allLiquidInPool(world, pos, required, fluid).size() < required)
            return false;
        List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            boolean foundMatch = false;
            List<ItemStack> toRemove = new LinkedList<>();
            for (ItemStack item : list) {
                if (itemIn.apply(item) && !outputIngredient.apply(item)) {
                    foundMatch = true;
                    item.shrink(1);
                    if (item.isEmpty())
                        toRemove.add(item);
                    break;
                }
            }
            if (!foundMatch)
                return false;
            list.removeAll(toRemove);
            toRemove.clear();
        }
        return true;
    }, (world, pos, items, currentDuration) -> {
        EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
        if (entityItem != null) {
            if (world.isRemote)
                LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
            if (bubbling && currentDuration % 10 == 0)
                world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
        }
    }, (world, pos, items, currentDuration) -> {
        if (consume) {
            Block block = fluid.getBlock();
            if (block != null) {
                IBlockState defaultState = block.getDefaultState();
                Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
                IBlockState drainState = defaultState;
                if (properties.hasNext())
                    drainState = drainState.cycleProperty(properties.next());
                for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
            }
        }
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        int count = 0;
        recipeLoop: {
            boolean itemFound = false;
            do {
                for (Ingredient itemIn : inputList) {
                    for (EntityItem entity : items) {
                        if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
                            entity.getItem().shrink(1);
                            if (entity.getItem().isEmpty())
                                entity.setDead();
                            break;
                        }
                    }
                }
                count += outputItem.getCount();
                for (Ingredient itemIn : inputList) {
                    itemFound = false;
                    for (EntityItem entity : items) {
                        if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
                            itemFound = true;
                            break;
                        }
                    }
                    if (!itemFound)
                        break recipeLoop;
                }
            } while (duration == 0 && !consume && instant && itemFound);
        }
        EntityItem output;
        do {
            output = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, outputItem.copy());
            output.getItem().setCount(Math.min(count, outputItem.getMaxStackSize()));
            output.motionX = 0;
            output.motionY = 0;
            output.motionZ = 0;
            output.forceSpawn = true;
            world.spawnEntity(output);
            count -= outputItem.getMaxStackSize();
        } while (count > 0);
        if (explode) {
            PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output.getPositionVector(), Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.posX, output.posY, output.posZ, 256));
            PosUtils.boom(world, output.getPositionVector(), output, 3, false);
        }
        if (harp)
            world.playSound(null, output.posX, output.posY, output.posZ, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
    }, identifier, duration).setInputs(input, inputs).setOutput(outputItem).setDoesConsume(consume).setRequired(required).setFluid(fluid);
}
Also used : Color(java.awt.Color) Ingredient(net.minecraft.item.crafting.Ingredient) ModFluids(com.teamwizardry.wizardry.common.block.fluid.ModFluids) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) PosUtils(com.teamwizardry.wizardry.api.util.PosUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) ModSounds(com.teamwizardry.wizardry.init.ModSounds) Fluid(net.minecraftforge.fluids.Fluid) LinkedList(java.util.LinkedList) SoundCategory(net.minecraft.util.SoundCategory) EntityItem(net.minecraft.entity.item.EntityItem) PacketHandler(com.teamwizardry.librarianlib.features.network.PacketHandler) Iterator(java.util.Iterator) World(net.minecraft.world.World) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) FluidStack(net.minecraftforge.fluids.FluidStack) Collections(java.util.Collections) IBlockState(net.minecraft.block.state.IBlockState) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) Ingredient(net.minecraft.item.crafting.Ingredient) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 77 with IProperty

use of net.minecraft.block.properties.IProperty in project Wizardry by TeamWizardry.

the class FluidRecipeBuilder method buildFluidCrafter.

public static FluidCrafter buildFluidCrafter(String identifier, IBlockState outputBlock, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
    List<Ingredient> inputs = Lists.newArrayList(extraInputs);
    FluidCrafter builder = new FluidCrafter((world, pos, items) -> {
        if (allLiquidInPool(world, pos, required, fluid).size() < required)
            return false;
        List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            boolean foundMatch = false;
            List<ItemStack> toRemove = new LinkedList<>();
            for (ItemStack item : list) {
                if (itemIn.apply(item)) {
                    foundMatch = true;
                    item.shrink(1);
                    if (item.isEmpty())
                        toRemove.add(item);
                    break;
                }
            }
            if (!foundMatch)
                return false;
            list.removeAll(toRemove);
            toRemove.clear();
        }
        return true;
    }, (world, pos, items, currentDuration) -> {
        EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
        if (entityItem != null) {
            if (world.isRemote)
                LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
            if (bubbling && currentDuration % 10 == 0)
                world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
        }
    }, (world, pos, items, currentDuration) -> {
        if (consume) {
            Block block = fluid.getBlock();
            if (block != null) {
                IBlockState defaultState = block.getDefaultState();
                Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
                IBlockState drainState = defaultState;
                if (properties.hasNext())
                    drainState = drainState.cycleProperty(properties.next());
                for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
            }
        }
        List<Ingredient> inputList = new ArrayList<>(inputs);
        inputList.add(input);
        for (Ingredient itemIn : inputList) {
            for (EntityItem entity : items) {
                if (itemIn.apply(entity.getItem())) {
                    entity.getItem().shrink(1);
                    if (entity.getItem().isEmpty())
                        entity.setDead();
                }
            }
        }
        world.setBlockState(pos, outputBlock);
        Vec3d output = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
        if (explode) {
            PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output, Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.x, output.y, output.z, 256));
            PosUtils.boom(world, output, null, 3, false);
        }
        if (harp)
            world.playSound(null, output.x, output.y, output.z, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
    }, identifier, duration).setInputs(input, inputs).setIsBlock(true).setDoesConsume(true).setRequired(required).setFluid(fluid);
    Fluid fluidOutput = FluidRegistry.lookupFluidForBlock(outputBlock.getBlock());
    if (fluidOutput != null)
        builder.setOutput(new FluidStack(fluidOutput, 1000));
    else
        builder.setOutput(new ItemStack(outputBlock.getBlock(), 1, outputBlock.getBlock().damageDropped(outputBlock)));
    return builder;
}
Also used : Color(java.awt.Color) Ingredient(net.minecraft.item.crafting.Ingredient) ModFluids(com.teamwizardry.wizardry.common.block.fluid.ModFluids) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) PosUtils(com.teamwizardry.wizardry.api.util.PosUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) ModSounds(com.teamwizardry.wizardry.init.ModSounds) Fluid(net.minecraftforge.fluids.Fluid) LinkedList(java.util.LinkedList) SoundCategory(net.minecraft.util.SoundCategory) EntityItem(net.minecraft.entity.item.EntityItem) PacketHandler(com.teamwizardry.librarianlib.features.network.PacketHandler) Iterator(java.util.Iterator) World(net.minecraft.world.World) Set(java.util.Set) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) FluidStack(net.minecraftforge.fluids.FluidStack) Collections(java.util.Collections) IBlockState(net.minecraft.block.state.IBlockState) PacketExplode(com.teamwizardry.wizardry.common.network.PacketExplode) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) Vec3d(net.minecraft.util.math.Vec3d) Ingredient(net.minecraft.item.crafting.Ingredient) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 78 with IProperty

use of net.minecraft.block.properties.IProperty in project Solar by ArekkuusuJerii.

the class TileMechanicalTranslocator method getRotationState.

private IBlockState getRotationState(IBlockState original, EnumFacing from, EnumFacing to) {
    ProfilerHelper.begin("[Mechanical Translocator] Rotating block");
    boolean hasProperty = false;
    for (IProperty<?> p : original.getPropertyKeys()) {
        if (p.getValueClass().equals(EnumFacing.class) && p.getName().toLowerCase(Locale.ROOT).contains("facing")) {
            hasProperty = true;
            // noinspection unchecked
            IProperty<EnumFacing> property = (IProperty<EnumFacing>) p;
            EnumFacing actual = original.getValue(property);
            original = apply(property, original, FacingHelper.rotate(actual, from, to));
            break;
        }
    }
    if (!hasProperty) {
        // uwu
        original = original.withRotation(FacingHelper.getHorizontalRotation(from, to));
    }
    ProfilerHelper.end();
    return original;
}
Also used : IProperty(net.minecraft.block.properties.IProperty) EnumFacing(net.minecraft.util.EnumFacing)

Aggregations

IProperty (net.minecraft.block.properties.IProperty)78 IBlockState (net.minecraft.block.state.IBlockState)43 Block (net.minecraft.block.Block)23 EnumFacing (net.minecraft.util.EnumFacing)15 ResourceLocation (net.minecraft.util.ResourceLocation)15 ItemStack (net.minecraft.item.ItemStack)14 Map (java.util.Map)11 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)11 ArrayList (java.util.ArrayList)10 BlockPos (net.minecraft.util.math.BlockPos)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)10 TileEntity (net.minecraft.tileentity.TileEntity)8 List (java.util.List)7 BlockStateContainer (net.minecraft.block.state.BlockStateContainer)7 World (net.minecraft.world.World)7 JsonObject (com.google.gson.JsonObject)6 Collectors (java.util.stream.Collectors)6 ExtendedBlockState (net.minecraftforge.common.property.ExtendedBlockState)6 FluidStack (net.minecraftforge.fluids.FluidStack)6 Lists (com.google.common.collect.Lists)5