Worked a bit on gas block

This commit is contained in:
Robert 2013-11-10 15:17:58 -05:00
parent 2a89c258f8
commit e51ef7686d
6 changed files with 332 additions and 22 deletions

View file

@ -11,6 +11,7 @@ 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;
@ -31,16 +32,19 @@ import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import dark.api.reciepes.MachineRecipeHandler;
import dark.core.common.blocks.BlockBasalt;
import dark.core.common.blocks.BlockColorGlass;
import dark.core.common.blocks.BlockColorGlowGlass;
import dark.core.common.blocks.BlockColorSand;
import dark.core.common.blocks.BlockGasOre;
import dark.core.common.blocks.BlockOre;
import dark.core.common.blocks.BlockOre.OreData;
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;
@ -62,6 +66,7 @@ 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.machine.TileEntityNBTContainer;
import dark.core.prefab.vehicles.EntityDrivable;
import dark.core.prefab.vehicles.ItemVehicleSpawn;
import dark.core.registration.ModObjectRegistry;
@ -142,6 +147,10 @@ public class DarkMain extends ModPrefab
gas.getGas().setBlockID(CoreRecipeLoader.blockGas);
}
}
if (CoreRecipeLoader.blockGas != null)
{
OreGenerator.addOre(new OreGenFluid("METHANE", "GasMETHANE", new FluidStack(EnumGas.NATURAL_GAS.getGas(), 1000), 1, 3, 50, 10, 8));
}
if (CoreRecipeLoader.blockOre != null)
{
for (OreData data : OreData.values())
@ -245,6 +254,8 @@ public class DarkMain extends ModPrefab
/* CONFIGS */
CONFIGURATION.load();
GameRegistry.registerTileEntity(TileEntityNBTContainer.class, "DMNBTSaveBlock");
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
DarkMain.zeroAnimation = CONFIGURATION.get("Graphics", "DisableAllAnimation", false, "Disables active animations by any non-active models").getBoolean(false);
@ -266,6 +277,11 @@ public class DarkMain extends ModPrefab
CoreRecipeLoader.blockBasalt = ModObjectRegistry.createNewBlock("DMBlockBasalt", DarkMain.MOD_ID, BlockBasalt.class, ItemBlockColored.class);
CoreRecipeLoader.blockGlowGlass = ModObjectRegistry.createNewBlock("DMBlockGlowGlass", DarkMain.MOD_ID, BlockColorGlowGlass.class, ItemBlockColored.class);
CoreRecipeLoader.blockSolar = ModObjectRegistry.createNewBlock("DMBlockSolar", DarkMain.MOD_ID, BlockSolarPanel.class, ItemBlockHolder.class);
Block block = ModObjectRegistry.createNewBlock("DMBlockGas", DarkMain.MOD_ID, BlockGasOre.class, ItemBlockHolder.class);
if (block instanceof BlockGasOre)
{
CoreRecipeLoader.blockDebug = block;
}
/* ITEMS */
CoreRecipeLoader.itemTool = ModObjectRegistry.createNewItem("DMReadoutTools", DarkMain.MOD_ID, ItemReadoutTools.class, true);

View file

@ -1,19 +1,28 @@
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 java.util.List;
import java.util.Set;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent;
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;
import universalelectricity.prefab.block.BlockTile;
import com.builtbroken.common.Pair;
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.fluids.EnumGas;
/** Gas that is designed to generate underground in the same way as an ore
*
@ -21,24 +30,39 @@ import net.minecraftforge.fluids.FluidStack;
* volume
*
* @author DarkGuardsman */
public class BlockGasOre extends BlockTile implements IGasBlock
public class BlockGasOre extends BlockTile implements IGasBlock, IExtraBlockInfo
{
public BlockGasOre()
{
super(DarkMain.CONFIGURATION.getBlock("GasBlock", DarkMain.getNextID()).getInt(), Material.air);
this.setUnlocalizedName("DMBlockGas");
this.setCreativeTab(DMCreativeTab.tabIndustrial);
}
public void placeAndCreate(World world, int x, int y, int z, FluidStack stack)
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
world.setBlock(x, y, z, this.blockID, 0, 2);
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityNBTContainer)
if (entity instanceof TileEntityGasBlock)
{
((TileEntityNBTContainer) entity).getSaveData().setCompoundTag("Fluid", stack.writeToNBT(new NBTTagCompound()));
FluidStack fluid = ((TileEntityGasBlock) entity).getFluidStack();
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Gas Stack: " + (fluid != null ? fluid.getFluid().getName() : "null")));
}
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);
}
}
world.markBlockForUpdate(x, y, z);
}
/* IFluidBlock */
@ -46,9 +70,9 @@ public class BlockGasOre extends BlockTile implements IGasBlock
public FluidStack drain(World world, int x, int y, int z, boolean doDrain)
{
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileEntityNBTContainer)
if (entity instanceof TileEntityGasBlock)
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(((TileEntityNBTContainer) entity).getSaveData().getCompoundTag("Fluid"));
FluidStack fluid = ((TileEntityGasBlock) entity).getFluidStack();
if (doDrain || fluid == null)
{
world.setBlockToAir(x, y, z);
@ -73,13 +97,47 @@ public class BlockGasOre extends BlockTile implements IGasBlock
@Override
public Fluid getFluid()
{
return null;
return EnumGas.NATURAL_GAS.getGas();
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityNBTContainer();
return new TileEntityGasBlock();
}
@Override
public boolean hasExtraConfigs()
{
return false;
}
@Override
public void loadExtraConfigs(Configuration config)
{
//TODO add configs for spread rate,and update rate
}
@Override
public void loadOreNames()
{
// TODO Auto-generated method stub
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
list.add(new Pair<String, Class<? extends TileEntity>>("DMTileGas", TileEntityGasBlock.class));
}
@Override
public void getClientTileEntityRenderers(List<Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>> list)
{
// TODO Auto-generated method stub
}
}

