Added Oil Springs

Spawns an infinite Oil Spring at bedrock under 25% of large Oil Wells.
This Spring slowly produced more oil over time.

More balance testing needed, but I need to fix that damn Redstone Engine
bug first.
This commit is contained in:
CovertJaguar 2013-05-01 13:31:18 -07:00
parent b185cf7954
commit c61daa06a5
7 changed files with 164 additions and 60 deletions

View file

@ -94,4 +94,6 @@ tile.engineWood=Redstone Engine
tile.engineStone=Stirling Engine
tile.engineIron=Combustion Engine
tile.oilStill=Oil
tile.spring.water=Water Spring
tile.spring.oil=Oil Spring
tile.oilMoving=Oil

View file

@ -39,6 +39,7 @@ import buildcraft.core.EntityEnergyLaser;
import buildcraft.core.EntityPowerLaser;
import buildcraft.core.EntityRobot;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.ItemSpring;
import buildcraft.core.ItemWrench;
import buildcraft.core.RedstonePowerFramework;
import buildcraft.core.SpringPopulate;
@ -90,7 +91,7 @@ public class BuildCraftCore {
public static RenderMode render = RenderMode.Full;
public static boolean debugMode = false;
public static boolean debugMode = true;
public static boolean modifyWorld = false;
public static boolean trackNetworkUsage = false;
@ -242,7 +243,7 @@ public class BuildCraftCore {
if(BuildCraftCore.modifyWorld) {
springBlock = new BlockSpring(springId.getInt()).setUnlocalizedName("eternalSpring");
CoreProxy.proxy.registerBlock(springBlock);
CoreProxy.proxy.registerBlock(springBlock, ItemSpring.class);
}
woodenGearItem = (new ItemBuildCraft(woodenGearId.getInt())).setUnlocalizedName("woodenGearItem");

View file

@ -28,6 +28,7 @@ import buildcraft.api.fuels.IronEngineCoolant;
import buildcraft.api.fuels.IronEngineFuel;
import buildcraft.api.recipes.RefineryRecipe;
import buildcraft.core.BlockIndex;
import buildcraft.core.BlockSpring;
import buildcraft.core.DefaultProps;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.Version;
@ -117,7 +118,7 @@ public class BuildCraftEnergy {
BuildCraftCore.mainConfiguration.save();
engineBlock = new BlockEngine(engineId.getInt(DefaultProps.ENGINE_ID));
GameRegistry.registerBlock(engineBlock, ItemEngine.class);
CoreProxy.proxy.registerBlock(engineBlock, ItemEngine.class);
LanguageRegistry.addName(new ItemStack(engineBlock, 1, 0), "Redstone Engine");
LanguageRegistry.addName(new ItemStack(engineBlock, 1, 1), "Steam Engine");
@ -126,6 +127,7 @@ public class BuildCraftEnergy {
oilStill = (new BlockOilStill(oilStillId.getInt(DefaultProps.OIL_STILL_ID), Material.water)).setUnlocalizedName("oil");
CoreProxy.proxy.addName(oilStill.setUnlocalizedName("oilStill"), "Oil");
CoreProxy.proxy.registerBlock(oilStill);
BlockSpring.EnumSpring.OIL.liquidBlockId = oilStill.blockID;
oilMoving = (new BlockOilFlowing(oilMovingId.getInt(DefaultProps.OIL_MOVING_ID), Material.water)).setUnlocalizedName("oil");
CoreProxy.proxy.addName(oilMoving.setUnlocalizedName("oilMoving"), "Oil");

View file

@ -8,9 +8,36 @@ import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
public class BlockSpring extends Block {
public static final Random rand = new Random();
public enum EnumSpring {
WATER(5, -1, Block.waterStill.blockID),
OIL(6000, 8, 0); // Set in BuildCraftEnergy
public static final EnumSpring[] VALUES = values();
public final int tickRate, chance;
public int liquidBlockId;
private EnumSpring(int tickRate, int chance, int liquidBlockId) {
this.tickRate = tickRate;
this.chance = chance;
this.liquidBlockId = liquidBlockId;
}
public static EnumSpring fromMeta(int meta) {
if (meta < 0 || meta >= VALUES.length) {
return WATER;
}
return VALUES[meta];
}
}
public BlockSpring(int id) {
super(id, Material.rock);
setBlockUnbreakable();
@ -21,28 +48,50 @@ public class BlockSpring extends Block {
setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
}
@Override
public void getSubBlocks(int id, CreativeTabs tab, List list) {
for (EnumSpring type : EnumSpring.VALUES) {
list.add(new ItemStack(this, 1, type.ordinal()));
}
}
@Override
public int damageDropped(int meta) {
return meta;
}
@Override
public void updateTick(World world, int x, int y, int z, Random random) {
assertSpring(world, x, y, z);
}
// @Override
// public void onNeighborBlockChange(World world, int x, int y, int z, int blockid) {
// assertSpring(world, x, y, z);
// }
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockid) {
assertSpring(world, x, y, z);
public void onBlockAdded(World world, int x, int y, int z) {
super.onBlockAdded(world, x, y, z);
int meta = world.getBlockMetadata(x, y, z);
world.scheduleBlockUpdate(x, y, z, blockID, EnumSpring.fromMeta(meta).tickRate);
}
private void assertSpring(World world, int x, int y, int z) {
if(!world.isAirBlock(x, y + 1, z))
int meta = world.getBlockMetadata(x, y, z);
EnumSpring spring = EnumSpring.fromMeta(meta);
world.scheduleBlockUpdate(x, y, z, blockID, spring.tickRate);
if (!world.isAirBlock(x, y + 1, z)) {
return;
world.setBlock(x, y + 1, z, Block.waterStill.blockID);
}
if (spring.chance != -1 && rand.nextInt(spring.chance) != 0) {
return;
}
world.setBlock(x, y + 1, z, spring.liquidBlockId);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
blockIcon = par1IconRegister.registerIcon("water");
public void registerIcons(IconRegister par1IconRegister) {
blockIcon = par1IconRegister.registerIcon("bedrock");
}
}

View file

@ -0,0 +1,26 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core;
import net.minecraft.item.ItemStack;
public class ItemSpring extends ItemBlockBuildCraft {
public ItemSpring(int i) {
super(i);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return "tile.spring."+ BlockSpring.EnumSpring.fromMeta(stack.getItemDamage()).name().toLowerCase();
}
}

View file

@ -33,6 +33,7 @@ import buildcraft.core.network.BuildCraftPacket;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.ItemBlock;
public class CoreProxy {
@ -98,7 +99,11 @@ public class CoreProxy {
/* REGISTRATION */
public void registerBlock(Block block) {
GameRegistry.registerBlock(block, ItemBlockBuildCraft.class, block.getUnlocalizedName().replace("tile.", ""));
registerBlock(block, ItemBlockBuildCraft.class);
}
public void registerBlock(Block block, Class<? extends ItemBlock> item) {
GameRegistry.registerBlock(block, item, block.getUnlocalizedName().replace("tile.", ""));
}
public void registerItem(Item item) {

View file

@ -17,9 +17,18 @@ import net.minecraftforge.event.terraingen.PopulateChunkEvent;
import net.minecraftforge.event.terraingen.TerrainGen;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.core.BlockSpring;
import java.util.HashSet;
import java.util.Set;
public class OilPopulate {
public static final Set<Integer> surfaceDepositBiomes = new HashSet<Integer>();
static {
surfaceDepositBiomes.add(BiomeGenBase.desert.biomeID);
}
@ForgeSubscribe
public void populate(PopulateChunkEvent.Post event) {
@ -37,14 +46,14 @@ public class OilPopulate {
}
public static void doPopulate(World world, Random rand, int x, int z) {
BiomeGenBase biomegenbase = world.getBiomeGenForCoords(x + 16, z + 16);
BiomeGenBase biome = world.getBiomeGenForCoords(x + 16, z + 16);
// Do not generate oil in the End
if (biomegenbase.biomeID == BiomeGenBase.sky.biomeID || biomegenbase.biomeID == BiomeGenBase.hell.biomeID) {
if (biome.biomeID == BiomeGenBase.sky.biomeID || biome.biomeID == BiomeGenBase.hell.biomeID) {
return;
}
if (biomegenbase == BiomeGenBase.desert && rand.nextFloat() > 0.97) {
if (surfaceDepositBiomes.contains(biome.biomeID) && rand.nextFloat() > 0.97) {
// Generate a small desert deposit
int startX = rand.nextInt(10) + 2;
@ -54,13 +63,11 @@ public class OilPopulate {
int i = startX + x;
int k = startZ + z;
if (world.getBlockId(i, j, k) != 0) {
if (world.getBlockId(i, j, k) == Block.sand.blockID) {
generateSurfaceDeposit(world, rand, i, j, k, 3);
}
break;
int blockId = world.getBlockId(i, j, k);
if (blockId != 0 && blockId == Block.sand.blockID) {
generateSurfaceDeposit(world, rand, i, j, k, 3);
}
break;
}
}
@ -74,25 +81,32 @@ public class OilPopulate {
if (mediumDeposit || largeDeposit) {
// Generate a large cave deposit
int cx = x, cy = 20 + rand.nextInt(10), cz = z;
int r = 0;
if (largeDeposit) {
r = 8 + rand.nextInt(9);
} else if (mediumDeposit) {
r = 4 + rand.nextInt(4);
int baseX = x, baseZ = z;
int wellY = 20 + rand.nextInt(10);
int baseY;
if (largeDeposit && (BuildCraftCore.debugMode || rand.nextDouble() <= 0.25)) {
baseY = 0;
} else {
baseY = wellY;
}
int r2 = r * r;
int radius = 0;
for (int bx = -r; bx <= r; bx++) {
for (int by = -r; by <= r; by++) {
for (int bz = -r; bz <= r; bz++) {
int d2 = bx * bx + by * by + bz * bz;
if (largeDeposit) {
radius = 8 + rand.nextInt(9);
} else if (mediumDeposit) {
radius = 4 + rand.nextInt(4);
}
if (d2 <= r2) {
world.setBlock(bx + cx, by + cy, bz + cz, BuildCraftEnergy.oilStill.blockID);
int radiusSq = radius * radius;
for (int poolX = -radius; poolX <= radius; poolX++) {
for (int poolY = -radius; poolY <= radius; poolY++) {
for (int poolZ = -radius; poolZ <= radius; poolZ++) {
int distance = poolX * poolX + poolY * poolY + poolZ * poolZ;
if (distance <= radiusSq) {
world.setBlock(poolX + baseX, poolY + wellY, poolZ + baseZ, BuildCraftEnergy.oilStill.blockID);
}
}
}
@ -100,35 +114,40 @@ public class OilPopulate {
boolean started = false;
for (int y = 128; y >= cy; --y) {
if (!started && world.getBlockId(cx, y, cz) != 0 && world.getBlockId(cx, y, cz) != Block.leaves.blockID
&& world.getBlockId(cx, y, cz) != Block.wood.blockID && world.getBlockId(cx, y, cz) != Block.grass.blockID) {
started = true;
if (largeDeposit) {
generateSurfaceDeposit(world, rand, cx, y, cz, 20 + rand.nextInt(20));
} else if (mediumDeposit) {
generateSurfaceDeposit(world, rand, cx, y, cz, 5 + rand.nextInt(5));
for (int y = 128; y >= baseY; --y) {
if (started) {
int blockId = world.getBlockId(baseX, y, baseZ);
if (blockId == Block.bedrock.blockID) {
world.setBlock(baseX, y, baseZ, BuildCraftCore.springBlock.blockID, 1, 2);
break;
}
world.setBlock(baseX, y, baseZ, BuildCraftEnergy.oilStill.blockID);
} else {
int blockId = world.getBlockId(baseX, y, baseZ);
if (blockId != 0 && blockId != Block.leaves.blockID && blockId != Block.wood.blockID && blockId != Block.grass.blockID) {
started = true;
int ymax = 0;
if (largeDeposit) {
generateSurfaceDeposit(world, rand, baseX, y, baseZ, 20 + rand.nextInt(20));
} else if (mediumDeposit) {
generateSurfaceDeposit(world, rand, baseX, y, baseZ, 5 + rand.nextInt(5));
}
int ymax = 0;
if (largeDeposit) {
ymax = (y + 30 < 128 ? y + 30 : 128);
} else if (mediumDeposit) {
ymax = (y + 4 < 128 ? y + 4 : 128);
}
for (int h = y + 1; h <= ymax; ++h) {
world.setBlock(baseX, h, baseZ, BuildCraftEnergy.oilStill.blockID);
}
if (largeDeposit) {
ymax = (y + 30 < 128 ? y + 30 : 128);
} else if (mediumDeposit) {
ymax = (y + 4 < 128 ? y + 4 : 128);
}
for (int h = y + 1; h <= ymax; ++h) {
world.setBlock(cx, h, cz, BuildCraftEnergy.oilStill.blockID);
}
} else if (started) {
world.setBlock(cx, y, cz, BuildCraftEnergy.oilStill.blockID);
}
}
}
}