worked on gas blocks

dropped the ideal of using a tile entity as it was not generating with
it correctly. Instead we are going to use metadata to represent the
volume starting at 512 bucks and working down to 10mb.
This commit is contained in:
Robert 2013-11-22 16:44:33 -05:00
parent 574491d126
commit ec59a3d8b5
7 changed files with 105 additions and 199 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

View file

@ -11,7 +11,6 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.ore.OreGenReplaceStone;
@ -45,7 +44,6 @@ import dark.core.common.blocks.BlockOre.OreData;
import dark.core.common.blocks.GasOreGenerator;
import dark.core.common.blocks.ItemBlockColored;
import dark.core.common.blocks.ItemBlockOre;
import dark.core.common.blocks.OreGenFluid;
import dark.core.common.items.EnumMaterial;
import dark.core.common.items.EnumOrePart;
import dark.core.common.items.ItemBattery;
@ -69,7 +67,6 @@ import dark.core.prefab.fluids.EnumGas;
import dark.core.prefab.machine.BlockMulti;
import dark.core.prefab.machine.TileEntityNBTContainer;
import dark.core.prefab.vehicles.EntityTestCar;
import dark.core.prefab.vehicles.EntityVehicle;
import dark.core.prefab.vehicles.ItemVehicleSpawn;
import dark.core.registration.ModObjectRegistry;
@ -281,7 +278,6 @@ public class DarkMain extends ModPrefab
CoreRecipeLoader.blockGlowGlass = ModObjectRegistry.createNewBlock("DMBlockGlowGlass", DarkMain.MOD_ID, BlockColorGlowGlass.class, ItemBlockColored.class);
CoreRecipeLoader.blockSolar = ModObjectRegistry.createNewBlock("DMBlockSolar", DarkMain.MOD_ID, BlockSolarPanel.class, ItemBlockHolder.class);
CoreRecipeLoader.blockGas = ModObjectRegistry.createNewBlock("DMBlockGas", DarkMain.MOD_ID, BlockGasOre.class, ItemBlockHolder.class);
/* ITEMS */
CoreRecipeLoader.itemTool = ModObjectRegistry.createNewItem("DMReadoutTools", DarkMain.MOD_ID, ItemReadoutTools.class, true);

View file

@ -1,43 +1,90 @@
package dark.core.common.blocks;
import java.util.List;
import java.util.Set;
import java.awt.Color;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import universalelectricity.prefab.block.BlockTile;
import com.builtbroken.common.Pair;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.api.IGasBlock;
import dark.core.common.CoreRecipeLoader;
import dark.core.common.DMCreativeTab;
import dark.core.common.DarkMain;
import dark.core.interfaces.IExtraInfo.IExtraBlockInfo;
import dark.core.prefab.ModPrefab;
import dark.core.prefab.fluids.EnumGas;
/** 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, IExtraBlockInfo
public class BlockGasOre extends Block implements IGasBlock
{
public static final int[] volumePerMeta = new int[] { 10, 35, 75, 125, 250, 500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 12800, 256000, 512000 };
public BlockGasOre()
{
super(DarkMain.CONFIGURATION.getBlock("GasBlock", DarkMain.getNextID()).getInt(), Material.air);
super(DarkMain.CONFIGURATION.getBlock("GasBlock", ModPrefab.getNextID()).getInt(), Material.air);
this.setUnlocalizedName("DMBlockGas");
this.setCreativeTab(DMCreativeTab.tabIndustrial);
this.setTickRandomly(true);
}
@Override
public void updateTick(World world, int x, int y, int z, Random rand)
{
if (!world.isRemote)
{
if (rand.nextFloat() > 0.5f)
{
final Vector3 vec = new Vector3(x, y, z);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
int meta = world.getBlockMetadata(x, y, z);
Vector3 sVec = vec.clone().modifyPositionFromSide(dir);
int sMeta = sVec.getBlockMetadata(world);
int blockID = sVec.getBlockID(world);
Block block = Block.blocksList[blockID];
if (block != null && block.isAirBlock(world, x, y, z) && blockID != this.blockID)
{
if (meta == 0)
{
world.setBlockToAir(x, y, z);
break;
}
else
{
world.setBlock(x, y, z, this.blockID, meta / 2, 2);
sVec.setBlock(world, this.blockID, meta / 2, 2);
break;
}
}
else if (blockID == this.blockID && meta > sMeta)
{
meta += sMeta;
world.setBlock(x, y, z, this.blockID, meta / 2, 2);
sVec.setBlock(world, this.blockID, meta / 2, 2);
break;
}
}
}
}
}
@Override
@ -52,19 +99,6 @@ public class BlockGasOre extends BlockTile implements IGasBlock, IExtraBlockInfo
return true;
}
public static void placeAndCreate(World world, int x, int y, int z, FluidStack stack)
{
if (stack != null)
{
world.setBlock(x, y, z, CoreRecipeLoader.blockGas.blockID, 0, 2);
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityGasBlock)
{
((TileEntityGasBlock) entity).setStack(stack);
}
}
}
/* IFluidBlock */
@Override
public FluidStack drain(World world, int x, int y, int z, boolean doDrain)
@ -101,43 +135,69 @@ public class BlockGasOre extends BlockTile implements IGasBlock, IExtraBlockInfo
}
@Override
public TileEntity createNewTileEntity(World var1)
public int idDropped(int par1, Random par2Random, int par3)
{
return new TileEntityGasBlock();
return 0;
}
@Override
public boolean hasExtraConfigs()
public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
return null;
}
@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon(DarkMain.getInstance().PREFIX + "gas");
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public void loadExtraConfigs(Configuration config)
@SideOnly(Side.CLIENT)
public int getBlockColor()
{
//TODO add configs for spread rate,and update rate
return Color.GREEN.getRGB();
}
@Override
public void loadOreNames()
@SideOnly(Side.CLIENT)
public int getRenderColor(int par1)
{
// TODO Auto-generated method stub
return this.getBlockColor();
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
list.add(new Pair<String, Class<? extends TileEntity>>("DMTileGas", TileEntityGasBlock.class));
return true;
}
@Override
public void getClientTileEntityRenderers(List<Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>> list)
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
// TODO Auto-generated method stub
int l = 0;
int i1 = 0;
int j1 = 0;
for (int k1 = -1; k1 <= 1; ++k1)
{
for (int l1 = -1; l1 <= 1; ++l1)
{
int i2 = par1IBlockAccess.getBiomeGenForCoords(par2 + l1, par4 + k1).getBiomeGrassColor();
l += (i2 & 16711680) >> 16;
i1 += (i2 & 65280) >> 8;
j1 += i2 & 255;
}
}
return (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255;
}
}

