Added ItemStack sensitive burn time hook.

This commit is contained in:
LexManos 2012-04-10 01:04:00 -07:00
parent 0abb4e289a
commit 57b277c9d7
5 changed files with 81 additions and 8 deletions

View file

@ -323,6 +323,20 @@ public class ForgeHooks
} }
static LinkedList<ISaveEventHandler> saveHandlers = new LinkedList<ISaveEventHandler>(); static LinkedList<ISaveEventHandler> saveHandlers = new LinkedList<ISaveEventHandler>();
public static int getItemBurnTime(ItemStack stack)
{
for (IFuelHandler handler : fuelHandlers)
{
int ret = handler.getItemBurnTime(stack);
if (ret > 0)
{
return ret;
}
}
return 0;
}
static LinkedList<IFuelHandler> fuelHandlers = new LinkedList<IFuelHandler>();
// Plant Management // Plant Management
// ------------------------------------------------------------ // ------------------------------------------------------------
static class ProbableItem static class ProbableItem

View file

@ -0,0 +1,16 @@
/**
* This software is provided under the terms of the Minecraft Forge Public
* License v1.0.
*/
package net.minecraft.src.forge;
import net.minecraft.src.ItemStack;
public interface IFuelHandler
{
/** Called when a furnace gains fuel to get its burn time.
* @return fuel burn time in ticks or 0 to continue processing
*/
public int getItemBurnTime(ItemStack stack);
}

View file

@ -138,6 +138,15 @@ public class MinecraftForge
ForgeHooks.saveHandlers.add(handler); ForgeHooks.saveHandlers.add(handler);
} }
/**
* Register a new Fuel handler
* @param handler The handler to be registered
*/
public static void registerFuelHandler(IFuelHandler handler)
{
ForgeHooks.fuelHandlers.add(handler);
}
/** /**
* This is not supposed to be called outside of Minecraft internals. * This is not supposed to be called outside of Minecraft internals.
*/ */

View file

@ -1,16 +1,17 @@
--- ../src_base/minecraft/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,6 +1,8 @@ @@ -1,6 +1,9 @@
package net.minecraft.src; package net.minecraft.src;
-public class TileEntityFurnace extends TileEntity implements IInventory -public class TileEntityFurnace extends TileEntity implements IInventory
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.ISidedInventory; +import net.minecraft.src.forge.ISidedInventory;
+ +
+public class TileEntityFurnace extends TileEntity implements IInventory, ISidedInventory +public class TileEntityFurnace extends TileEntity implements IInventory, ISidedInventory
{ {
/** /**
* The ItemStacks that hold the items currently being used in the furnace * The ItemStacks that hold the items currently being used in the furnace
@@ -279,8 +281,12 @@ @@ -279,8 +282,12 @@
} }
else else
{ {
@ -25,7 +26,7 @@
} }
} }
@@ -291,13 +297,13 @@ @@ -291,13 +298,13 @@
{ {
if (this.canSmelt()) if (this.canSmelt())
{ {
@ -41,7 +42,23 @@
{ {
this.furnaceItemStacks[2].stackSize += var1.stackSize; this.furnaceItemStacks[2].stackSize += var1.stackSize;
} }
@@ -351,4 +357,18 @@ @@ -331,7 +338,14 @@
else
{
int var1 = par1ItemStack.getItem().shiftedIndex;
- return var1 < 256 && Block.blocksList[var1].blockMaterial == Material.wood ? 300 : (var1 == Item.stick.shiftedIndex ? 100 : (var1 == Item.coal.shiftedIndex ? 1600 : (var1 == Item.bucketLava.shiftedIndex ? 20000 : (var1 == Block.sapling.blockID ? 100 : (var1 == Item.blazeRod.shiftedIndex ? 2400 : ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage()))))));
+ if (var1 < 256 && Block.blocksList[var1].blockMaterial == Material.wood) return 300;
+ if (var1 == Item.stick.shiftedIndex) return 100;
+ if (var1 == Item.coal.shiftedIndex) return 1600;
+ if (var1 == Item.bucketLava.shiftedIndex) return 20000;
+ if (var1 == Block.sapling.blockID) return 100;
+ if (var1 == Item.blazeRod.shiftedIndex) return 2400;
+ int ret = ForgeHooks.getItemBurnTime(par1ItemStack);
+ return (ret > 0 ? ret : ModLoader.addAllFuel(par1ItemStack.itemID, par1ItemStack.getItemDamage()));
}
}
@@ -351,4 +365,18 @@
public void openChest() {} public void openChest() {}
public void closeChest() {} public void closeChest() {}

View file

@ -1,17 +1,18 @@
--- ../src_base/minecraft_server/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft_server/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/TileEntityFurnace.java 0000-00-00 00:00:00.000000000 -0000
@@ -2,7 +2,9 @@ @@ -2,7 +2,10 @@
import cpw.mods.fml.server.FMLServerHandler; import cpw.mods.fml.server.FMLServerHandler;
-public class TileEntityFurnace extends TileEntity implements IInventory -public class TileEntityFurnace extends TileEntity implements IInventory
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.ISidedInventory; +import net.minecraft.src.forge.ISidedInventory;
+ +
+public class TileEntityFurnace extends TileEntity implements IInventory, ISidedInventory +public class TileEntityFurnace extends TileEntity implements IInventory, ISidedInventory
{ {
/** /**
* The ItemStacks that hold the items currently being used in the furnace * The ItemStacks that hold the items currently being used in the furnace
@@ -251,8 +253,12 @@ @@ -251,8 +254,12 @@
} }
else else
{ {
@ -26,7 +27,7 @@
} }
} }
@@ -263,13 +269,13 @@ @@ -263,13 +270,13 @@
{ {
if (this.canSmelt()) if (this.canSmelt())
{ {
@ -42,7 +43,23 @@
{ {
++this.furnaceItemStacks[2].stackSize; ++this.furnaceItemStacks[2].stackSize;
} }
@@ -316,4 +322,18 @@ @@ -296,7 +303,14 @@
else
{
int var1 = par1ItemStack.getItem().shiftedIndex;
- return var1 < 256 && Block.blocksList[var1].blockMaterial == Material.wood ? 300 : (var1 == Item.stick.shiftedIndex ? 100 : (var1 == Item.coal.shiftedIndex ? 1600 : (var1 == Item.bucketLava.shiftedIndex ? 20000 : (var1 == Block.sapling.blockID ? 100 : (var1 == Item.blazeRod.shiftedIndex ? 2400 : FMLServerHandler.instance().fuelLookup(var1, par1ItemStack.getItemDamage()))))));
+ if (var1 < 256 && Block.blocksList[var1].blockMaterial == Material.wood) return 300;
+ if (var1 == Item.stick.shiftedIndex) return 100;
+ if (var1 == Item.coal.shiftedIndex) return 1600;
+ if (var1 == Item.bucketLava.shiftedIndex) return 20000;
+ if (var1 == Block.sapling.blockID) return 100;
+ if (var1 == Item.blazeRod.shiftedIndex) return 2400;
+ int ret = ForgeHooks.getItemBurnTime(par1ItemStack);
+ return (ret > 0 ? ret : FMLServerHandler.instance().fuelLookup(var1, par1ItemStack.getItemDamage()));
}
}
@@ -316,4 +330,18 @@
public void openChest() {} public void openChest() {}
public void closeChest() {} public void closeChest() {}