Started work on heat based machines

I was going to just work on and release the coal gen as a self contained
generator. Instead i'm going to make it a 2+ part system. The system
must contain a heat produce, and heat collector. It can also include
block to help contain, move, and maintain the heat.
This commit is contained in:
DarkGuardsman 2013-10-02 00:58:55 -04:00
parent 51f71fd0ad
commit 09952ce675
4 changed files with 228 additions and 58 deletions

View file

@ -0,0 +1,28 @@
package dark.api.energy;
import java.util.HashMap;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import com.builtbroken.common.Pair;
/** Information about block not provided by minecraft such as density, mass, volume, tempature, etc
* etc
*
* @author DarkGuardsman */
public class ExtraBlockData
{
HashMap<Pair<Integer, Integer>, HeatEnergyData> blockTempature = new HashMap();
public static double getTempature(World world, Vector3 vec)
{
return 0;
}
public static class HeatEnergyData
{
public float maxTempature;
public float defaultTempature;
}
}

View file

@ -0,0 +1,156 @@
package dark.core.common.machines;
import java.util.List;
import java.util.Set;
import com.builtbroken.common.Pair;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.Configuration;
import dark.core.common.CommonProxy;
import dark.core.common.DarkMain;
import dark.core.prefab.machine.BlockMachine;
import dark.core.registration.ModObjectRegistry.BlockBuildData;
public class BlockHeater extends BlockMachine
{
public BlockHeater(BlockBuildData data)
{
super(data);
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (world.getBlockMetadata(x, y, z) % 4 < 3)
{
world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) + 1, 3);
return true;
}
else
{
world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 3, 3);
return true;
}
}
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
for (HeatMachineData data : HeatMachineData.values())
{
list.add(new Pair<String, Class<? extends TileEntity>>("DC" + data.unlocalizedName, data.clazz));
}
}
@Override
public void loadExtraConfigs(Configuration config)
{
super.loadExtraConfigs(config);
}
/** Called when the block is right clicked by the player */
@Override
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!par1World.isRemote)
{
par5EntityPlayer.openGui(DarkMain.getInstance(), HeatMachineData.values()[par1World.getBlockMetadata(x, y, z) / 4].guiID, par1World, x, y, z);
}
return true;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public TileEntity createTileEntity(World world, int metadata)
{
try
{
return HeatMachineData.values()[metadata / 4].clazz.newInstance();
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
@Override
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
{
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 8));
par3List.add(new ItemStack(par1, 1, 12));
}
@Override
public int damageDropped(int metadata)
{
return metadata / 4;
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{
int id = idPicked(world, x, y, z);
if (id == 0)
{
return null;
}
Item item = Item.itemsList[id];
if (item == null)
{
return null;
}
int metadata = getDamageValue(world, x, y, z);
return new ItemStack(id, 1, metadata);
}
public static enum HeatMachineData
{
HEAT_COUPLE("themalcouple", 0, CommonProxy.GUI_COAL_GEN, TileEntityCoalGenerator.class),
HEAT_EXCHANGE("heatexchanger", 4, CommonProxy.GUI_FUEL_GEN, TileEntityCoalGenerator.class),
HEAT_PLATE("heatplate", 8, CommonProxy.GUI_BATTERY_BOX, TileEntityBatteryBox.class);
public String unlocalizedName;
public int startMeta, guiID;
public boolean enabled = true;
public boolean allowCrafting = true;
public Class<? extends TileEntity> clazz;
private HeatMachineData(String name, int meta, int guiID, Class<? extends TileEntity> clazz)
{
this.unlocalizedName = name;
this.startMeta = meta;
this.guiID = guiID;
this.clazz = clazz;
}
}
}

View file

