Search in sources :

Example 36 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.

the class ModelLoader method loadItemModels.

@Override
protected void loadItemModels() {
    // register model for the universal bucket, if it exists
    if (FluidRegistry.isUniversalBucketEnabled()) {
        setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
    }
    registerVariantNames();
    List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {

        public boolean apply(Item item) {
            return item.getRegistryName() != null;
        }
    }));
    Collections.sort(items, new Comparator<Item>() {

        public int compare(Item i1, Item i2) {
            return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
        }
    });
    ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
    for (Item item : items) {
        itemBar.step(item.getRegistryName().toString());
        for (String s : getVariantNames(item)) {
            ResourceLocation file = getItemLocation(s);
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getMissingModel();
            Exception exception = null;
            try {
                model = ModelLoaderRegistry.getModel(file);
            } catch (Exception normalException) {
                // try blockstate json if the item model is missing
                FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
                try {
                    model = ModelLoaderRegistry.getModel(memory);
                } catch (Exception blockstateException) {
                    exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
                }
            }
            if (exception != null) {
                storeException(memory, exception);
                model = ModelLoaderRegistry.getMissingModel(memory, exception);
            }
            stateModels.put(memory, model);
        }
    }
    ProgressManager.pop(itemBar);
    // replace vanilla bucket models if desired. done afterwards for performance reasons
    if (ForgeModContainer.replaceVanillaBucketModel) {
        // ensure the bucket model is loaded
        if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
            // load forges blockstate json for it
            try {
                registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
            } catch (Exception exception) {
                FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
                return;
            }
        }
        // empty bucket
        for (String s : getVariantNames(Items.BUCKET)) {
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
            // only on successful load, otherwise continue using the old model
            if (model != getMissingModel()) {
                stateModels.put(memory, model);
            }
        }
        setBucketModel(Items.WATER_BUCKET);
        setBucketModel(Items.LAVA_BUCKET);
        // milk bucket only replaced if some mod adds milk
        if (FluidRegistry.isFluidRegistered("milk")) {
            // can the milk be put into a bucket?
            Fluid milk = FluidRegistry.getFluid("milk");
            FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
            IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
            if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
                setBucketModel(Items.MILK_BUCKET);
            }
        } else {
            // milk bucket if no milk fluid is present
            for (String s : getVariantNames(Items.MILK_BUCKET)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
                // only on successful load, otherwise continue using the old model
                if (model != getMissingModel()) {
                    stateModels.put(memory, model);
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Predicate(com.google.common.base.Predicate) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Example 37 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.

the class FluidHandlerConcatenate method drain.

@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
    if (maxDrain == 0)
        return null;
    FluidStack totalDrained = null;
    for (IFluidHandler handler : subHandlers) {
        if (totalDrained == null) {
            totalDrained = handler.drain(maxDrain, doDrain);
            if (totalDrained != null) {
                maxDrain -= totalDrained.amount;
            }
        } else {
            FluidStack copy = totalDrained.copy();
            copy.amount = maxDrain;
            FluidStack drain = handler.drain(copy, doDrain);
            if (drain != null) {
                totalDrained.amount += drain.amount;
                maxDrain -= drain.amount;
            }
        }
        if (maxDrain <= 0)
            break;
    }
    return totalDrained;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 38 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.

the class BlockLiquidWrapper method getTankProperties.

@Override
public IFluidTankProperties[] getTankProperties() {
    FluidStack containedStack = null;
    IBlockState blockState = world.getBlockState(blockPos);
    if (blockState.getBlock() == blockLiquid) {
        containedStack = getStack(blockState);
    }
    return new FluidTankProperties[] { new FluidTankProperties(containedStack, Fluid.BUCKET_VOLUME, false, true) };
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidTankProperties(net.minecraftforge.fluids.capability.FluidTankProperties) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 39 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.

the class FluidBlockWrapper method getTankProperties.

@Override
public IFluidTankProperties[] getTankProperties() {
    float percentFilled = fluidBlock.getFilledPercentage(world, blockPos);
    if (percentFilled < 0) {
        percentFilled *= -1;
    }
    int amountFilled = Math.round(Fluid.BUCKET_VOLUME * percentFilled);
    FluidStack fluid = amountFilled > 0 ? new FluidStack(fluidBlock.getFluid(), amountFilled) : null;
    return new FluidTankProperties[] { new FluidTankProperties(fluid, Fluid.BUCKET_VOLUME, false, true) };
}
Also used : IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) FluidTankProperties(net.minecraftforge.fluids.capability.FluidTankProperties) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 40 with FluidStack

use of net.minecraftforge.fluids.FluidStack in project MinecraftForge by MinecraftForge.

the class DynBucketTest method onBucketFill.

@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
    RayTraceResult target = event.getTarget();
    if (target != null) {
        IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
        if (state.getBlock() instanceof IFluidBlock) {
            Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
            FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
            ItemStack bucket = event.getEmptyBucket();
            IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
            if (fluidHandler != null) {
                int fillAmount = fluidHandler.fill(fs, true);
                if (fillAmount > 0) {
                    ItemStack filledBucket = fluidHandler.getContainer();
                    event.setFilledBucket(filledBucket);
                    event.setResult(Result.ALLOW);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) TestFluid(net.minecraftforge.debug.ModelFluidDebug.TestFluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

FluidStack (net.minecraftforge.fluids.FluidStack)188 ItemStack (net.minecraft.item.ItemStack)63 TileEntity (net.minecraft.tileentity.TileEntity)30 Fluid (net.minecraftforge.fluids.Fluid)28 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)25 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)19 ArrayList (java.util.ArrayList)18 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)16 Block (net.minecraft.block.Block)12 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)10 Item (net.minecraft.item.Item)9 BlockPos (net.minecraft.util.math.BlockPos)9 HashMap (java.util.HashMap)6 FluidIdentifier (logisticspipes.utils.FluidIdentifier)6 StandardTank (mods.railcraft.common.fluids.tanks.StandardTank)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)5 IBlockState (net.minecraft.block.state.IBlockState)5 EnumFacing (net.minecraft.util.EnumFacing)5