net.minecraftforge.fluids.IFluidBlock Java Examples

The following examples show how to use net.minecraftforge.fluids.IFluidBlock. 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: SurfaceRockPopulator.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<Material> findUndergroundMaterials(Collection<IBlockState> generatedBlocks) {
    HashSet<Material> result = new HashSet<>();
    for (IBlockState blockState : generatedBlocks) {
        Material resultMaterial;
        if (blockState.getBlock() instanceof IFluidBlock || blockState.getBlock() instanceof BlockLiquid) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(blockState.getBlock());
            resultMaterial = fluid == null ? null : MetaFluids.getMaterialFromFluid(fluid);
        } else {
            ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().damageDropped(blockState));
            UnificationEntry entry = OreDictUnifier.getUnificationEntry(itemStack);
            resultMaterial = entry == null ? null : entry.material;
        }
        if (resultMaterial != null) {
            result.add(resultMaterial);
        }
    }
    return result;
}
 
Example #2
Source File: MetaTileEntityPump.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void tryPumpFirstBlock() {
    BlockPos fluidBlockPos = fluidSourceBlocks.poll();
    if (fluidBlockPos == null) return;
    IBlockState blockHere = getWorld().getBlockState(fluidBlockPos);
    if (blockHere.getBlock() instanceof BlockLiquid ||
        blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), fluidBlockPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && exportFluids.fill(drainStack, false) == drainStack.amount) {
            exportFluids.fill(drainStack, true);
            fluidHandler.drain(drainStack.amount, true);
            this.fluidSourceBlocks.remove(fluidBlockPos);
            energyContainer.changeEnergy(-GTValues.V[getTier()]);
        }
    }
}
 
Example #3
Source File: MetaTileEntityPump.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
    IBlockState blockHere = getWorld().getBlockState(checkPos);
    boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);

    if (blockHere.getBlock() instanceof BlockLiquid ||
        blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && drainStack.amount > 0) {
            this.fluidSourceBlocks.add(checkPos);
        }
        shouldCheckNeighbours = true;
    }

    if (shouldCheckNeighbours) {
        int maxPumpRange = getMaxPumpRange();
        for (EnumFacing facing : EnumFacing.VALUES) {
            BlockPos offsetPos = checkPos.offset(facing);
            if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
                continue; //do not add blocks outside bounds
            if (!fluidSourceBlocks.contains(offsetPos) &&
                !blocksToCheck.contains(offsetPos)) {
                this.blocksToCheck.add(offsetPos);
            }
        }
    }
}
 
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: TileEntityReactorFuelRod.java    From BigReactors with MIT License 5 votes vote down vote up
private float getConductivityFromBlock(Block block, int metadata) {
	ReactorInteriorData interiorData = null;
	
	if(block == Blocks.iron_block) {
		interiorData = ReactorInterior.getBlockData("blockIron");
	}
	else if(block == Blocks.gold_block) {
		interiorData = ReactorInterior.getBlockData("blockGold");
	}
	else if(block == Blocks.diamond_block) {
		interiorData = ReactorInterior.getBlockData("blockDiamond");
	}
	else if(block == Blocks.emerald_block) {
		interiorData = ReactorInterior.getBlockData("blockEmerald");
	}
	else {
		interiorData = ReactorInterior.getBlockData(ItemHelper.oreProxy.getOreName(new ItemStack(block, 1, metadata)));

		if(interiorData == null && block instanceof IFluidBlock) {
			Fluid fluid = ((IFluidBlock)block).getFluid();
			if(fluid != null) {
				interiorData = ReactorInterior.getFluidData(fluid.getName());
			}
		}
	}
	
	if(interiorData == null) {
		interiorData = RadiationHelper.airData;
	}
	
	return interiorData.heatConductivity;
}
 
Example #6
Source File: BlockFluidMana.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #7
Source File: BlockFluidLethe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: RadiationHelper.java    From BigReactors with MIT License 5 votes vote down vote up
private void performIrradiation(World world, RadiationData data, RadiationPacket radiation, int x, int y, int z) {
	TileEntity te = world.getTileEntity(x, y, z);
	if(te instanceof IRadiationModerator) {
		((IRadiationModerator)te).moderateRadiation(data, radiation);
	}
	else if (world.isAirBlock(x, y, z)) {
		moderateByAir(data, radiation);
	}
	else {
		Block block = world.getBlock(x, y, z);
		if(block != null) {
			
			if(block instanceof IFluidBlock) {
				moderateByFluid(data, radiation, ((IFluidBlock)block).getFluid());
			}
			else {
				// Go by block
				moderateByBlock(data, radiation, block, world.getBlockMetadata(x, y, z));
			}
		}
		else {
			// Weird-ass problem. Assume it's air.
			moderateByAir(data, radiation);
		}
		// Do it based on fluid?
	}
}
 