View file

@ -16,13 +16,14 @@ import net.minecraftforge.fluids.FluidStack;
import universalelectricity.prefab.ore.OreGenBase;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.registry.GameRegistry;
import dark.core.common.CoreRecipeLoader;
public class GasOreGenerator implements IWorldGenerator
{
public int minGenerateLevel = 6;
public int maxGenerateLevel = 50;
public int amountPerChunk = 3;
public int amountPerChunk = 10;
public int amountPerBranch = 10;
public int replaceID = 1;
@ -107,7 +108,7 @@ public class GasOreGenerator implements IWorldGenerator
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (block == null || block.isAirBlock(world, x, y, z) || block.canBeReplacedByLeaves(world, x, y, z) || blockid == this.replaceID))
{
System.out.println("Generated a gas at " + x + "x " + y + "y " + z + "z ");
BlockGasOre.placeAndCreate(world, x, y, z, stack);
world.setBlock(x, y, z, CoreRecipeLoader.blockGas.blockID, 10 + world.rand.nextInt(5), 2);
}
}
}

View file

@ -1,147 +0,0 @@
package dark.core.common.blocks;
import java.util.Random;
import dark.core.common.CoreRecipeLoader;
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.fluids.FluidStack;
import universalelectricity.prefab.ore.OreGenBase;
/** Used to generate very small pockets of fluid underground
*
* @author DarkGuardsman */
public class OreGenFluid extends OreGenBase
{
public int minGenerateLevel;
public int maxGenerateLevel;
public int amountPerChunk;
public int amountPerBranch;
public int replaceID;
public FluidStack stack;
/** Dimensions to ignore ore generation */
public boolean ignoreSurface = false;
public boolean ignoreNether = true;
public boolean ignoreEnd = true;
public OreGenFluid(String name, String oreDiectionaryName, FluidStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
{
super(name, oreDiectionaryName, new ItemStack(CoreRecipeLoader.blockGas, 1), "", 0);
this.stack = stack;
this.minGenerateLevel = minGenerateLevel;
this.maxGenerateLevel = maxGenerateLevel;
this.amountPerChunk = amountPerChunk;
this.amountPerBranch = amountPerBranch;
this.replaceID = replaceID;
}
@Override
public void generate(World world, Random random, int varX, int varZ)
{
try
{
for (int i = 0; i < this.amountPerChunk; i++)
{
int x = varX + random.nextInt(16);
int z = varZ + 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.name);
e.printStackTrace();
}
}
public boolean generateReplace(World world, Random random, int par3, int par4, int par5)
{
float var6 = random.nextFloat() * (float) Math.PI;
double var7 = par3 + 8 + MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
double var9 = par3 + 8 - MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
double var11 = par5 + 8 + MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
double var13 = par5 + 8 - MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
double var15 = par4 + random.nextInt(3) - 2;
double var17 = par4 + random.nextInt(3) - 2;
for (int oreCount = 0; oreCount <= this.amountPerBranch; ++oreCount)
{
double var20 = var7 + (var9 - var7) * oreCount / this.amountPerBranch;
double var22 = var15 + (var17 - var15) * oreCount / this.amountPerBranch;
double var24 = var11 + (var13 - var11) * oreCount / this.amountPerBranch;
double var26 = random.nextDouble() * this.amountPerBranch / 16.0D;
double var28 = (MathHelper.sin(oreCount * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (MathHelper.sin(oreCount * (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 blockid = world.getBlockId(x, y, z);
Block block = Block.blocksList[blockid];
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (block == null || block.isAirBlock(world, x, y, z) || block.canBeReplacedByLeaves(world, x, y, z) || blockid == this.replaceID))
{
System.out.println("Generated a gas at " + x + "x " + y + "y " + z + "z ");
BlockGasOre.placeAndCreate(world, x, y, z, stack);
}
}
}
}
}
}
}
return true;
}
@Override
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

@ -3,8 +3,6 @@ package dark.core.prefab.fluids;
import com.builtbroken.common.science.ChemElement;
import com.builtbroken.common.science.ChemicalCompound;
import dark.core.common.blocks.OreGenFluid;
/** Enum of gases used to create all the gas fluids
*
* @author DarkGuardsman */
@ -29,8 +27,6 @@ public enum EnumGas
/** Local instance of the gas used when the getGas method is called */
private Gas gas;
public OreGenFluid gen;
private EnumGas(String name, boolean enabled)
{
this.fluidName = name.replace(" ", "").toLowerCase();