View file

@ -0,0 +1,146 @@
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 par2Random, int par3, int par4, int par5)
{
float var6 = par2Random.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 + par2Random.nextInt(3) - 2;
double var17 = par4 + par2Random.nextInt(3) - 2;
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
{
double var20 = var7 + (var9 - var7) * var19 / this.amountPerBranch;
double var22 = var15 + (var17 - var15) * var19 / this.amountPerBranch;
double var24 = var11 + (var13 - var11) * var19 / this.amountPerBranch;
double var26 = par2Random.nextDouble() * this.amountPerBranch / 16.0D;
double var28 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D;
double var30 = (MathHelper.sin(var19 * (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))
{
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

@ -0,0 +1,78 @@
package dark.core.common.blocks;
import java.io.IOException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.Player;
import dark.core.common.DarkMain;
import dark.core.network.ISimplePacketReceiver;
import dark.core.network.PacketHandler;
public class TileEntityGasBlock extends TileEntity implements ISimplePacketReceiver
{
private FluidStack stack = null;
public FluidStack getFluidStack()
{
return stack;
}
public void setStack(FluidStack stack)
{
this.stack = stack;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.stack = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid"));
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setCompoundTag("fluid", this.getFluidStack().writeToNBT(new NBTTagCompound()));
}
@Override
public boolean canUpdate()
{
return false;
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
{
try
{
if (id.equalsIgnoreCase("Desc"))
{
this.stack = FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(data));
return true;
}
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}
@Override
public Packet getDescriptionPacket()
{
if (this.stack != null)
{
return PacketHandler.instance().getPacket(DarkMain.CHANNEL, this, "Desc", this.stack.writeToNBT(new NBTTagCompound()));
}
return null;
}
}

View file

@ -3,14 +3,16 @@ 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 */
public enum EnumGas
{
C2O("Carbon DiOxide", false),
O2(ChemElement.Oxygen, 2f, true),
C4H10(ChemicalCompound.BUTANE, true),
CarbonDiOxide("Carbon DiOxide", false),
Oxygen(ChemElement.Oxygen, 2f, true),
BUTANE(ChemicalCompound.BUTANE, true),
METHANE(ChemicalCompound.METHANE, true),
NATURAL_GAS("Natural Gas", false),
PROPANE("Propane", false);
@ -27,6 +29,8 @@ 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();
@ -61,6 +65,14 @@ public enum EnumGas
{
gas.setDensity((int) ((ChemElement) data).density * 1000);
}
else if (data instanceof ChemicalCompound)
{
gas.setDensity((int) ((ChemicalCompound) data).density * 1000);
}
else
{
gas.setDensity(-1000);
}
}
return gas;
}

View file

@ -24,14 +24,14 @@ public class TileEntityNBTContainer extends TileEntity
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
nbt.setCompoundTag("saveData", this.getSaveData());
this.saveData = nbt.getCompoundTag("saveData");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
this.saveData = nbt.getCompoundTag("saveData");
nbt.setCompoundTag("saveData", this.getSaveData());
}
@Override