Example #9
Source File: Entity.java    From TickDynamic with MIT License 5 votes vote down vote up
/**
 * Checks if the current block the entity is within of the specified material type
 */
public boolean isInsideOfMaterial(Material p_70055_1_)
{
    double d0 = this.posY + (double)this.getEyeHeight();
    int i = MathHelper.floor_double(this.posX);
    int j = MathHelper.floor_float((float)MathHelper.floor_double(d0));
    int k = MathHelper.floor_double(this.posZ);
    Block block = this.worldObj.getBlock(i, j, k);

    if (block.getMaterial() == p_70055_1_)
    {
        double filled = 1.0f; //If it's not a liquid assume it's a solid block
        if (block instanceof IFluidBlock)
        {
            filled = ((IFluidBlock)block).getFilledPercentage(worldObj, i, j, k);
        }

        if (filled < 0)
        {
            filled *= -1;
            //filled -= 0.11111111F; //Why this is needed.. not sure...
            return d0 > (double)(j + (1 - filled));
        }
        else
        {
            return d0 < (double)(j + filled);
        }
    }
    else
    {
        return false;
    }
}
 
Example #10
Source File: ItemSealDetector.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player,
		World world, BlockPos pos, EnumHand hand, EnumFacing facing,
		float hitX, float hitY, float hitZ) {
       if (!world.isRemote)
       {
           if (SealableBlockHandler.INSTANCE.isBlockSealed(world, pos))
           {
               player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.sealed")));
           }
           else
           {
           	IBlockState state = world.getBlockState(pos);
               Material mat = state.getMaterial();
               if (SealableBlockHandler.INSTANCE.isMaterialBanned(mat))
               {
                   player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.notsealmat")));
               }
               else if (SealableBlockHandler.INSTANCE.isBlockBanned(state.getBlock()))
               {
                   player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.notsealblock")));
               }
               else if (SealableBlockHandler.isFulBlock(world, pos))
               {
                   player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.notfullblock")));
               }
               else if (state.getBlock() instanceof IFluidBlock)
               {
                   player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.fluid")));
               }
               else
               {
                   player.sendMessage(new TextComponentString(LibVulpes.proxy.getLocalizedString("msg.sealdetector.other")));
               }
           }
       }
       return EnumActionResult.SUCCESS;
}
 
Example #11
Source File: Utils.java    From NEI-Integration with MIT License 5 votes vote down vote up
public static boolean isFluidBlock(ItemStack stack) {
    if (stack == null || stack.getItem() == null) {
        return false;
    }
    
    Block block = Block.getBlockFromItem(stack.getItem());
    if (block == null) {
        return false;
    }
    
    return block instanceof IFluidBlock || block == Blocks.water || block == Blocks.flowing_water || block == Blocks.lava || block == Blocks.flowing_lava;
}
 
Example #12
Source File: TileEntityTransitionPlaneFluid.java    From ExtraCells1 with MIT License 4 votes vote down vote up
public void doWork()
{
	if (isMachineActive() && getGrid() != null)
	{
		ForgeDirection orientation = ForgeDirection.getOrientation(getBlockMetadata());

		int offsetID = worldObj.getBlockId(xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ);
		int offsetMeta = worldObj.getBlockMetadata(xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ);

		IMEInventoryHandler cellArray = getGrid().getCellArray();
		if (cellArray != null)
		{
			try
			{
				if (Block.blocksList[offsetID] instanceof IFluidBlock)
				{
					FluidStack simulation = ((IFluidBlock) Block.blocksList[offsetID]).drain(worldObj, xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ, false);

					if (simulation != null && cellArray.calculateItemAddition(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), simulation.amount, simulation.fluidID))) == null)
					{
						((IFluidBlock) Block.blocksList[offsetID]).drain(worldObj, xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ, true);
						cellArray.addItems(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), simulation.amount, simulation.fluidID)));
					}
				} else if (offsetID == FluidRegistry.WATER.getBlockID() && offsetMeta == 0)
				{
					if (cellArray.calculateItemAddition(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), 1000, FluidRegistry.WATER.getID()))) == null)
					{
						worldObj.setBlockToAir(xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ);
						cellArray.addItems(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), 1000, FluidRegistry.WATER.getID())));
					}
				} else if (offsetID == FluidRegistry.LAVA.getBlockID() && offsetMeta == 0)
				{
					if (cellArray.calculateItemAddition(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), 1000, FluidRegistry.LAVA.getID()))) == null)
					{
						worldObj.setBlockToAir(xCoord + orientation.offsetX, yCoord + orientation.offsetY, zCoord + orientation.offsetZ);
						cellArray.addItems(Util.createItemStack(new ItemStack(ItemEnum.FLUIDDISPLAY.getItemInstance(), 1000, FluidRegistry.LAVA.getID())));
					}
				}
			} catch (Throwable wontHappen)
			{
				// Nothing
			}
		}
	}
}
 
