public BlockFluidSimple(Fluid fluid, String name) { super(fluid, //ThermionicsWorld.MATERIAL_PAIN); Material.WATER); //this.opaque = true; //this.icons = icons; this.quantaPerBlock = 4; this.quantaPerBlockFloat = 4.0f; this.tickRate = 10; //density-based tickrate winds up really high this.setRegistryName(name); this.setUnlocalizedName("thermionics_world.fluid."+name); this.fluidDamage = new DamageSource("fluid."+fluid.getName()).setDamageBypassesArmor().setDamageIsAbsolute(); //if (fluid.getTemperature() > SCALDING) damageAmount = 1 + (fluid.getTemperature() - SCALDING) / 20f; this.setDefaultState(blockState.getBaseState().withProperty(BlockFluidBase.LEVEL, 3)); }
@SideOnly(Side.CLIENT) public void registerRenders() { enumInstanceMap.values().stream().map(Map::entrySet).map(Collection::stream).forEach(entries -> entries.forEach(entry -> { if (Item.class.isAssignableFrom(entry.getValue().getClass())) { if (entry.getValue() instanceof CustomModelMasking) { registerRender((Item) entry.getValue(), 0, ((CustomModelMasking) entry.getValue()).getModelLocation()); FoodCraftReloaded.getLogger().debug("Registered custom model " + entry.getValue().getClass() + " as " + ((CustomModelMasking) entry.getValue()).getModelLocation()); } else if (((Item) entry.getValue()).getRegistryName() != null) { registerRender((Item) entry.getValue(), 0, new ModelResourceLocation(((Item) entry.getValue()).getRegistryName(), "inventory")); } } else if (BlockFluidBase.class.isAssignableFrom(entry.getValue().getClass())) { // TODO Null condition registerFluidRender((BlockFluidBase) entry.getValue(), ((Block)entry.getValue()).getRegistryName().getResourcePath()); } else if (Block.class.isAssignableFrom(entry.getValue().getClass())) { if (entry.getValue() instanceof CustomModelMasking) ModelLoader.setCustomStateMapper((Block) entry.getValue(), block -> ((CustomModelMasking) entry.getValue()).getStateModelLocations()); } })); }
public ExPBiome(BiomeProperties properties, String name, float... biomedata) { super(properties); this.name = name; this.temperatureMultiplier = biomedata[0]; this.humidityMultiplier = biomedata[1]; this.temperatureBaseModifier = biomedata[2]; this.humidityBaseModifier = biomedata[3]; this.spawnableCaveCreatureList.clear(); this.spawnableCreatureList.clear(); this.spawnableMonsterList.clear(); this.spawnableWaterCreatureList.clear(); this.SALT_WATER = ExPBlocks.saltWater.getDefaultState().withProperty(BlockFluidBase.LEVEL, 9); this.FRESH_WATER = ExPBlocks.freshWater.getDefaultState().withProperty(BlockFluidBase.LEVEL, 9); this.LAVA = ExPBlocks.lava.getDefaultState().withProperty(BlockFluidBase.LEVEL, 9); this.SALT_ICE = ExPBlocks.ice.getDefaultState().withProperty(ExPBlockProperties.ICE_IS_SALT, true); this.FRESH_ICE = ExPBlocks.ice.getDefaultState().withProperty(ExPBlockProperties.ICE_IS_SALT, false); this.setRegistryName(ExPRegistryNames.asLocation(name)); Stream.of(EnumCrop.values()).filter(c -> c != EnumCrop.DEAD && c.getData().foundIn.contains(name.toLowerCase())).forEach(this.cropsToGenerate::add); }
@Override public void randomTick(World world, BlockPos pos, IBlockState state, Random random) { super.randomTick(world, pos, state, random); if(random.nextFloat() < 0.05f) { for(int i = 1; i <= 50; i++) { BlockPos checkpos = pos.down(i); if(world.isSideSolid(checkpos, EnumFacing.UP)) { IBlockState checkstate = world.getBlockState(checkpos.up()); if(world.isAirBlock(checkpos.up()) || checkstate.getBlock().isReplaceable(world,checkpos.up()) && !(checkstate.getBlock() instanceof BlockLiquid || checkstate.getBlock() instanceof BlockFluidBase)) world.setBlockState(checkpos.up(), ModBlocks.sakuraLeafPile.getDefaultState(), 3); break; } } } }
@Override public boolean generate(World world, Random rand, BlockPos pos) { boolean result = super.func_180709_b(world, rand, pos); if (result) switch (flowerType) { case RED: int level = minLevel + rand.nextInt(maxLevel - minLevel); IBlockState state = fluid.withProperty(BlockFluidBase.LEVEL, level); world.setBlockState(pos = pos.up(7), state, 2); for (EnumFacing facing : EnumFacing.values()) world.setBlockState(pos.offset(facing), state, 2); default: break; } return result; }
@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; } }); } }
@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; }
/** * Creates and returns fluid object if successful, else returns null. * * @param name name of fluid. * @param still ResourceLocation. * @param flowing ResourceLocation. * @param fluidBlock block fluid uses if applicable. * @param luminosity luminosity of fluid. * @param density density of fluid. * @param temperature temperature of fluid. * @param viscosity viscosity of fluid. * @param isGaseous isGaseous of fluid. * @param rarity rarity of fluid. * @return fluid object. */ public static Fluid createNewFluid(String name, ResourceLocation still, ResourceLocation flowing, BlockFluidBase fluidBlock, int luminosity, int density, int temperature, int viscosity, boolean isGaseous, EnumRarity rarity) { Fluid ret = null; if (name != null && name.length() > 0) { if (luminosity < 0) luminosity = 0; else if (luminosity > 0xf) luminosity = 0xf; ret = new Fluid(name, still, flowing); if (fluidBlock != null) ret.setBlock(fluidBlock); ret.setLuminosity(luminosity); ret.setDensity(density); ret.setTemperature(temperature); ret.setViscosity(viscosity); ret.setGaseous(isGaseous); ret.setRarity(rarity); } return ret; }
public static int getFlowDecayOfFluidAt(World world, int x, int y, int z, Fluid fluid) { int flowDecay = -1; TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof TileEntityFluidJunction) { flowDecay = ((TileEntityFluidJunction) tile).getFlowDecay(fluid); } else { Block block = world.getBlock(x, y, z); if (block != null && getFluidTypeOfBlock(block) == fluid) { if (block instanceof BlockLiquid) flowDecay = Wrappers.getFlowDecay(((BlockLiquid) block), world, x, y, z); else if (block instanceof BlockFluidBase) flowDecay = convertQuantaRemainingToFlowDecay(((BlockFluidBase) block).getQuantaValue(world, x, y, z), getFluidTypeOfBlock(block)); } } return flowDecay; }
public float getCoolant(World world, int x, int y, int z) { float coolant = 0.0F; for (int i = -1; i < 2; i++) for (int j = -1; j < 2; j++) { Block block = world.getBlock(x + i, y, z + j); if (block == Block.getBlockFromName("flowing_water") || block == Block.getBlockFromName("water")) coolant += 0.2F; else if (block == Block.getBlockFromName("flowing_lava") || block == Block.getBlockFromName("lava")) coolant -= 0.2F; else if (block != null && block instanceof BlockFluidBase) { BlockFluidBase liquid = (BlockFluidBase) block; Fluid fluid = liquid.getFluid(); if (fluid != null) { float fluidTemp = fluid.getTemperature(world, x + i, y, z + j); if (fluidTemp < this.getTemperature()) coolant += (this.getTemperature() - fluidTemp) / 10; else coolant -= (fluidTemp - this.getTemperature()) / 10; } } } return coolant; }
public ItemBlockPneumaticCraft(Block block) { super(block); if (block instanceof BlockPneumaticCraft) { this.block = (BlockPneumaticCraft) block; } else { if (!(block instanceof BlockAir) && !(block instanceof BlockFluidBase)) { Log.warning("Block " + block.getUnlocalizedName() + " does not extend BlockPneumaticCraft! No tooltip displayed"); } } }
/** * Check if the given blockpos contains a fluid source block. * * @param world the world * @param pos the blockpos * @return true if there is a fluid source block at the given blockpos, false otherwise */ public static boolean isSourceBlock(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); if (state.getProperties().containsKey(BlockLiquid.LEVEL)) { return state.getValue(BlockLiquid.LEVEL) == 0; } else return state.getProperties().containsKey(BlockFluidBase.LEVEL) && state.getValue(BlockFluidBase.LEVEL) == 0; }
public static void renderGhostBlock(IBlockState state, BlockPos position, Color color, boolean noDepth, float partialTicks) { if(!(state.getBlock() instanceof BlockLiquid) && !(state.getBlock() instanceof BlockFluidBase)) { renderGhostModel(Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state), position, color, noDepth, partialTicks); return; } GlStateManager.enableBlend(); GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_DST_COLOR); BufferBuilder vb; if(noDepth) { GlStateManager.depthFunc(519); vb = prepRenderBlockDepth(partialTicks, true); } else vb = prepRender(partialTicks, true); vb.begin(7, DefaultVertexFormats.BLOCK); World world = Minecraft.getMinecraft().world; Minecraft.getMinecraft().getBlockRendererDispatcher().renderBlock(state, position.add(0, noDepth ? 500 : 0, 0), world, vb); for(int i = 0; i < vb.getVertexCount(); i++) vb.putColorMultiplier(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, i); vb.color(1, 1, 1, 0.1f); postRender(); GlStateManager.disableBlend(); GlStateManager.depthFunc(515); }
public static boolean isFluid(IBlockState state) { boolean flag1 = state.getBlock() instanceof BlockLiquid; boolean flag2 = state.getBlock().getMaterial(state).isLiquid(); boolean flag3 = state.getBlock() instanceof BlockFluidBase; return flag1 || flag2 || flag3; }
private static int[] getCorners(Optional<IExtendedBlockState> stateOption) { int[] cornerRound = new int[]{0, 0, 0, 0}; if(stateOption.isPresent()) { IExtendedBlockState state = stateOption.get(); for(int i = 0; i < 4; i++) { Float level = state.getValue(BlockFluidBase.LEVEL_CORNERS[i]); cornerRound[i] = Math.round((level == null ? 7f / 8 : level) * 768); } } return cornerRound; }
private static int getFlow(Optional<IExtendedBlockState> stateOption) { Float flow = -1000f; if(stateOption.isPresent()) { flow = stateOption.get().getValue(BlockFluidBase.FLOW_DIRECTION); if(flow == null) flow = -1000f; } int flowRound = (int)Math.round(Math.toDegrees(flow)); flowRound = MathHelper.clamp_int(flowRound, -1000, 1000); return flowRound; }
@SideOnly(Side.CLIENT) protected void registerFluidRender(BlockFluidBase blockFluid, String blockStateName) { final String location = FoodCraftReloaded.MODID + ":" + blockStateName; final Item itemFluid = Item.getItemFromBlock(blockFluid); ModelLoader.setCustomMeshDefinition(itemFluid, stack -> new ModelResourceLocation(location, "fluid")); ModelLoader.setCustomStateMapper(blockFluid, new StateMapperBase() { @Nonnull @Override protected ModelResourceLocation getModelResourceLocation(@Nonnull IBlockState state) { return new ModelResourceLocation(location, "fluid"); } }); }
@Override public boolean generate(World worldIn, Random rand, BlockPos position) { IBlockState oilBlock = ExPBlocks.oil.getDefaultState().withProperty(BlockFluidBase.LEVEL, 10); int randomY = 32 + rand.nextInt(64); int size = 4 + rand.nextInt(8); BlockPos at = new BlockPos(position.getX(), randomY, position.getZ()); for (int dx = -size; dx <= size; ++dx) { for (int dy = -size; dy <= size; ++dy) { for (int dz = -size; dz <= size; ++dz) { double dist = Math.sqrt(dx * dx + dy * dy + dz * dz); if (dist > size) { continue; } worldIn.setBlockState(at.add(dx, dy, dz), oilBlock, 2); } } } int randomYEx = 8 + rand.nextInt(size * 2); while (at.getY() < randomYEx + 128) { if (worldIn.getBlockState(at.up(3)).getMaterial() == Material.WATER && worldIn.getBlockState(at.up(3)) != oilBlock) { break; } worldIn.setBlockState(at, oilBlock, 2); at = at.up(); } return true; }
public void tryMelt(World world, BlockPos pos, IBlockState state, Random rand) { float temp = Helpers.getTemperatureAt(world, pos); if (temp > 0 && rand.nextFloat() < temp / 10 && world.isAirBlock(pos.up())) { boolean salt = state.getValue(ExPBlockProperties.ICE_IS_SALT); world.setBlockState(pos, salt ? ExPBlocks.saltWater.getDefaultState().withProperty(BlockFluidBase.LEVEL, 9) : ExPBlocks.freshWater.getDefaultState().withProperty(BlockFluidBase.LEVEL, 9)); } }
@SubscribeEvent public void onRightClick(PlayerInteractEvent.RightClickBlock event) { if (!event.getWorld().isRemote) { EntityPlayer player = event.getEntityPlayer(); IExPPlayer data = IExPPlayer.of(player); if (data.getThirst() < data.getMaxThirst(true) - 200) { RayTraceResult rtr = event.getWorld().rayTraceBlocks(player.getPositionEyes(1), player.getPositionEyes(1).add(player.getLook(1).scale(3)), true, false, false); if (rtr != null && rtr.typeOfHit == Type.BLOCK) { BlockPos pos = rtr.getBlockPos(); IBlockState hit = event.getWorld().getBlockState(pos); if (hit.getBlock() instanceof IWater && !((IWater)hit.getBlock()).isSalt(event.getWorld(), pos)) { int level = hit.getValue(BlockFluidBase.LEVEL); if (level > 0) { event.getWorld().setBlockState(pos, hit.withProperty(BlockFluidBase.LEVEL, level - 1)); } else { event.getWorld().setBlockToAir(pos); } data.setThirst(data.getThirst() + 200, true); event.getWorld().playSound(null, pos, SoundEvents.ENTITY_GENERIC_DRINK, SoundCategory.PLAYERS, 1, 1); } } } } }
private IBlockStateDescriptor(Block block) { List<Integer> usedMetas = Lists.newArrayList(); if(!(block instanceof BlockLiquid) && !(block instanceof BlockFluidBase)) { for (IBlockState state : block.getBlockState().getValidStates()) { int meta = block.getMetaFromState(state); if(!usedMetas.contains(meta)) { usedMetas.add(meta); this.applicable.add(state); } } } if(applicable.isEmpty()) { applicable.add(block.getDefaultState()); } }
@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; } }
public static BlockFluidBase registerClassicBlock(Fluid fluid) { BlockFluidBase block = new BlockCrystalFluid(fluid, net.minecraft.block.material.Material.WATER); return ModBlocks.registerBlock(block, new ItemBlock(block){ @Override public String getItemStackDisplayName(ItemStack stack) { return Lang.translateToLocal(this.getUnlocalizedNameInefficiently(stack)).trim(); } }, fluid.getName()); }
public static BlockFluidBase registerMoltenBlock(Fluid fluid) { BlockFluidBase block = new BlockCrystalFluid(fluid, net.minecraft.block.material.Material.LAVA); return ModBlocks.registerBlock(block, new ItemBlock(block){ @Override public String getItemStackDisplayName(ItemStack stack) { return Lang.translateToLocal(this.getUnlocalizedNameInefficiently(stack)).trim(); } }, fluid.getName()); }
private void checkFluidBlocks(BlockPos pos) { if (pos.getY() < 2) { lvl = 0; return; } fluidBlocks.clear(); IBlockState stateB = world.getBlockState(pos); if (stateB.getBlock() instanceof BlockFluidBase || stateB.getBlock() instanceof BlockLiquid) { Stack<BlockPos> nextPos = new Stack<>(); nextPos.add(pos); while (!nextPos.isEmpty()) { BlockPos p = nextPos.pop(); if (!fluidBlocks.contains(p) && p.distanceSq(this.pos) < 4096) { fluidBlocks.add(p); for (EnumFacing f : EnumFacing.HORIZONTALS) { if (!fluidBlocks.contains(p.offset(f))) { IBlockState stateB2 = world.getBlockState(p.offset(f)); if (stateB2.getBlock() instanceof BlockFluidBase || stateB2.getBlock() instanceof BlockLiquid) { nextPos.add(p.offset(f)); } } } } } } else if (stateB.getMaterial() != Material.AIR) { lvl = 0; } }
/** Make sure to set up the rendering info */ @SideOnly(Side.CLIENT) public static void registerRendering() { for(Fluid fluid : fluidBlocks.keySet()) { BlockFluidBase block = fluidBlocks.get(fluid); final ModelResourceLocation fluidModelLocation = new ModelResourceLocation( RefStrings.MODID + ":" + fluidBlockNames.get(block), "fluid"); ModelLoader.setCustomStateMapper(block, new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState state) { return fluidModelLocation; } }); } }
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; }
/** * Creates and resturns fluid object if successful, else returns null. * * @param name name of fluid. * @param still ResourceLocation. * @param flowing ResourceLocation. * @param fluidBlock block fluid uses if applicable. * @param rarity rarity of fluid. * @return fluid object. */ public static Fluid createNewFluid(String name, ResourceLocation still, ResourceLocation flowing, BlockFluidBase fluidBlock, EnumRarity rarity) { if (name != null && name.length() > 0) { Fluid fluid = new Fluid(name, still, flowing); if (fluidBlock != null) fluid.setBlock(fluidBlock); fluid.setRarity(rarity); return fluid; } return null; }
public static boolean canBreak(Block block,World w, int x, int y,int z){ if(block == Blocks.air)return false; if(block instanceof BlockLiquid)return false; if(block instanceof BlockFluidBase)return false; if(Block.isEqualTo(block,Blocks.mob_spawner))return false; if(block == Blocks.portal)return false; if(block == Blocks.end_portal)return false; if(block == Blocks.end_portal_frame)return false; if(block.getBlockHardness(w, x, y, z) == -1)return false; return true; }
/** * Adds fluid block models to the game and applies them to the fluid blocks */ @SideOnly(Side.CLIENT) public static void bakeModels(){ String modID = PowerAdvantage.MODID; for(Map.Entry<String,Block> e : allBlocks.entrySet()){ Block b = e.getValue(); String name = e.getKey(); if(b instanceof BlockFluidBase){ BlockFluidBase block = (BlockFluidBase)b; Fluid fluid = block.getFluid(); Item item = Item.getItemFromBlock(block); final ModelResourceLocation fluidModelLocation = new ModelResourceLocation( modID.toLowerCase() + ":" + name, "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; } }); } } }
private static Block addBlock(Block block, String name ){ block.setUnlocalizedName(PowerAdvantage.MODID+"."+name); GameRegistry.registerBlock(block, name); if((block instanceof BlockFluidBase) == false)block.setCreativeTab(ItemGroups.tab_powerAdvantage); allBlocks.put(name, block); return block; }
@Override public void updateTick(World world, int x, int y, int z, Random rand) { super.updateTick(world, x, y, z, rand); final Block bl = world.getBlock(x, y - 1, z); if (!world.isRemote && !(bl instanceof BlockFluidBase) && bl.getHarvestLevel(world.getBlockMetadata(x, y - 1, z)) < rand.nextInt(2)) { IaSBlockHelper.breakBlock(world, x, y - 1, z, false); } }
public static int getQuantaPerBlock(Block block) { if (block instanceof BlockFluidBase) return Wrappers.getQuantaPerBlock((BlockFluidBase) block); else { if (isBlockWater(block)) return 8; else if (isBlockLava(block)) return 8; } return 0; }
public int getQuantaRemaining() { int quantaPerBlock = 8; if (fluid != FluidRegistry.WATER || fluid != FluidRegistry.LAVA && fluid.getBlock() instanceof BlockFluidBase) quantaPerBlock = Wrappers.getQuantaPerBlock((BlockFluidBase) fluid.getBlock()); return Math.max(0, quantaPerBlock - flowDecay); }
public static int getQuantaPerBlock(BlockFluidBase fluidBlock) { try { return quantaPerBlock.getInt(fluidBlock); } catch (Exception e) { e.printStackTrace(); return 0; } }
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"); } } }