Started up on gas blocks

This commit is contained in:
Robert 2013-11-10 13:18:28 -05:00
parent 0f9721e0c2
commit 2a89c258f8
11 changed files with 117 additions and 227 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

@ -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);
}

View file

@ -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;

View file

@ -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())

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -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<OreGenSettings> ORES_TO_GENERATE = new ArrayList<OreGenSettings>();
/** 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);
}
}
}
}

View file

@ -0,0 +1,6 @@
package dark.core.prefab.fluids;
public enum EnumFluid
{
}

View file

@ -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;

View file

@ -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());