Example #13
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isBlockLiquid(Block block){
    return block instanceof BlockLiquid || block instanceof IFluidBlock;
}
 
Example #14
Source File: SealableBlockHandler.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
/**
 * Checks to see if the block at the location can be sealed
 * @param world
 * @param pos
 * @return
 */
@Override
public boolean isBlockSealed(World world, BlockPos pos)
{
	//Ensure we are not checking outside of the map
	if(pos.getY() >= 0 && pos.getY() <= 256)
	{
		//Prevents orphan chunk loading - DarkGuardsman
		//ChunkExists
		if(world instanceof WorldServer && !((WorldServer) world).getChunkProvider().chunkExists(pos.getX() >> 4, pos.getZ() >> 4))
		{
			return false;
		}

		IBlockState state = world.getBlockState(pos);
		Block block = state.getBlock();
		Material material = state.getMaterial();

		//Always allow list
		if (blockAllowList.contains(block) || materialAllowList.contains(material))
		{
			return true;
		}
		//Always block list
		else if (blockBanList.contains(block) || materialBanList.contains(material))
		{
			return false;
		}
		else if (material.isLiquid() || !material.isSolid())
		{
			return false;
		}
		else if (world.isAirBlock(pos) || block instanceof IFluidBlock)
		{
			return false;
		}
		//TODO replace with seal logic handler
		else if (block == AdvancedRocketryBlocks.blockAirLock)
		{
			HashedBlockPosition myPos = new HashedBlockPosition(pos);
			if(doorPositions.contains(myPos))
				return true;
			doorPositions.add(myPos);
			
			boolean doorIsSealed = checkDoorIsSealed(world, pos, state);
			doorPositions.remove(myPos);
			return doorIsSealed;
		}
		//TODO add is side solid check, which will require forge direction or side check. Eg more complex logic...
		return isFulBlock(world, pos);
	}
	return false;
}
 