@ -9,6 +9,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
@ -23,80 +24,63 @@ import dark.core.prefab.machine.TileEntityEnergyMachine;
public class TileEntityCoalGenerator extends TileEntityEnergyMachine public class TileEntityCoalGenerator extends TileEntityEnergyMachine
{ {
/** Maximum amount of energy needed to generate electricity */ /** Maximum amount of energy needed to generate electricity */
public static final float MAX_GENERATE_WATTS = 0.5f; public static float MAX_GENERATE_WATTS = 0.5f;
/** Amount of heat the coal generator needs before generating electricity. */ /** Amount of heat the coal generator needs before generating electricity. */
public static final float MIN_GENERATE_WATTS = MAX_GENERATE_WATTS * 0.1f; public static final float MIN_GENERATE_WATTS = MAX_GENERATE_WATTS * 0.1f;
private static final float BASE_ACCELERATION = 0.000001f; private static float BASE_ACCELERATION = 0.000001f;
private static float BASE_DECCELERATION = 0.008f;
/** Per second */ /** Per second */
public float prevGenerateWatts, generateWatts = 0; public float generateWatts = 0;
/** The number of ticks that a fresh copy of the currently-burning item would keep the furnace /** The number of ticks that a fresh copy of the currently-burning item would keep the furnace
* burning for */ * burning for */
public int itemCookTime = 0; public int itemCookTime = 0;
public final Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
@Override @Override
public void updateEntity() public void updateEntity()
{ {
this.setEnergyStored(this.generateWatts);
super.updateEntity(); super.updateEntity();
if (!this.worldObj.isRemote) if (!this.worldObj.isRemote)
{ {
this.prevGenerateWatts = this.generateWatts; //Consume item if cook time is too low
if (this.getInventory().getStackInSlot(0) != null && this.itemCookTime <= 10)
if (this.itemCookTime > 0)
{ {
this.itemCookTime--; if (TileEntityFurnace.isItemFuel(this.getInventory().getStackInSlot(0)))
if (this.getEnergyStored() < this.getMaxEnergyStored())
{ {
this.generateWatts = Math.min(this.generateWatts + Math.min((this.generateWatts * 0.007F + BASE_ACCELERATION), 0.007F), TileEntityCoalGenerator.MAX_GENERATE_WATTS); this.itemCookTime += TileEntityFurnace.getItemBurnTime(this.getInventory().getStackInSlot(0));
this.decrStackSize(0, 1);
} }
} }
if (this.getInventory().getStackInSlot(0) != null && this.getEnergyStored() < this.getMaxEnergyStored()) //Update item cook time & power output
if (this.itemCookTime-- > 0)
{ {
if (this.getInventory().getStackInSlot(0).getItem().itemID == Item.coal.itemID) this.generateWatts = Math.min(this.generateWatts + Math.min((this.generateWatts * 0.007F + BASE_ACCELERATION), 0.007F), TileEntityCoalGenerator.MAX_GENERATE_WATTS);
{
if (this.itemCookTime <= 0)
{
this.itemCookTime = 320;
this.decrStackSize(0, 1);
}
}
} }
//Decrease generator output if nothing is burning
if (this.itemCookTime <= 0) if (this.itemCookTime <= 0)
{ {
this.generateWatts = Math.max(this.generateWatts - 0.008F, 0); this.generateWatts = Math.max(this.generateWatts - BASE_DECCELERATION, 0);
} }
if (this.ticks % 3 == 0) if(this.generateWatts >= MIN_GENERATE_WATTS)
{ {
for (EntityPlayer player : this.playersUsing) this.produceAllSides();
{
PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), (Player) player);
}
}
if (this.prevGenerateWatts <= 0 && this.generateWatts > 0 || this.prevGenerateWatts > 0 && this.generateWatts <= 0)
{
PacketHandler.instance().sendPacketToClients(getDescriptionPacket(), this.worldObj);
} }
} }
} }
/** Does this tile have power to run and do work */
@Override @Override
public Packet getDescriptionPacket() public boolean canFunction()
{ {
return PacketHandler.instance().getPacket(this.getChannel(), this, "gen", this.generateWatts, this.itemCookTime); return !this.isDisabled() && this.generateWatts > 0;
} }
@Override @Override
@ -121,13 +105,12 @@ public class TileEntityCoalGenerator extends TileEntityEnergyMachine
} }
@Override @Override
public void openChest() public void sendGUIPacket(EntityPlayer entity)
{
}
@Override
public void closeChest()
{ {
if (entity != null)
{
PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getPacket(this.getChannel(), this, "gen", this.generateWatts, this.itemCookTime), (Player) entity);
}
} }
/** Reads a tile entity from NBT. */ /** Reads a tile entity from NBT. */
@ -155,27 +138,19 @@ public class TileEntityCoalGenerator extends TileEntityEnergyMachine
} }
@Override @Override
public boolean isItemValidForSlot(int slotID, ItemStack itemstack) public boolean canStore(ItemStack stack, int slot, ForgeDirection side)
{ {
return itemstack.itemID == Item.coal.itemID; return TileEntityFurnace.isItemFuel(stack);
} }
@Override @Override
public int[] getAccessibleSlotsFromSide(int var1) public boolean canRemove(ItemStack stack, int slot, ForgeDirection side)
{ {
return new int[] { 0 }; if (slot >= this.getSizeInventory())
} {
return false;
@Override }
public boolean canInsertItem(int slotID, ItemStack itemstack, int j) return true;
{
return this.isItemValidForSlot(slotID, itemstack);
}
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int j)
{
return slotID == 0;
} }
@Override @Override

View file

@ -0,0 +1,11 @@
package dark.core.common.machines;
import dark.core.prefab.machine.TileEntityEnergyMachine;
/** Machine that turns heat into usable electrical energy
*
* @author DarkGuardsman */
public class TileEntityHeatCouple extends TileEntityEnergyMachine
{
}