Search in sources :

Example 21 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Wizardry by TeamWizardry.

the class BlockFluidMana method run.

public static void run(World world, BlockPos pos, Block block, Entity entity, Predicate<Entity> test, Consumer<Entity> process) {
    if (!(block instanceof IFluidBlock))
        return;
    float height;
    IBlockState up = world.getBlockState(pos.up());
    if (up.getMaterial().isLiquid() || up.getBlock() instanceof IFluidBlock)
        height = 1f;
    else
        height = ((IFluidBlock) block).getFilledPercentage(world, pos) * 0.875f;
    AxisAlignedBB bb = new AxisAlignedBB(pos).contract(0, 1 - height, 0);
    AxisAlignedBB entityBox = entity.getCollisionBoundingBox();
    if ((entityBox == null || entityBox.intersects(bb)) && test.test(entity))
        process.accept(entity);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 22 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Wizardry by TeamWizardry.

the class BlockFluidLethe method run.

public static void run(World world, BlockPos pos, Block block, Entity entity, Predicate<Entity> test, Consumer<Entity> process) {
    if (!(block instanceof IFluidBlock))
        return;
    float height;
    IBlockState up = world.getBlockState(pos.up());
    if (up.getMaterial().isLiquid() || up.getBlock() instanceof IFluidBlock)
        height = 1f;
    else
        height = ((IFluidBlock) block).getFilledPercentage(world, pos) * 0.875f;
    AxisAlignedBB bb = new AxisAlignedBB(pos).contract(0, 1 - height, 0);
    AxisAlignedBB entityBox = entity.getCollisionBoundingBox();
    if ((entityBox == null || entityBox.intersects(bb)) && test.test(entity))
        process.accept(entity);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 23 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project TechReborn by TechReborn.

the class DynamicCell method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    if (!worldIn.isRemote) {
        RayTraceResult result = rayTrace(worldIn, playerIn, true);
        if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
            BlockPos pos = result.getBlockPos();
            IBlockState state = worldIn.getBlockState(pos);
            Block block = state.getBlock();
            if (block instanceof IFluidBlock) {
                IFluidBlock fluidBlock = (IFluidBlock) block;
                if (fluidBlock.canDrain(worldIn, pos)) {
                    FluidStack fluid = fluidBlock.drain(worldIn, pos, false);
                    if (fluid != null && fluid.amount == DynamicCell.CAPACITY) {
                        if (tryAddCellToInventory(playerIn, stack, fluid.getFluid())) {
                            fluidBlock.drain(worldIn, pos, true);
                            return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                        }
                    }
                }
            } else if (block instanceof BlockStaticLiquid) {
                Fluid fluid = block.getMaterial(state) == Material.LAVA ? FluidRegistry.LAVA : FluidRegistry.WATER;
                if (tryAddCellToInventory(playerIn, stack, fluid)) {
                    if (fluid != FluidRegistry.WATER)
                        worldIn.setBlockToAir(pos);
                    return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
                }
            }
        }
    }
    return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) BlockStaticLiquid(net.minecraft.block.BlockStaticLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 24 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project NetherEx by LogicTechCorp.

the class NetherExModels method registerModel.

private static void registerModel(IFluidBlock block) {
    Item item = Item.getItemFromBlock((Block) block);
    ModelBakery.registerItemVariants(item);
    ModelResourceLocation modelLocation = new ModelResourceLocation(NetherEx.MOD_ID + ":fluid", block.getFluid().getName());
    ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelLocation));
    ModelLoader.setCustomStateMapper((Block) block, new StateMapperBase() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            return modelLocation;
        }
    });
}
Also used : nex.block(nex.block) NetherExItems(nex.init.NetherExItems) Item(net.minecraft.item.Item) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) ModelBakery(net.minecraft.client.renderer.block.model.ModelBakery) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) Mod(net.minecraftforge.fml.common.Mod) ModelLoader(net.minecraftforge.client.model.ModelLoader) NetherExBlocks(nex.init.NetherExBlocks) BlockWall(net.minecraft.block.BlockWall) ItemMeshDefinition(net.minecraft.client.renderer.ItemMeshDefinition) EnumFacing(net.minecraft.util.EnumFacing) BlockSlab(net.minecraft.block.BlockSlab) NetherEx(nex.NetherEx) BlockFenceGate(net.minecraft.block.BlockFenceGate) IBlockState(net.minecraft.block.state.IBlockState) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Logger(org.apache.logging.log4j.Logger) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ItemSalamanderHide(nex.item.ItemSalamanderHide) StateMap(net.minecraft.client.renderer.block.statemap.StateMap) LogManager(org.apache.logging.log4j.LogManager) StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 25 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Witchworks by Um-Mitternacht.

