net.minecraftforge.fluids.BlockFluidBase Java Examples

The following examples show how to use net.minecraftforge.fluids.BlockFluidBase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Fluids.java    From BaseMetals with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public static void bakeModels(String modID){
	for(Fluid fluid : fluidBlocks.keySet()){
		BlockFluidBase block = fluidBlocks.get(fluid);
		Item item = Item.getItemFromBlock(block);
		final ModelResourceLocation fluidModelLocation = new ModelResourceLocation(
				modID.toLowerCase() + ":" + fluidBlockNames.get(block), "fluid");
           ModelBakery.registerItemVariants(item);
		ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
		{
			public ModelResourceLocation getModelLocation(ItemStack stack)
			{
				return fluidModelLocation;
			}
		});
		ModelLoader.setCustomStateMapper(block, new StateMapperBase()
		{
			protected ModelResourceLocation getModelResourceLocation(IBlockState state)
			{
				return fluidModelLocation;
			}
		});
	}
}
 
Example #2
Source File: MovementHandlerFluid.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Priority(PriorityEnum.OVERRIDE)
public BlockMovementType getMovementType(World world, int x, int y, int z, ForgeDirection side, IMovement movement) {

    Block b = world.getBlock(x, y, z);

    if (b instanceof BlockFluidBase) {
        if (((BlockFluidBase) b).getFilledPercentage(world, x, y, z) == 1F)
            return BlockMovementType.SEMI_MOVABLE;
        return BlockMovementType.UNMOVABLE;
    }
    if (b instanceof BlockLiquid) {
        if (BlockLiquid.getLiquidHeightPercent(world.getBlockMetadata(x, y, z)) == 1 / 9F)
            return BlockMovementType.SEMI_MOVABLE;
        return BlockMovementType.UNMOVABLE;
    }

    return null;
}
 
Example #3
Source File: FluidSpringPopulator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initializeForVein(OreDepositDefinition definition) {
    List<IBlockState> possibleStates = definition.getBlockFiller().getAllPossibleStates().stream()
        .flatMap(it -> it.getPossibleResults().stream())
        .collect(Collectors.toList());
    this.fluidState = possibleStates.stream().filter(it -> it.getPropertyKeys().contains(BlockFluidBase.LEVEL)).findFirst().orElse(null);
    if (fluidState == null) {
        String message = "Can't find fluid block for spring in vein %s. Blocks in vein: %s";
        throw new IllegalArgumentException(String.format(message, definition.getDepositName(), possibleStates));
    }
}
 
Example #4
Source File: RendererSwitchingColorFluid.java    From bartworks with MIT License 5 votes vote down vote up
private float getFluidHeightForRender(IBlockAccess world, int x, int y, int z, BlockFluidBase block) {

        if (world.getBlock(x, y, z) == block) {
            Block vOrigin = world.getBlock(x, y + 1, z);
            if (vOrigin.getMaterial().isLiquid() || vOrigin instanceof IFluidBlock) {
                return RendererSwitchingColorFluid.LIGHT_Y_POS;
            }
            if (world.getBlockMetadata(x, y, z) == block.getMaxRenderHeightMeta()) {
                return RendererSwitchingColorFluid.THREE_QUARTERS_FILLED;
            }
        }
        return (!world.getBlock(x, y, z).getMaterial().isSolid() && world.getBlock(x, y + 1, z) == block) ? RendererSwitchingColorFluid.LIGHT_Y_POS : (block.getQuantaPercentage(world, x, y, z) * RendererSwitchingColorFluid.THREE_QUARTERS_FILLED);
    }
 
Example #5
Source File: Fluids.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static BlockFluidBase registerFluidBlock(Fluid f, BlockFluidBase block, String name) {
	block.setUnlocalizedName(BaseMetals.MODID+"."+name);
	GameRegistry.registerBlock(block, name);
	block.setCreativeTab(CreativeTabs.MISC);
	FluidRegistry.addBucketForFluid(f);
	fluidBlocks.put(f, block);
	fluidBlockNames.put(block, name);
	return block;
}
 
Example #6
Source File: SchematicBlock.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BuildingStage getBuildStage () {
	if (block instanceof BlockFalling) {
		return BuildingStage.SUPPORTED;
	} else if (block instanceof BlockFluidBase || block instanceof BlockLiquid) {
		return BuildingStage.EXPANDING;
	} else if (block.isOpaqueCube()) {
		return BuildingStage.STANDALONE;
	} else {
		return BuildingStage.SUPPORTED;
	}
}
 
Example #7
Source File: ItemBlockPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public ItemBlockPneumaticCraft(Block block){
    super(block);
    if(block instanceof BlockPneumaticCraft) {
        this.block = (BlockPneumaticCraft)block;
    } else {
        if(!(block instanceof BlockPneumaticPlantBase) && !(block instanceof BlockAir) && !(block instanceof BlockFluidBase)) {
            Log.warning("Block " + block.getUnlocalizedName() + " does not extend BlockPneumaticCraft! No tooltip displayed");
        }
    }
}
 
