@SubscribeEvent public void onFillBucket(FillBucketEvent event) { RayTraceResult rtr = event.getTarget(); if (rtr != null) { Block b = event.getWorld().getBlockState(rtr.getBlockPos()).getBlock(); if (b instanceof IFluidBlock) { Fluid fluid = ((IFluidBlock) b).getFluid(); ItemStack filled = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)); if (!filled.isEmpty()) { event.setFilledBucket(FluidUtil.getFilledBucket(new FluidStack(fluid, 1000))); event.getWorld().setBlockToAir(rtr.getBlockPos()); event.setResult(Result.ALLOW); if (TileEntityRefinery.isInputFluidValid(fluid, 4) && event.getEntityPlayer() instanceof EntityPlayerMP) { AdvancementTriggers.OIL_BUCKET.trigger((EntityPlayerMP) event.getEntityPlayer()); } } } } }
private static <T extends Block & IFluidBlock> Fluid createFluid(String name, boolean hasFlowIcon, Consumer<Fluid> fluidPropertyApplier, Function<Fluid, T> blockFactory, boolean hasBucket) { final ResourceLocation still = new ResourceLocation(LibMod.MOD_ID + ":blocks/fluid/" + name + "_still"); final ResourceLocation flowing = hasFlowIcon ? new ResourceLocation(LibMod.MOD_ID + ":blocks/fluid/" + name + "_flow") : still; Fluid fluid = new Fluid(name, still, flowing); final boolean useOwnFluid = FluidRegistry.registerFluid(fluid); if (useOwnFluid) { fluidPropertyApplier.accept(fluid); MOD_FLUID_BLOCKS.add(blockFactory.apply(fluid)); if (hasBucket) FluidRegistry.addBucketForFluid(fluid); } else { fluid = FluidRegistry.getFluid(name); } return fluid; }
private boolean tryBlockClient(int x, int y, int z) { BlockVec3 bv = new BlockVec3(x, y, z); if (this.laserBlocks.contains(bv)) return false; //Add minable blocks to the laser fx list Block b = this.worldObj.getBlock(x, y, z); if (b.getMaterial() == Material.air) return false; if (noMineList.contains(b)) return true; if (b instanceof BlockLiquid) return false; if (b instanceof IFluidBlock) return false; if (b instanceof IPlantable) return true; int meta = this.worldObj.getBlockMetadata(x, y, z); if (b.hasTileEntity(meta) || b.getBlockHardness(this.worldObj, x, y, z) < 0) return true; if (this.tryBlockLimit == 0) return false; this.tryBlockLimit--; this.laserBlocks.add(bv); this.laserTimes.add(this.ticksExisted); return false; }
public static boolean isInsideOfFluid(Entity entity, Fluid fluid) { double d0 = entity.posY + entity.getEyeHeight(); int i = MathHelper.floor_double(entity.posX); int j = MathHelper.floor_float(MathHelper.floor_double(d0)); int k = MathHelper.floor_double(entity.posZ); Block block = entity.worldObj.getBlock(i, j, k); if (block != null && block instanceof IFluidBlock && ((IFluidBlock) block).getFluid() != null && ((IFluidBlock) block).getFluid().getName().equals(fluid.getName())) { double filled = ((IFluidBlock) block).getFilledPercentage(entity.worldObj, i, j, k); if (filled < 0) { filled *= -1; return d0 > j + (1 - filled); } else { return d0 < j + filled; } } else { return false; } }
@SubscribeEvent public void waterOverlay(RenderBlockOverlayEvent event){ if(event.getOverlayType() == OverlayType.WATER){ EntityPlayer player = event.getPlayer(); IBlockState state = player.getEntityWorld().getBlockState(event.getBlockPos()); if(state.getBlock() instanceof IFluidBlock){ Fluid fluid = ((IFluidBlock)state.getBlock()).getFluid(); if(fluid !=null){ ResourceLocation res = ModFluids.getOverlayTexture(fluid); if(res !=null){ event.setCanceled(true); renderWaterOverlayTexture(event.getRenderPartialTicks(), res); } } } } }
public static FluidStack getFluidTypeFromItem(ItemStack stack) { if (ItemStackTools.isNullStack(stack)) { return null; } stack = stack.copy(); ItemStackTools.setStackSize(stack, 1); IFluidHandler handler = getFluidHandlerCapability(stack); if (handler != null) { return handler.drain(Fluid.BUCKET_VOLUME, false); } if (Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock) { Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid(); if (fluid != null) { return new FluidStack(fluid, 1000); } } return null; }
/** * Create a {@link Fluid} and its {@link IFluidBlock}, or use the existing ones if a fluid has already been registered with the same name. * * @param name The name of the fluid * @param hasFlowIcon Does the fluid have a flow icon? * @param fluidPropertyApplier A function that sets the properties of the {@link Fluid} * @param blockFactory A function that creates the {@link IFluidBlock} * @return The fluid and block */ private static <T extends Block & IFluidBlock> Fluid createFluid(String name, boolean hasFlowIcon, Consumer<Fluid> fluidPropertyApplier, Function<Fluid, T> blockFactory) { final String texturePrefix = Constants.RESOURCE_PREFIX + "blocks/fluids/"; final ResourceLocation still = new ResourceLocation(texturePrefix + name + "_still"); final ResourceLocation flowing = hasFlowIcon ? new ResourceLocation(texturePrefix + name + "_flow") : still; Fluid fluid = new Fluid(name, still, flowing); final boolean useOwnFluid = FluidRegistry.registerFluid(fluid); if (useOwnFluid) { fluidPropertyApplier.accept(fluid); registerFluidBlock(blockFactory.apply(fluid)); } else { fluid = FluidRegistry.getFluid(name); } FLUIDS.add(fluid); return fluid; }
private static <T extends Block & IFluidBlock> Fluid createFluidAcid(String name, boolean hasFlowIcon, int color, Consumer<Fluid> fluidPropertyApplier, Function<Fluid, T> blockFactory) { final String texturePrefix = Constants.RESOURCE_PREFIX + "blocks/fluids/"; final ResourceLocation still = new ResourceLocation(texturePrefix + "acid_still"); final ResourceLocation flowing = hasFlowIcon ? new ResourceLocation(texturePrefix + "acid_flow") : still; FluidAcid fluid = new FluidAcid(name, color, still, flowing); final boolean useOwnFluid = FluidRegistry.registerFluid(fluid); if (useOwnFluid) { fluidPropertyApplier.accept(fluid); registerFluidBlock(blockFactory.apply(fluid)); } else { // fluid = FluidRegistry.getFluid(name); //TODO: deal with this case } FLUIDS.add(fluid); return fluid; }
private void registerFluidModel(IFluidBlock fluidBlock) { final Item item = Item.getItemFromBlock((Block) fluidBlock); assert item != null; ModelBakery.registerItemVariants(item); ModelResourceLocation modelResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, fluidBlock.getFluid().getName()); ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation)); ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState p_178132_1_) { return modelResourceLocation; } }); itemsRegistered.add(item); }
@SideOnly(Side.CLIENT) public void registerRenderer() { IFluidBlock block = BlocksRegistry.liquidXpBlock; Item item = Item.getItemFromBlock((Block)block); assert (item == Items.AIR); ModelBakery.registerItemVariants(item); ModelResourceLocation modelResourceLocation = new ModelResourceLocation(MekfarmMod.MODID + ":fluids", this.getName()); ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { @Override public ModelResourceLocation getModelLocation(ItemStack stack) { return modelResourceLocation; } }); ModelLoader.setCustomStateMapper((Block) block, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) { return modelResourceLocation; } }); }
@SideOnly(Side.CLIENT) public void registerRenderer() { IFluidBlock block = BlocksRegistry.sewageBlock; Item item = Item.getItemFromBlock((Block)block); assert (item == Items.AIR); ModelBakery.registerItemVariants(item); ModelResourceLocation modelResourceLocation = new ModelResourceLocation(MekfarmMod.MODID + ":fluids", this.getName()); ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { @Override public ModelResourceLocation getModelLocation(ItemStack stack) { return modelResourceLocation; } }); ModelLoader.setCustomStateMapper((Block) block, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) { return modelResourceLocation; } }); }
/** * Create a {@link Fluid} and its {@link IFluidBlock}, or use the existing ones if a fluid has already been registered with the same name. * * @param name The name of the fluid * @param hasFlowIcon Does the fluid have a flow icon? * @param fluidPropertyApplier A function that sets the properties of the {@link Fluid} * @param blockFactory A function that creates the {@link IFluidBlock} * @return The fluid and block */ private static <T extends Block & IFluidBlock> Fluid createFluid(final String name, final boolean hasFlowIcon, final Consumer<Fluid> fluidPropertyApplier, final Function<Fluid, T> blockFactory) { final String texturePrefix = GlobalNames.Domain + ":" + "blocks/fluid_"; final ResourceLocation still = new ResourceLocation(texturePrefix + name + "_still"); final ResourceLocation flowing = hasFlowIcon ? new ResourceLocation(texturePrefix + name + "_flow") : still; Fluid fluid = new Fluid(name, still, flowing); final boolean useOwnFluid = FluidRegistry.registerFluid(fluid); if (useOwnFluid) { fluidPropertyApplier.accept(fluid); MOD_FLUID_BLOCKS.add(blockFactory.apply(fluid)); } else { fluid = FluidRegistry.getFluid(name); } FLUIDS.add(fluid); return fluid; }
/** * Register this mod's fluid {@link ItemBlock}s. * * @param event The event */ // Use EventPriority.LOWEST so this is called after the RegistryEvent.Register<Item> handler in ModBlocks where // the ItemBlock for ModBlocks.FLUID_TANK is registered. @SubscribeEvent(priority = EventPriority.LOWEST) public static void registerItems(final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); for (final IFluidBlock fluidBlock : MOD_FLUID_BLOCKS) { final Block block = (Block) fluidBlock; final ItemBlock itemBlock = new ItemBlock(block); final ResourceLocation registryName = Preconditions.checkNotNull(block.getRegistryName()); itemBlock.setRegistryName(registryName); registry.register(itemBlock); } registerFluidContainers(); }
private void registerFluidModel(final IFluidBlock fluidBlock) { final Item item = Item.getItemFromBlock((Block) fluidBlock); assert item != Items.AIR; ModelBakery.registerItemVariants(item); final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(FLUID_MODEL_PATH, fluidBlock.getFluid().getName()); ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation)); ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(final IBlockState p_178132_1_) { return modelResourceLocation; } }); }
public static FluidStack getFluidFromItem(ItemStack stack) { if (stack != null) { FluidStack fluidStack = null; if (stack.getItem() instanceof IFluidContainerItem) { fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack); } if (fluidStack == null) { fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack); } if (fluidStack == null && Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock) { Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid(); if (fluid != null) { return new FluidStack(fluid, 1000); } } return fluidStack; } return null; }
public static float guessBlockMass(World world, Block block, int meta, int x, int y, int z) { if(block instanceof IFluidBlock) { return getMassForFluid(((IFluidBlock)block).getFluid()); } if(block instanceof BlockLiquid) { // vanilla MC fluids if(block == Blocks.lava) { return getMassForFluid(FluidRegistry.LAVA); } return getMassForFluid(FluidRegistry.WATER); } // extra stuff if(block == Blocks.snow_layer) { return (meta+1) * 0.025F; //return 0.01F; // meta 0 => one, 1 => two, 2=>3, 3=>4, 4=>5, 5=>6, 7 => 8 => full } if(block == Blocks.vine) { return 0.01F; } return getMassFromHardnessAndMaterial(block.getBlockHardness(world, x, y, z), block.getMaterial()); }
/** * Create a {@link Fluid} and its {@link IFluidBlock}, or use the existing ones if a fluid has already been registered with the same name. * * @param name The name of the fluid * @param hasFlowIcon Does the fluid have a flow icon? * @param fluidPropertyApplier A function that sets the properties of the {@link Fluid} * @param blockFactory A function that creates the {@link IFluidBlock} * @return The fluid and block */ private static <T extends Block & IFluidBlock> Fluid createFluid(String name, boolean hasFlowIcon, Consumer<Fluid> fluidPropertyApplier, Function<Fluid, T> blockFactory) { final String texturePrefix = Reference.MOD_ID + ":blocks/fluid_"; final ResourceLocation still = new ResourceLocation(texturePrefix + name + "_still"); final ResourceLocation flowing = hasFlowIcon ? new ResourceLocation(texturePrefix + name + "_flow") : still; Fluid fluid = new Fluid(name, still, flowing); final boolean useOwnFluid = FluidRegistry.registerFluid(fluid); if (useOwnFluid) { fluidPropertyApplier.accept(fluid); MOD_FLUID_BLOCKS.add(blockFactory.apply(fluid)); } else { fluid = FluidRegistry.getFluid(name); } FLUIDS.add(fluid); return fluid; }
private static void registerFluidModel(IFluidBlock fluidBlock) { final Item item = Item.getItemFromBlock((Block) fluidBlock); assert item != null; ModelBakery.registerItemVariants(item); final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(Reference.MOD_ID + ":fluid", fluidBlock.getFluid().getName()); ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> modelResourceLocation)); ModelLoader.setCustomStateMapper((Block) fluidBlock, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState p_178132_1_) { return modelResourceLocation; } }); }
/** * Whether or not a block is a dead fluid. * @param world - world the block is in * @param x - x coordinate * @param y - y coordinate * @param z - z coordinate * @return if the block is a dead fluid */ public static boolean isDeadFluid(World world, int x, int y, int z) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); if(block == null || meta == 0) { return false; } if((block == Blocks.water || block == Blocks.flowing_water)) { return true; } else if((block == Blocks.lava || block == Blocks.flowing_lava)) { return true; } else if(block instanceof IFluidBlock) { return true; } return false; }
@Override public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { if(!world.isRemote) { Block b = world.getBlock(x, y+1, z); if(TFC_Core.isSoilOrGravel(b) || b instanceof BlockCobble || b instanceof BlockSand) { TFC_Core.setBlockToAirWithDrops(world, x, y, z); } if(world.isAirBlock(x, y-1, z) || world.getBlock(x, y-1, z) instanceof IFluidBlock || world.getBlock(x, y+1, z) instanceof IFluidBlock || world.getBlock(x-1, y, z) instanceof IFluidBlock || world.getBlock(x+1, y, z) instanceof IFluidBlock || world.getBlock(x, y, z-1) instanceof IFluidBlock || world.getBlock(x, y, z+1) instanceof IFluidBlock) { TFC_Core.setBlockToAirWithDrops(world, x, y, z); } } }
public static FluidStack getFluidFromWorld(World worldObj, int x, int y, int z) { int bId = worldObj.getBlockId(x, y, z); int bMeta = worldObj.getBlockMetadata(x, y, z); if (bId == 9 || bId == 8) { if (bMeta == 0) { return WATER.copy(); } else { return null; } } else if (bId == 10 || bId == 11) { if (bMeta == 0) { return LAVA.copy(); } else { return null; } } else if (Block.blocksList[bId] != null && Block.blocksList[bId] instanceof IFluidBlock) { IFluidBlock block = (IFluidBlock) Block.blocksList[bId]; return block.drain(worldObj, x, y, z, true); } return null; }
public static void registerFluidContainers(Class<? extends Catalog> catalogClass) { Field[] fields = catalogClass.getFields(); for (Field field : fields) { try { Object value = field.get(null); if (value instanceof IFluidBlock) { IFluidBlock block = (IFluidBlock)value; if (!block.getFluid().isGaseous()) { registerBucket(block); registerFlask(block.getFluid()); } } } catch (Exception e) { throw new LoaderException(e); } } }
public static ItemStack phaseBucket(Block block) { if(block instanceof BlockLiquid || block instanceof IFluidBlock) { Fluid fluid = block instanceof BlockLiquid ? FluidRegistry.lookupFluidForBlock(block) : ((IFluidBlock)block).getFluid(); if(fluid == null) return new ItemStack(block); ItemStack stack = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)); return stack.isEmpty() ? new ItemStack(block) : stack; } return new ItemStack(block); }
public static boolean isInsideOfMaterial(Material material, Entity entity, BlockPos pos) { IBlockState state = entity.worldObj.getBlockState(pos); Block block = state.getBlock(); double eyes = entity.posY + (double)entity.getEyeHeight(); double filled = 1.0f; //If it's not a liquid assume it's a solid block if (block instanceof IFluidBlock) { filled = ((IFluidBlock)block).getFilledPercentage(entity.worldObj, pos); } else if (block instanceof BlockLiquid) { filled = BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state)); } if (filled < 0) { filled *= -1; //filled -= 0.11111111F; //Why this is needed.. not sure... return eyes > pos.getY() + 1 + (1 - filled); } else { return eyes < pos.getY() + 1 + filled; } }
private boolean isOilBlock(EntityPlayer player, World world, int x, int y, int z, boolean doDrain) { Block block = world.getBlock(x, y, z); if (block instanceof IFluidBlock) { IFluidBlock fluidBlockHit = (IFluidBlock) block; boolean flag = false; if (block == GCBlocks.crudeOil) { flag = true; } else { Fluid fluidHit = FluidRegistry.lookupFluidForBlock(block); if (fluidHit != null) { if (fluidHit.getName().startsWith("oil")) { flag = true; } } } if (flag) { FluidStack stack = fluidBlockHit.drain(world, x, y, z, doDrain); return stack != null && stack.amount > 0; } } return false; }
public static boolean isFluidBlock(World world, BlockPos pos, IBlockState iblockstate) { Block block = iblockstate.getBlock(); if(block instanceof IFluidBlock){ return true; } if(block instanceof BlockLiquid){ return true; } return false; }
public static boolean isFluidSource(World world, BlockPos pos, IBlockState iblockstate) { Block block = iblockstate.getBlock(); if(block instanceof IFluidBlock){ return ((IFluidBlock)block).getFilledPercentage(world, pos) == 1.0f; } if(block instanceof BlockLiquid){ return iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0; } return false; }
private static <T extends Block & IFluidBlock> T registerFluidBlock(T block) { block.setRegistryName("fluid." + block.getFluid().getName()); block.setUnlocalizedName(Constants.RESOURCE_PREFIX + block.getFluid().getUnlocalizedName()); block.setCreativeTab(AquaRegia.creativeTab); ModBlocks.registerBlock(block); MOD_FLUID_BLOCKS.add(block); return block; }
private void pump() { if (!fluidBlocks.isEmpty()) { if (tank.getFluid() == null) { BlockPos pos = fluidBlocks.pop(); if (pos == null) return; IBlockState stateB = world.getBlockState(pos); if (stateB.getBlock() instanceof IFluidBlock || stateB.getBlock() instanceof BlockLiquid) { IFluidHandler h = FluidUtil.getFluidHandler(world, pos, EnumFacing.UP); if (h != null) { FluidStack drained = h.drain(1000, false); int temp = drained.getFluid().getTemperature(world, pos); if (drained != null && drained.amount > 0) { if (tank.fillInternal(drained, false) == 1000) { tank.fillInternal(h.drain(1000, true), true); energy.extractEnergy(1, false); cooldown = 120; if (!clearing && !(pos.getX() == this.pos.getX() && pos.getZ() == this.pos.getZ())) world.setBlockState(pos, temp > 300 ? Blocks.STONE.getDefaultState() : Blocks.DIRT.getDefaultState()); } else { cooldown = 100; } } else { cooldown = 50; } } else { cooldown = 50; } } else { cooldown = 50; } } else { cooldown = 200; } } else { cooldown = 200; } }
private boolean place(World world, boolean isSecondTry) { if (this.isInValid) return false; IBlockState oldState = world.getBlockState(pos); if (!this.onlyEffect) { if (oldState == null) { put(world); return true; } else if (oldState.getBlock() == null) { put(world); return true; } else if (oldState.getBlock().isReplaceable(world, pos)) { put(world); return true; } else if (effect.hasSponge && !isSecondTry) { if (oldState != null && (oldState.getBlock() instanceof BlockStaticLiquid || oldState.getBlock() instanceof IFluidBlock)) { world.setBlockToAir(pos); } return this.place(world, true); } else if (effect.hasBlockBreakingUpgrade && !isSecondTry && oldState.getBlock() != DefenseInit.blockForce) { TomsModUtils.breakBlockWithDrops(world, pos); return this.place(world, true); } else return false; } else if (effect.hasSponge) { if (oldState != null && (oldState.getBlock() instanceof BlockLiquid || oldState.getBlock() instanceof IFluidBlock)) { world.setBlockToAir(pos); } return true; } else if (effect.hasBlockBreakingUpgrade && oldState.getBlock() != DefenseInit.blockForce) { TomsModUtils.breakBlockWithDrops(world, pos); return true; } else return false; }
/** * Register this mod's fluid {@link Block}s. * * @param event The event */ @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { final IForgeRegistry<Block> registry = event.getRegistry(); for (final IFluidBlock fluidBlock : MOD_FLUID_BLOCKS) { final Block block = (Block) fluidBlock; block.setRegistryName(main.MODID, "fluid." + fluidBlock.getFluid().getName()); block.setUnlocalizedName(GlobalNames.Domain + fluidBlock.getFluid().getUnlocalizedName()); block.setCreativeTab(InitCreativeTabs.Fallout_stats_blocks); registry.register(block); } }
public Fluid getFluid() { Block b = getBlock(); if (b instanceof IFluidBlock) { return ((IFluidBlock) b).getFluid(); } if (b == Blocks.water || b == Blocks.flowing_water) { return FluidRegistry.WATER; } if (b == Blocks.lava || b == Blocks.flowing_lava) { return FluidRegistry.LAVA; } return null; }
private void buildWorkQueue() { needsCompletenessCheck = false; complete = true; this.currentWork = new ArrayList<>(); clearingWork = new Work[blocksToBuild.length][blocksToBuild[0].length][blocksToBuild[0][0].length]; buildingWork = new Work[blocksToBuild.length][blocksToBuild[0].length][blocksToBuild[0][0].length]; for(int x = 0; x < blocksToBuild.length; x ++) { for(int y = 0; y < blocksToBuild[x].length; y++) { for(int z = 0; z < blocksToBuild[x][y].length; z ++) { BlockPos pos = new BlockPos(x + origin.getX(), y + origin.getY(), z + origin.getZ()); IBlockState state = getWorld().getBlockState(pos); Block block = state.getBlock(); boolean base = isAllowedState(state, blocksToBuild[x][y][z]); boolean last = isAllowedState(state, finalBlocksToBuild[x][y][z]); if(state.getMaterial() == Material.AIR || block instanceof BlockLiquid || block instanceof IFluidBlock) { if(blocksToBuild[x][y][z] != null) { if(!base) { buildingWork[x][y][z] = new Work.PlaceBlock(blocksToBuild[x][y][z]); complete = false; } } else if(finalBlocksToBuild[x][y][z] != null) { if(!last) { buildingWork[x][y][z] = new Work.PlaceBlock(finalBlocksToBuild[x][y][z]); complete = false; } } } if(base || last) { continue; } if(block.getBlockHardness(state, getWorld(), pos) < 0) { //block is unbreakable continue; } clearingWork[x][y][z] = new Work.ClearBlock(pos); complete = false; } } } }
@Override public ItemStack[] harvestBlock(World world, int x, int y, int z, EntityPlayer player, IToggleController controller) { Block block = world.getBlock(x, y, z); System.out.println(block.getClass().getSimpleName()); if (block instanceof IFluidBlock) { IToggleStorage storage = controller.getStorageHandler(); IFluidBlock fluidBlock = (IFluidBlock) block; FluidStack containing = fluidBlock.drain(world, x, y, z, true); ItemStack emptyContainer = null; for (int s = 0; s < storage.getStorageSlots(); s++) { ItemStack inSlot = storage.getItemFromSlot(s); if (FluidContainerRegistry.isEmptyContainer(inSlot)) { emptyContainer = inSlot; break; } } if (emptyContainer == null) return null; ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(containing, emptyContainer); emptyContainer.stackSize--; return new ItemStack[]{filledContainer}; } else if (block instanceof BlockStaticLiquid) { ItemStack emptyBucket = controller.getStorageHandler().getItemFromStorage(new ItemStack(Items.bucket)); if (emptyBucket != null) { emptyBucket.stackSize--; ItemStack filledBucket = null; if (block == Blocks.water) filledBucket = new ItemStack(Items.water_bucket); else if (block == Blocks.lava) filledBucket = new ItemStack(Items.lava_bucket); world.setBlockToAir(x, y, z); return filledBucket != null ? new ItemStack[]{filledBucket} : null; } } return null; }
@Override public boolean canHarvestBlock(World world, int x, int y, int z, IToggleController controller) { Block block = world.getBlock(x, y, z); System.out.println(block.getClass().getSimpleName()); return (block instanceof IFluidBlock && ((IFluidBlock) block).getFilledPercentage(world, x, y, z) > 0) || block instanceof BlockStaticLiquid; // Block block = world.getBlock(x, y, z); // return block != null && (block == Blocks.water || block == Blocks.lava); /*Block block = world.getBlock(x, y, z); if (block == null) return false; Fluid fromBlock = FluidRegistry.lookupFluidForBlock(block); if (fromBlock == null) return false; if (!FluidRegistry.isFluidRegistered(fromBlock)) return false; ItemStack[] storage = controller.getAllStorage(); ItemStack fluidContainer = null; for (ItemStack stack : storage) if (stack != null) if (FluidContainerRegistry.isEmptyContainer(stack)) if (FluidContainerRegistry.fillFluidContainer(new FluidStack(fromBlock, 1000), stack) != null) fluidContainer = stack.copy(); return fluidContainer != null;*/ }
@Override public ItemStack onItemRightClick(ItemStack heldStack, World currentWorld, EntityPlayer clickingPlayer) { // Get the object the user clicked on (raytrace) - the last 'flag' parameter controls whether or not to trace through transparent objects, with 'true' meaning it won't MovingObjectPosition clickedObject = this.getMovingObjectPositionFromPlayer(currentWorld, clickingPlayer, true); // If no object was within the click-range, just return normally if (clickedObject == null) { return heldStack; } else { // If the user clicked on a tile of some sort if (clickedObject.typeOfHit == MovingObjectType.BLOCK) { int x = clickedObject.blockX, y = clickedObject.blockY, z = clickedObject.blockZ; // Make sure the player has permission to edit the clicked-on block, otherwise just cancel this if (!clickingPlayer.canPlayerEdit(x, y, z, clickedObject.sideHit, heldStack)) { return heldStack; } // If it's fluid blood, make it congealed and remove a coagulant if (currentWorld.getBlock(x, y, z) != Blocks.air) { if (currentWorld.getBlock(x, y, z) instanceof IFluidBlock) { IFluidBlock fluidBlock = (IFluidBlock)currentWorld.getBlock(x, y, z); if(fluidBlock.getFluid().getName().contentEquals("blood")) { currentWorld.setBlock(x, y, z, congealedBlock); if(!clickingPlayer.capabilities.isCreativeMode) { --heldStack.stackSize; } } } } return heldStack; } else { return heldStack; } } }
/** * 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; } }
/** * Register this mod's fluid {@link Block}s. * * @param event The event */ @SubscribeEvent public static void registerBlocks(RegistryEvent.Register<Block> event) { final IForgeRegistry<Block> registry = event.getRegistry(); for (final IFluidBlock fluidBlock : MOD_FLUID_BLOCKS) { final Block block = (Block) fluidBlock; block.setRegistryName(Reference.MOD_ID, "fluid." + fluidBlock.getFluid().getName()); block.setUnlocalizedName(Reference.MOD_ID + ":" + fluidBlock.getFluid().getUnlocalizedName()); block.setCreativeTab(ClockworkPhase2.instance.CREATIVE_TAB); registry.register(block); } }
/** * Register this mod's fluid {@link ItemBlock}s. * * @param event The event */ @SubscribeEvent public static void registerItems(RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); for (final IFluidBlock fluidBlock : MOD_FLUID_BLOCKS) { final Block block = (Block) fluidBlock; final ItemBlock itemBlock = new ItemBlock(block); itemBlock.setRegistryName(block.getRegistryName()); registry.register(itemBlock); } }
public Fluid getFluid() { Block b = getBlock(); if ((b instanceof IFluidBlock)) { return ((IFluidBlock)b).getFluid(); } if ((b == Blocks.water) || (b == Blocks.flowing_water)) { return FluidRegistry.WATER; } if ((b == Blocks.lava) || (b == Blocks.flowing_lava)) { return FluidRegistry.LAVA; } return null; }