the class CommonRegistration method registerBlocks.

@SubscribeEvent
public static void registerBlocks(RegistryEvent.Register<Block> event) {
    final IForgeRegistry<Block> registry = event.getRegistry();
    ModTiles.registerAll();
    registry.registerAll(//Crops
    new BlockCrop(LibBlockName.CROP_ACONITUM), new BlockCrop(LibBlockName.CROP_ASPHODEL), new BlockCrop(LibBlockName.CROP_GINGER), new CropMint(), new BlockCrop(LibBlockName.CROP_WHITE_SAGE), new BlockCrop(LibBlockName.CROP_MANDRAKE), new BlockCrop(LibBlockName.CROP_LAVENDER), new CropSilphium(), new CropThistle(), new BlockCrop(LibBlockName.CROP_TULSI), new CropKenaf(), new BlockCrop(LibBlockName.CROP_GARLIC), new CropWormwood(), new CropKelp(), new CropBelladonna(), new BlockBeehive(), //Ore
    new BlockMod(LibBlockName.SILVER_BLOCK, Material.IRON).setSound(SoundType.METAL).setHardness(5.0F), new BlockMod(LibBlockName.SILVER_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(2.0F), new BlockMod(LibBlockName.MOLDAVITE_BLOCK, Material.ROCK).setSound(SoundType.GLASS).setHardness(5.0F), new BlockMod(LibBlockName.MOLDAVITE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.TOURMALINE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.MALACHITE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.TOURMALINE_BLOCK, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.JASPER_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.BLOODSTONE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.TIGERS_EYE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.NUUMMITE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.GARNET_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.SALT_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.ALEXANDRITE_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.COQUINA, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.CHALK, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.AMETHYST_ORE, Material.ROCK).setSound(SoundType.STONE).setHardness(7.0F), //Normal Blocks
    new BlockMod(LibBlockName.BLOODSTONE_BLOCK, Material.ROCK).setSound(SoundType.STONE).setHardness(5.0F), new BlockMod(LibBlockName.NETHERSTEEL, Material.IRON).setSound(SoundType.METAL).setHardness(5.0F), //Tool Blocks
    new BlockKettle(), new BlockCandleLarge(), new BlockCandleMedium(), new BlockCandleSmall(), new BlockSaltBarrier(), new BlockApiary(), new BlockAltar());
    for (final IFluidBlock fluidBlock : Fluids.MOD_FLUID_BLOCKS) {
        registry.register((Block) fluidBlock);
    }
}
Also used : BlockMod(com.witchworks.common.block.BlockMod) BlockBeehive(com.witchworks.common.block.natural.BlockBeehive) BlockSaltBarrier(com.witchworks.common.block.magic.BlockSaltBarrier) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

IFluidBlock (net.minecraftforge.fluids.IFluidBlock)41 Block (net.minecraft.block.Block)28 IBlockState (net.minecraft.block.state.IBlockState)24 BlockLiquid (net.minecraft.block.BlockLiquid)18 BlockPos (net.minecraft.util.math.BlockPos)13 ItemStack (net.minecraft.item.ItemStack)11 FluidStack (net.minecraftforge.fluids.FluidStack)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 TileEntity (net.minecraft.tileentity.TileEntity)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 Fluid (net.minecraftforge.fluids.Fluid)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 Entity (net.minecraft.entity.Entity)4 World (net.minecraft.world.World)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 BlockStaticLiquid (net.minecraft.block.BlockStaticLiquid)3 Item (net.minecraft.item.Item)3 ItemBlock (net.minecraft.item.ItemBlock)3 EnumFacing (net.minecraft.util.EnumFacing)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3