From 2a89c258f88086b2168128434249837874ba6615 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 10 Nov 2013 13:18:28 -0500 Subject: [PATCH] Started up on gas blocks --- models/TestCar.tcn | Bin 1078 -> 1078 bytes .../assets/dark/textures/models/TestCar.png | Bin 0 -> 1966 bytes src/dark/api/IGasBlock.java | 10 + src/dark/core/common/CoreRecipeLoader.java | 2 + src/dark/core/common/DarkMain.java | 11 ++ src/dark/core/common/blocks/BlockGasOre.java | 85 +++++++++ .../core/common/blocks/OreGenSettings.java | 178 ------------------ src/dark/core/common/blocks/OreGenerator.java | 47 ----- src/dark/core/prefab/fluids/EnumFluid.java | 6 + src/dark/core/prefab/fluids/EnumGas.java | 2 +- .../core/registration/ModObjectRegistry.java | 3 +- 11 files changed, 117 insertions(+), 227 deletions(-) create mode 100644 resources/assets/dark/textures/models/TestCar.png create mode 100644 src/dark/api/IGasBlock.java create mode 100644 src/dark/core/common/blocks/BlockGasOre.java delete mode 100644 src/dark/core/common/blocks/OreGenSettings.java delete mode 100644 src/dark/core/common/blocks/OreGenerator.java create mode 100644 src/dark/core/prefab/fluids/EnumFluid.java diff --git a/models/TestCar.tcn b/models/TestCar.tcn index 803803b5ad511a7fceb9e6d43ea0f551f03c76a0..79c74127b3f2b826ad029d62953ed713eb743d89 100644 GIT binary patch delta 79 zcmdnSv5kW#z?+#xgn@y9gTX3gB9FRg%j_aH>wD)IQRs~xoy<&DDU&ZVn_^cmS(Zf- E0KB{!0{{R3 delta 79 zcmdnSv5kW#z?+#xgn@y9gF!25B9FT0uQiK84DOv{M4>l&bTTt(MNPiUY>HjMWLXwT E0B}zqs{jB1 diff --git a/resources/assets/dark/textures/models/TestCar.png b/resources/assets/dark/textures/models/TestCar.png new file mode 100644 index 0000000000000000000000000000000000000000..632cae0b6199fe377fa4a22b9c01cda1140d17a8 GIT binary patch literal 1966 zcmV;f2T}NmP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2SZ6jK~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0yEaVw1 z7BCgtWKyT0WK#L*Oo0M8qTfHT4hcICl}T*YzyKW4>AY~#VpmqefO_$&vWNw05JQ|E z$P|MW&JIq@1{+Pq_dy^GfH~*_m;(a2;!u5kgaK>z>%07*qoM6N<$f;ZNY A5C8xG literal 0 HcmV?d00001 diff --git a/src/dark/api/IGasBlock.java b/src/dark/api/IGasBlock.java new file mode 100644 index 000000000..adfed39c2 --- /dev/null +++ b/src/dark/api/IGasBlock.java @@ -0,0 +1,10 @@ +package dark.api; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.fluids.IFluidBlock; + +public interface IGasBlock extends IFluidBlock +{ + /** Can a fracking machine harvest this gas underground */ + public boolean canFrackerHarvest(TileEntity entity); +} diff --git a/src/dark/core/common/CoreRecipeLoader.java b/src/dark/core/common/CoreRecipeLoader.java index 53068d455..377172fde 100644 --- a/src/dark/core/common/CoreRecipeLoader.java +++ b/src/dark/core/common/CoreRecipeLoader.java @@ -11,6 +11,7 @@ import dark.api.ColorCode; import dark.api.reciepes.MachineRecipeHandler; import dark.api.reciepes.ProcessorType; import dark.core.common.blocks.BlockBasalt; +import dark.core.common.blocks.BlockGasOre; import dark.core.common.blocks.BlockOre; import dark.core.common.blocks.BlockOre.OreData; import dark.core.common.items.EnumMaterial; @@ -34,6 +35,7 @@ public class CoreRecipeLoader extends RecipeLoader public static Block blockBasalt; public static Block blockGlowGlass; public static Block basicMachine, blockSolar; + public static BlockGasOre blockGas; /* ITEMS */ public static Item itemMetals, battery, itemTool, itemParts; diff --git a/src/dark/core/common/DarkMain.java b/src/dark/core/common/DarkMain.java index 63b4c0169..a735a6c9c 100644 --- a/src/dark/core/common/DarkMain.java +++ b/src/dark/core/common/DarkMain.java @@ -10,6 +10,7 @@ import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.oredict.OreDictionary; import universalelectricity.prefab.TranslationHelper; import universalelectricity.prefab.ore.OreGenReplaceStone; @@ -59,6 +60,7 @@ import dark.core.helpers.PacketDataWatcher; import dark.core.network.PacketHandler; import dark.core.prefab.ItemBlockHolder; import dark.core.prefab.ModPrefab; +import dark.core.prefab.fluids.EnumGas; import dark.core.prefab.machine.BlockMulti; import dark.core.prefab.vehicles.EntityDrivable; import dark.core.prefab.vehicles.ItemVehicleSpawn; @@ -131,6 +133,15 @@ public class DarkMain extends ModPrefab super.init(event); EntityRegistry.registerGlobalEntityID(EntityDrivable.class, "TestCar", EntityRegistry.findGlobalUniqueEntityId()); EntityRegistry.registerModEntity(EntityDrivable.class, "TestCar", 60, this, 64, 1, true); + + for (EnumGas gas : EnumGas.values()) + { + FluidRegistry.registerFluid(gas.getGas()); + if (CoreRecipeLoader.blockGas != null) + { + gas.getGas().setBlockID(CoreRecipeLoader.blockGas); + } + } if (CoreRecipeLoader.blockOre != null) { for (OreData data : OreData.values()) diff --git a/src/dark/core/common/blocks/BlockGasOre.java b/src/dark/core/common/blocks/BlockGasOre.java new file mode 100644 index 000000000..9bba670a0 --- /dev/null +++ b/src/dark/core/common/blocks/BlockGasOre.java @@ -0,0 +1,85 @@ +package dark.core.common.blocks; + +import universalelectricity.prefab.block.BlockTile; +import dark.api.IGasBlock; +import dark.core.common.DarkMain; +import dark.core.prefab.fluids.Gas; +import dark.core.prefab.machine.TileEntityNBTContainer; +import net.minecraft.block.material.Material; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.Configuration; +import net.minecraftforge.fluids.BlockFluidFinite; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +/** Gas that is designed to generate underground in the same way as an ore + * + * TODO code actual gas behavior such as expanding to fill an area but at the same time losing + * volume + * + * @author DarkGuardsman */ +public class BlockGasOre extends BlockTile implements IGasBlock +{ + + public BlockGasOre() + { + super(DarkMain.CONFIGURATION.getBlock("GasBlock", DarkMain.getNextID()).getInt(), Material.air); + this.setUnlocalizedName("DMBlockGas"); + } + + public void placeAndCreate(World world, int x, int y, int z, FluidStack stack) + { + world.setBlock(x, y, z, this.blockID, 0, 2); + TileEntity entity = world.getBlockTileEntity(x, y, z); + if (entity instanceof TileEntityNBTContainer) + { + ((TileEntityNBTContainer) entity).getSaveData().setCompoundTag("Fluid", stack.writeToNBT(new NBTTagCompound())); + } + world.markBlockForUpdate(x, y, z); + } + + /* IFluidBlock */ + @Override + public FluidStack drain(World world, int x, int y, int z, boolean doDrain) + { + TileEntity entity = world.getBlockTileEntity(x, y, z); + if (entity instanceof TileEntityNBTContainer) + { + FluidStack fluid = FluidStack.loadFluidStackFromNBT(((TileEntityNBTContainer) entity).getSaveData().getCompoundTag("Fluid")); + if (doDrain || fluid == null) + { + world.setBlockToAir(x, y, z); + } + return fluid; + } + return null; + } + + @Override + public boolean canDrain(World world, int x, int y, int z) + { + return true; + } + + @Override + public boolean canFrackerHarvest(TileEntity entity) + { + return true; + } + + @Override + public Fluid getFluid() + { + return null; + } + + @Override + public TileEntity createNewTileEntity(World var1) + { + return new TileEntityNBTContainer(); + } + +} diff --git a/src/dark/core/common/blocks/OreGenSettings.java b/src/dark/core/common/blocks/OreGenSettings.java deleted file mode 100644 index e151eb4f5..000000000 --- a/src/dark/core/common/blocks/OreGenSettings.java +++ /dev/null @@ -1,178 +0,0 @@ -package dark.core.common.blocks; - -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.ChunkProviderEnd; -import net.minecraft.world.gen.ChunkProviderGenerate; -import net.minecraft.world.gen.ChunkProviderHell; -import net.minecraftforge.common.Configuration; -import net.minecraftforge.common.MinecraftForge; -import cpw.mods.fml.common.FMLLog; - -public class OreGenSettings -{ - public int minGenerateLevel; - public int maxGenerateLevel; - public int amountPerChunk; - public int amountPerBranch; - public int replaceID; - - public boolean ignoreSurface = false; - public boolean ignoreNether = true; - public boolean ignoreEnd = true; - - public boolean shouldGenerate = false; - - public int havestLevel; - public String harvestTool; - - public String oreName; - public ItemStack oreStack; - - /** @param name - name of the ore to be used in the config file - * @param stack - itemStack of the ore, amount doesn't matter - * @param harvestTool - tool needed to harvest tool - * @param harvestLevel - level of hardness need to harvest the ore */ - public OreGenSettings(String name, ItemStack stack, String harvestTool, int harvestLevel, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) - { - if (stack != null) - { - this.harvestTool = harvestTool; - this.oreStack = stack; - this.havestLevel = harvestLevel; - - this.minGenerateLevel = minGenerateLevel; - this.maxGenerateLevel = maxGenerateLevel; - this.amountPerChunk = amountPerChunk; - this.amountPerBranch = amountPerBranch; - this.replaceID = replaceID; - - MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel); - } - else - { - FMLLog.severe("ItemStack is null while registering ore generation!"); - } - } - - public OreGenSettings genStone(String name, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) - { - return new OreGenSettings(name, stack, "pickAxe", 1, Block.stone.blockID, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch); - } - - /** Is the ore gen enabled */ - public OreGenSettings enable(Configuration config) - { - this.shouldGenerate = shouldGenerateOre(config, this.oreName); - return this; - } - - /** Checks the config file and see if Universal Electricity should generate this ore */ - private static boolean shouldGenerateOre(Configuration configuration, String oreName) - { - boolean shouldGenerate = configuration.get("Ore_Generation", "Generate_" + oreName, true).getBoolean(true); - configuration.save(); - return shouldGenerate; - } - - public void generate(World world, Random random, int chunkCoordX, int chunkCoordZ) - { - try - { - for (int i = 0; i < this.amountPerChunk; i++) - { - int x = chunkCoordX + random.nextInt(16); - int z = chunkCoordZ + random.nextInt(16); - int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel; - this.generateReplace(world, random, x, y, z); - } - } - catch (Exception e) - { - System.out.println("Error generating ore: " + this.oreName); - e.printStackTrace(); - } - } - - public boolean generateReplace(World world, Random random, int genX, int genY, int genZ) - { - float var6 = random.nextFloat() * (float) Math.PI; - double var7 = genX + 8 + MathHelper.sin(var6) * this.amountPerBranch / 8.0F; - double var9 = genX + 8 - MathHelper.sin(var6) * this.amountPerBranch / 8.0F; - double var11 = genZ + 8 + MathHelper.cos(var6) * this.amountPerBranch / 8.0F; - double var13 = genZ + 8 - MathHelper.cos(var6) * this.amountPerBranch / 8.0F; - double var15 = genY + random.nextInt(3) - 2; - double var17 = genY + random.nextInt(3) - 2; - - for (int branchCount = 0; branchCount <= this.amountPerBranch; ++branchCount) - { - double var20 = var7 + (var9 - var7) * branchCount / this.amountPerBranch; - double var22 = var15 + (var17 - var15) * branchCount / this.amountPerBranch; - double var24 = var11 + (var13 - var11) * branchCount / this.amountPerBranch; - double var26 = random.nextDouble() * this.amountPerBranch / 16.0D; - double var28 = (MathHelper.sin(branchCount * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D; - double var30 = (MathHelper.sin(branchCount * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D; - int var32 = MathHelper.floor_double(var20 - var28 / 2.0D); - int var33 = MathHelper.floor_double(var22 - var30 / 2.0D); - int var34 = MathHelper.floor_double(var24 - var28 / 2.0D); - int var35 = MathHelper.floor_double(var20 + var28 / 2.0D); - int var36 = MathHelper.floor_double(var22 + var30 / 2.0D); - int var37 = MathHelper.floor_double(var24 + var28 / 2.0D); - - for (int x = var32; x <= var35; ++x) - { - double var39 = (x + 0.5D - var20) / (var28 / 2.0D); - - if (var39 * var39 < 1.0D) - { - for (int y = var33; y <= var36; ++y) - { - double var42 = (y + 0.5D - var22) / (var30 / 2.0D); - - if (var39 * var39 + var42 * var42 < 1.0D) - { - for (int z = var34; z <= var37; ++z) - { - double var45 = (z + 0.5D - var24) / (var28 / 2.0D); - - int block = world.getBlockId(x, y, z); - if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID)) - { - world.setBlock(x, y, z, this.oreStack.itemID, this.oreStack.getItemDamage(), 2); - } - } - } - } - } - } - } - - return true; - } - - public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) - { - if (!this.shouldGenerate) - { - return false; - } - if (this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate) - { - return false; - } - if (this.ignoreNether && chunkGenerator instanceof ChunkProviderHell) - { - return false; - } - if (this.ignoreEnd && chunkGenerator instanceof ChunkProviderEnd) - { - return false; - } - return true; - } -} diff --git a/src/dark/core/common/blocks/OreGenerator.java b/src/dark/core/common/blocks/OreGenerator.java deleted file mode 100644 index a1574dab9..000000000 --- a/src/dark/core/common/blocks/OreGenerator.java +++ /dev/null @@ -1,47 +0,0 @@ -package dark.core.common.blocks; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import cpw.mods.fml.common.IWorldGenerator; -import cpw.mods.fml.common.registry.GameRegistry; - -public class OreGenerator implements IWorldGenerator -{ - public static boolean isInitiated = false; - - /** Add your ore data to this list of ores for it to automatically generate! No hassle indeed! */ - private static final List ORES_TO_GENERATE = new ArrayList(); - - /** Adds an ore to the ore generate list. Do this in pre-init. */ - public static void addOre(OreGenSettings data) - { - if (!isInitiated) - { - GameRegistry.registerWorldGenerator(new OreGenerator()); - } - - ORES_TO_GENERATE.add(data); - } - - @Override - public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) - { - chunkX = chunkX << 4; - chunkZ = chunkZ << 4; - - // Checks to make sure this is the normal - // world - for (OreGenSettings oreData : ORES_TO_GENERATE) - { - if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) - { - oreData.generate(world, rand, chunkX, chunkZ); - } - - } - } -} diff --git a/src/dark/core/prefab/fluids/EnumFluid.java b/src/dark/core/prefab/fluids/EnumFluid.java new file mode 100644 index 000000000..e1e2417a8 --- /dev/null +++ b/src/dark/core/prefab/fluids/EnumFluid.java @@ -0,0 +1,6 @@ +package dark.core.prefab.fluids; + +public enum EnumFluid +{ + +} diff --git a/src/dark/core/prefab/fluids/EnumGas.java b/src/dark/core/prefab/fluids/EnumGas.java index 563113610..a66ada4a8 100644 --- a/src/dark/core/prefab/fluids/EnumGas.java +++ b/src/dark/core/prefab/fluids/EnumGas.java @@ -59,7 +59,7 @@ public enum EnumGas gas = new Gas(fluidName); if (data instanceof ChemElement) { - gas.setDensity((int) ((ChemElement) data).density); + gas.setDensity((int) ((ChemElement) data).density * 1000); } } return gas; diff --git a/src/dark/core/registration/ModObjectRegistry.java b/src/dark/core/registration/ModObjectRegistry.java index ebce8ea2a..9f106b0f0 100644 --- a/src/dark/core/registration/ModObjectRegistry.java +++ b/src/dark/core/registration/ModObjectRegistry.java @@ -22,6 +22,7 @@ import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.registry.GameRegistry; import dark.core.common.DarkMain; +import dark.core.common.blocks.BlockGasOre; import dark.core.interfaces.IExtraInfo; import dark.core.interfaces.IExtraInfo.IExtraBlockInfo; import dark.core.interfaces.IExtraInfo.IExtraItemInfo; @@ -159,7 +160,7 @@ public class ModObjectRegistry { Block fluidBlock = null; Fluid fluidActual = null; - if (config != null && fluid != null && config.get("general", "EnableOilFluid", true).getBoolean(true) && FluidRegistry.getFluid(fluid.getName()) == null) + if (config != null && fluid != null && config.get("general", "EnableFluid_" + fluid.getName(), true).getBoolean(true) && FluidRegistry.getFluid(fluid.getName()) == null) { FluidRegistry.registerFluid(fluid); fluidActual = FluidRegistry.getFluid(fluid.getName());