Example #15
Source File: ClientProxy.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void preInitBlocks()
{
	//Register Block models
	Item blockItem = Item.getItemFromBlock(AdvancedRocketryBlocks.blockLoader);
	ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation("advancedrocketry:databus", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 1, new ModelResourceLocation("advancedrocketry:satelliteHatch", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 2, new ModelResourceLocation("libvulpes:inputHatch", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 3, new ModelResourceLocation("libvulpes:outputHatch", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 4, new ModelResourceLocation("libvulpes:fluidInputHatch", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 5, new ModelResourceLocation("libvulpes:fluidOutputHatch", "inventory"));
	ModelLoader.setCustomModelResourceLocation(blockItem, 6, new ModelResourceLocation("advancedrocketry:guidancecomputeraccesshatch", "inventory"));

	blockItem = Item.getItemFromBlock(AdvancedRocketryBlocks.blockCrystal);
	for(int i = 0; i < BlockCrystal.numMetas; i++)
		ModelLoader.setCustomModelResourceLocation(blockItem, i, new ModelResourceLocation("advancedrocketry:crystal", "inventory"));


	blockItem = Item.getItemFromBlock(AdvancedRocketryBlocks.blockAirLock);

	blockItem = Item.getItemFromBlock(AdvancedRocketryBlocks.blockLaunchpad);
	ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation("advancedrocketry:launchpad_all", "inventory"));

	blockItem = Item.getItemFromBlock(AdvancedRocketryBlocks.blockPlatePress);
	ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation("advancedrocketry:platePress", "inventory"));
	
	//TODO fluids
	registerFluidModel((IFluidBlock) AdvancedRocketryBlocks.blockOxygenFluid);
	registerFluidModel((IFluidBlock) AdvancedRocketryBlocks.blockNitrogenFluid);
	registerFluidModel((IFluidBlock) AdvancedRocketryBlocks.blockHydrogenFluid);
	registerFluidModel((IFluidBlock) AdvancedRocketryBlocks.blockFuelFluid);
	/*ModelLoader.setCustomMeshDefinition(Item, new ItemMeshDefinition() {

	@Override
	public ModelResourceLocation getModelLocation(ItemStack stack) {
		return new ModelResourceLocation("advancedRocketry:fluid", "rocketFuel");
	}
});*/


	/*Item item = Item.getItemFromBlock((Block) AdvancedRocketryBlocks.blockFuelFluid);
ModelBakery.registerItemVariants(item, );
ModelResourceLocation modeEgylResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, fluidBlock.getFluid().getName());
ModelLoader.setCustomMeshDefinition(AdvancedRocketryItems.itemBucketRocketFuel, new ItemMeshDefinition() {
	@Override
	public ModelResourceLocation getModelLocation(ItemStack stack) {
		FluidStack fluidStack = AdvancedRocketryItems.itemBucketRocketFuel.getFluid(stack);
		return fluidStack != null ? new ModelResourceLocation("advancedrocketry:bucket/" + fluidStack.getFluid().getName(), "inventory") : null;
	}
});
//Register Fluid Block
ModelLoader.setCustomStateMapper(AdvancedRocketryBlocks.blockFuelFluid, new StateMapperBase() {

	@Override
	protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
		return new ModelResourceLocation("advancedrocketry:fluid");
	}
});*/
}
 
Example #16
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;
}
 
Example #17
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 #18
Source File: CapeHandler.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean isFluid(IBlockState state) {
	return state.getBlock() instanceof IFluidBlock || state.getBlock() instanceof BlockLiquid;
}
 
Example #19
Source File: MetaTileEntityPump.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void updateQueueState(int blocksToCheckAmount) {
    BlockPos selfPos = getPos().down(pumpHeadY);

    for(int i = 0; i < blocksToCheckAmount; i++) {
        BlockPos checkPos = null;
        int amountIterated = 0;
        do {
            if (checkPos != null) {
                blocksToCheck.push(checkPos);
                amountIterated++;
            }
            checkPos = blocksToCheck.poll();

        } while (checkPos != null &&
            !getWorld().isBlockLoaded(checkPos) &&
            amountIterated < blocksToCheck.size());
        if (checkPos != null) {
            checkFluidBlockAt(selfPos, checkPos);
        } else break;
    }

    if (fluidSourceBlocks.isEmpty()) {
        if (getTimer() % 20 == 0) {
            BlockPos downPos = selfPos.down(1);
            if (downPos != null && downPos.getY() >= 0) {
                IBlockState downBlock = getWorld().getBlockState(downPos);
                if (downBlock.getBlock() instanceof BlockLiquid ||
                    downBlock.getBlock() instanceof IFluidBlock ||
                    !downBlock.isTopSolid()) {
                    this.pumpHeadY++;
                }
            }

            // Always recheck next time
            writeCustomData(200, b -> b.writeVarInt(pumpHeadY));
            markDirty();
            //schedule queue rebuild because we changed our position and no fluid is available
            this.initializedQueue = false;
        }

        if (!initializedQueue || getTimer() % 6000 == 0) {
            this.initializedQueue = true;
            //just add ourselves to check list and see how this will go
            this.blocksToCheck.add(selfPos);
        }
    }
}
 
Example #20
Source File: ClientProxy.java    From AdvancedRocketry with MIT License 3 votes vote down vote up
private void registerFluidModel(IFluidBlock fluidBlock) {
	Item item = Item.getItemFromBlock((Block) fluidBlock);

	ModelBakery.registerItemVariants(item);

	final ModelResourceLocation modelResourceLocation = new ModelResourceLocation("advancedrocketry:fluid", fluidBlock.getFluid().getName());
	
	//ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation));

	
	StateMapperBase ignoreState = new FluidStateMapper(modelResourceLocation);
	ModelLoader.setCustomStateMapper((Block) fluidBlock, ignoreState);
	ModelLoader.setCustomMeshDefinition(item, new FluidItemMeshDefinition(modelResourceLocation));
	ModelBakery.registerItemVariants(item, modelResourceLocation);
}