Example #8
Source File: FluidSpringPopulator.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public IBlockState getBlockByIndex(World world, BlockPos pos, int index) {
    return fluidState.withProperty(BlockFluidBase.LEVEL, index);
}
 
Example #9
Source File: BakedModelHandler.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addFluidBlock(BlockFluidBase fluidBase) {
    this.fluidBlocks.add(fluidBase);
    ModelLoader.setCustomStateMapper(fluidBase, SIMPLE_STATE_MAPPER);
}
 
Example #10
Source File: BarrelModeFluid.java    From ExNihiloAdscensio with MIT License 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void update(TileBarrel barrel) {
	// Fluids on top.
	if (barrel.getTank().getFluid() != null) {
		FluidTank tank = barrel.getTank();
		if (tank.getFluid().amount != tank.getCapacity())
			return;

		Fluid fluidInBarrel = tank.getFluid().getFluid();

		BlockPos barrelPos = barrel.getPos();
		BlockPos pos = new BlockPos(barrelPos.getX(), barrelPos.getY() + 1, barrelPos.getZ());
		Block onTop = barrel.getWorld().getBlockState(pos).getBlock();

		Fluid fluidOnTop = null;
		if (onTop instanceof BlockLiquid) {
			fluidOnTop = onTop.getMaterial(barrel.getWorld().getBlockState(pos)) == Material.WATER
					? FluidRegistry.WATER : FluidRegistry.LAVA;
		}

		if (onTop != null && onTop instanceof IFluidBlock) {
			fluidOnTop = ((BlockFluidBase) onTop).getFluid();
		}

		if (FluidOnTopRegistry.isValidRecipe(fluidInBarrel, fluidOnTop)) {
			ItemInfo info = FluidOnTopRegistry.getTransformedBlock(fluidInBarrel, fluidOnTop);
			tank.drain(tank.getCapacity(), true);
			barrel.setMode("block");
			PacketHandler.sendToAllAround(new MessageBarrelModeUpdate("block", barrel.getPos()), barrel);

			barrel.getMode().addItem(info.getItemStack(), barrel);

			return;
		}

		// Fluid transforming time!
		if (FluidTransformRegistry.containsKey(barrel.getTank().getFluid().getFluid().getName())) {
			List<FluidTransformer> transformers = FluidTransformRegistry
					.getFluidTransformers(barrel.getTank().getFluid().getFluid().getName());

			boolean found = false;
			for (int radius = 0; radius <= 2; radius++) {
				for (FluidTransformer transformer : transformers) {
					if (!BarrelLiquidBlacklistRegistry.isBlacklisted(barrel.getTier(), transformer.getOutputFluid())
							&& (Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
									barrel.getPos().add(0, -1, 0), barrel.getWorld(), radius)
									|| Util.isSurroundingBlocksAtLeastOneOf(transformer.getTransformingBlocks(),
											barrel.getPos(), barrel.getWorld(), radius))) {
						// Time to start the process.
						FluidStack fstack = tank.getFluid();
						tank.setFluid(null);

						barrel.setMode("fluidTransform");
						BarrelModeFluidTransform mode = (BarrelModeFluidTransform) barrel.getMode();

						mode.setTransformer(transformer);
						mode.setInputStack(fstack);
						mode.setOutputStack(FluidRegistry.getFluidStack(transformer.getOutputFluid(), 1000));

						PacketHandler.sendNBTUpdate(barrel);
						found = true;
					}
				}
				if (found) break;
			}
		}
	}
}
 
Example #11
Source File: OilGeneratorFix.java    From NewHorizonsCoreMod with GNU General Public License v3.0 4 votes vote down vote up
private int getTopBlock( World pWorld, int pLocX, int pLocZ )
{
  Chunk tChunk = pWorld.getChunkFromBlockCoords( pLocX, pLocZ );
  int y = tChunk.getTopFilledSegment() + 15;

  int trimmedX = pLocX & 0xF;
  int trimmedZ = pLocZ & 0xF;
  for( ; y > 0; y-- )
  {
    Block tBlock = tChunk.getBlock( trimmedX, y, trimmedZ );

    if( !tBlock.isAir( pWorld, pLocX, y, pLocZ ) )
    {

      if(tBlock instanceof BlockStaticLiquid)
      {
        return y;
      }

      if(tBlock instanceof BlockFluidBase)
      {
        return y;
      }

      if(tBlock instanceof IFluidBlock)
      {
        return y;
      }

      if( tBlock.getMaterial().blocksMovement() )
      {

        if( !( tBlock instanceof BlockFlower ) )
        {

          return y - 1;
        }
      }
    }
  }
  return -1;
}