diff --git a/src/dark/api/energy/ExtraBlockData.java b/src/dark/api/energy/ExtraBlockData.java new file mode 100644 index 00000000..70d78673 --- /dev/null +++ b/src/dark/api/energy/ExtraBlockData.java @@ -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, HeatEnergyData> blockTempature = new HashMap(); + + public static double getTempature(World world, Vector3 vec) + { + return 0; + } + + public static class HeatEnergyData + { + public float maxTempature; + public float defaultTempature; + } +} diff --git a/src/dark/core/common/machines/BlockHeater.java b/src/dark/core/common/machines/BlockHeater.java new file mode 100644 index 00000000..59e98d91 --- /dev/null +++ b/src/dark/core/common/machines/BlockHeater.java @@ -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>> list) + { + for (HeatMachineData data : HeatMachineData.values()) + { + list.add(new Pair>("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 clazz; + + private HeatMachineData(String name, int meta, int guiID, Class clazz) + { + this.unlocalizedName = name; + this.startMeta = meta; + this.guiID = guiID; + this.clazz = clazz; + } + } +} diff --git a/src/dark/core/common/machines/TileEntityCoalGenerator.java b/src/dark/core/common/machines/TileEntityCoalGenerator.java index e0495eed..d37b0cd1 100644 --- a/src/dark/core/common/machines/TileEntityCoalGenerator.java +++ b/src/dark/core/common/machines/TileEntityCoalGenerator.java @@ -9,6 +9,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; +import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.electricity.ElectricityPack; @@ -23,80 +24,63 @@ import dark.core.prefab.machine.TileEntityEnergyMachine; public class TileEntityCoalGenerator extends TileEntityEnergyMachine { /** 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. */ 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 */ - 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 * burning for */ public int itemCookTime = 0; - public final Set playersUsing = new HashSet(); - @Override public void updateEntity() { - this.setEnergyStored(this.generateWatts); - super.updateEntity(); if (!this.worldObj.isRemote) { - this.prevGenerateWatts = this.generateWatts; - - if (this.itemCookTime > 0) + //Consume item if cook time is too low + if (this.getInventory().getStackInSlot(0) != null && this.itemCookTime <= 10) { - this.itemCookTime--; - - if (this.getEnergyStored() < this.getMaxEnergyStored()) + if (TileEntityFurnace.isItemFuel(this.getInventory().getStackInSlot(0))) { - 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) - { - if (this.itemCookTime <= 0) - { - this.itemCookTime = 320; - this.decrStackSize(0, 1); - } - } + this.generateWatts = Math.min(this.generateWatts + Math.min((this.generateWatts * 0.007F + BASE_ACCELERATION), 0.007F), TileEntityCoalGenerator.MAX_GENERATE_WATTS); } + //Decrease generator output if nothing is burning 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) - { - PacketDispatcher.sendPacketToPlayer(getDescriptionPacket(), (Player) player); - } - } - - if (this.prevGenerateWatts <= 0 && this.generateWatts > 0 || this.prevGenerateWatts > 0 && this.generateWatts <= 0) - { - PacketHandler.instance().sendPacketToClients(getDescriptionPacket(), this.worldObj); + this.produceAllSides(); } } } + /** Does this tile have power to run and do work */ @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 @@ -121,13 +105,12 @@ public class TileEntityCoalGenerator extends TileEntityEnergyMachine } @Override - public void openChest() - { - } - - @Override - public void closeChest() + public void sendGUIPacket(EntityPlayer entity) { + if (entity != null) + { + PacketDispatcher.sendPacketToPlayer(PacketHandler.instance().getPacket(this.getChannel(), this, "gen", this.generateWatts, this.itemCookTime), (Player) entity); + } } /** Reads a tile entity from NBT. */ @@ -155,27 +138,19 @@ public class TileEntityCoalGenerator extends TileEntityEnergyMachine } @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 - public int[] getAccessibleSlotsFromSide(int var1) + public boolean canRemove(ItemStack stack, int slot, ForgeDirection side) { - return new int[] { 0 }; - } - - @Override - public boolean canInsertItem(int slotID, ItemStack itemstack, int j) - { - return this.isItemValidForSlot(slotID, itemstack); - } - - @Override - public boolean canExtractItem(int slotID, ItemStack itemstack, int j) - { - return slotID == 0; + if (slot >= this.getSizeInventory()) + { + return false; + } + return true; } @Override diff --git a/src/dark/core/common/machines/TileEntityHeatCouple.java b/src/dark/core/common/machines/TileEntityHeatCouple.java new file mode 100644 index 00000000..9f561b3a --- /dev/null +++ b/src/dark/core/common/machines/TileEntityHeatCouple.java @@ -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 +{ + +}