Deprecated IUseItemFirst, and made onUseItemFirst work in Creative.

This commit is contained in:
Eloraam 2011-12-21 06:34:57 +00:00
parent b91eb1ceac
commit 6e1442e8e6
6 changed files with 74 additions and 43 deletions

View file

@ -14,6 +14,9 @@ import net.minecraft.src.World;
* This interface is to be implemented by item classes. It will allow an item * This interface is to be implemented by item classes. It will allow an item
* to perform a use before the block is activated. * to perform a use before the block is activated.
* *
* @deprecated This interface is no longer used, the function has been moved to
* Item. The functionality remains, it simply does not require this interface
* any further.
* @see Item * @see Item
*/ */
public interface IUseItemFirst { public interface IUseItemFirst {

View file

@ -18,7 +18,22 @@
protected Item(int i) protected Item(int i)
{ {
maxStackSize = 64; maxStackSize = 64;
@@ -231,6 +235,13 @@ @@ -221,6 +225,14 @@
return getIconFromDamage(itemstack.getItemDamage());
}
+ /* FORGE: This is called when the item is used, before the block is
+ * activated. Return true to prevent any further processing.
+ */
+ public boolean onItemUseFirst(ItemStack ist, EntityPlayer player,
+ World world, int i, int j, int k, int l) {
+ return false;
+ }
+
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
{
return false;
@@ -231,6 +243,13 @@
return 1.0F; return 1.0F;
} }
@ -32,7 +47,7 @@
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{ {
return itemstack; return itemstack;
@@ -278,6 +289,29 @@ @@ -278,6 +297,29 @@
return maxDamage > 0 && !hasSubtypes; return maxDamage > 0 && !hasSubtypes;
} }
@ -62,7 +77,7 @@
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{ {
return false; return false;
@@ -473,6 +507,18 @@ @@ -473,6 +515,18 @@
{ {
return 0; return 0;
} }

View file

@ -1,16 +1,15 @@
--- ../src_base/minecraft/net/minecraft/src/PlayerControllerMP.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/PlayerControllerMP.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/PlayerControllerMP.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/PlayerControllerMP.java 0000-00-00 00:00:00.000000000 -0000
@@ -4,6 +4,9 @@ @@ -4,6 +4,8 @@
package net.minecraft.src; package net.minecraft.src;
+import net.minecraft.src.forge.IUseItemFirst;
+import net.minecraft.src.forge.ForgeHooks; +import net.minecraft.src.forge.ForgeHooks;
+ +
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
// Referenced classes of package net.minecraft.src: // Referenced classes of package net.minecraft.src:
@@ -68,13 +71,19 @@ @@ -68,13 +70,19 @@
public boolean onPlayerDestroyBlock(int i, int j, int k, int l) public boolean onPlayerDestroyBlock(int i, int j, int k, int l)
{ {
@ -31,7 +30,7 @@
if(itemstack != null) if(itemstack != null)
{ {
itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer); itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer);
@@ -103,7 +112,7 @@ @@ -103,7 +111,7 @@
{ {
Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer); Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer);
} }
@ -40,7 +39,7 @@
{ {
onPlayerDestroyBlock(i, j, k, l); onPlayerDestroyBlock(i, j, k, l);
} else } else
@@ -149,7 +158,7 @@ @@ -149,7 +157,7 @@
return; return;
} }
Block block = Block.blocksList[i1]; Block block = Block.blocksList[i1];
@ -49,21 +48,21 @@
if(stepSoundTickCounter % 4F == 0.0F && block != null) if(stepSoundTickCounter % 4F == 0.0F && block != null)
{ {
mc.sndManager.playSound(block.stepSound.stepSoundDir2(), (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F, (block.stepSound.getVolume() + 1.0F) / 8F, block.stepSound.getPitch() * 0.5F); mc.sndManager.playSound(block.stepSound.stepSoundDir2(), (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F, (block.stepSound.getVolume() + 1.0F) / 8F, block.stepSound.getPitch() * 0.5F);
@@ -216,6 +225,13 @@ @@ -216,6 +224,13 @@
{ {
syncCurrentPlayItem(); syncCurrentPlayItem();
netClientHandler.addToSendQueue(new Packet15Place(i, j, k, l, entityplayer.inventory.getCurrentItem())); netClientHandler.addToSendQueue(new Packet15Place(i, j, k, l, entityplayer.inventory.getCurrentItem()));
+ +
+ if (itemstack != null && itemstack.getItem() instanceof IUseItemFirst) { + if (itemstack != null) {
+ IUseItemFirst iuif = (IUseItemFirst) itemstack.getItem(); + Item it=itemstack.getItem();
+ if (iuif.onItemUseFirst(itemstack, entityplayer, world, i, j, k, l)) { + if (it.onItemUseFirst(itemstack, entityplayer, world, i, j, k, l)) {
+ return true; + return true;
+ } + }
+ } + }
int i1 = world.getBlockId(i, j, k); int i1 = world.getBlockId(i, j, k);
if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer)) if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer))
{ {
@@ -235,7 +251,11 @@ @@ -235,7 +250,11 @@
return flag; return flag;
} else } else
{ {

View file

@ -1,15 +1,14 @@
--- ../src_base/minecraft/net/minecraft/src/PlayerControllerSP.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft/net/minecraft/src/PlayerControllerSP.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/PlayerControllerSP.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft/net/minecraft/src/PlayerControllerSP.java 0000-00-00 00:00:00.000000000 -0000
@@ -3,6 +3,8 @@ @@ -3,6 +3,7 @@
// Decompiler options: packimports(3) braces deadcode fieldsfirst // Decompiler options: packimports(3) braces deadcode fieldsfirst
package net.minecraft.src; package net.minecraft.src;
+import net.minecraft.src.forge.IUseItemFirst;
+import net.minecraft.src.forge.ForgeHooks; +import net.minecraft.src.forge.ForgeHooks;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -46,11 +48,17 @@ @@ -46,11 +47,17 @@
public boolean onPlayerDestroyBlock(int i, int j, int k, int l) public boolean onPlayerDestroyBlock(int i, int j, int k, int l)
{ {
@ -29,7 +28,7 @@
if(itemstack != null) if(itemstack != null)
{ {
itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer); itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer);
@@ -79,7 +87,7 @@ @@ -79,7 +86,7 @@
{ {
Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer); Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer);
} }
@ -38,7 +37,7 @@
{ {
onPlayerDestroyBlock(i, j, k, l); onPlayerDestroyBlock(i, j, k, l);
} }
@@ -110,7 +118,7 @@ @@ -110,7 +117,7 @@
return; return;
} }
Block block = Block.blocksList[i1]; Block block = Block.blocksList[i1];
@ -47,20 +46,20 @@
if(blockDestroySoundCounter % 4F == 0.0F && block != null) if(blockDestroySoundCounter % 4F == 0.0F && block != null)
{ {
mc.sndManager.playSound(block.stepSound.stepSoundDir2(), (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F, (block.stepSound.getVolume() + 1.0F) / 8F, block.stepSound.getPitch() * 0.5F); mc.sndManager.playSound(block.stepSound.stepSoundDir2(), (float)i + 0.5F, (float)j + 0.5F, (float)k + 0.5F, (block.stepSound.getVolume() + 1.0F) / 8F, block.stepSound.getPitch() * 0.5F);
@@ -173,6 +181,12 @@ @@ -173,6 +180,12 @@
public boolean onPlayerRightClick(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l) public boolean onPlayerRightClick(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l)
{ {
+ if (itemstack != null && itemstack.getItem() instanceof IUseItemFirst) { + if (itemstack != null) {
+ IUseItemFirst iuif = (IUseItemFirst) itemstack.getItem(); + Item it=itemstack.getItem();
+ if (iuif.onItemUseFirst(itemstack, entityplayer, world, i, j, k, l)) { + if (it.onItemUseFirst(itemstack, entityplayer, world, i, j, k, l)) {
+ return true; + return true;
+ } + }
+ } + }
int i1 = world.getBlockId(i, j, k); int i1 = world.getBlockId(i, j, k);
if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer)) if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer))
{ {
@@ -183,7 +197,11 @@ @@ -183,7 +196,11 @@
return false; return false;
} else } else
{ {

View file

@ -18,7 +18,22 @@
protected Item(int i) protected Item(int i)
{ {
maxStackSize = 64; maxStackSize = 64;
@@ -219,6 +223,13 @@ @@ -209,6 +213,14 @@
return this;
}
+ /* FORGE: This is called when the item is used, before the block is
+ * activated. Return true to prevent any further processing.
+ */
+ public boolean onItemUseFirst(ItemStack ist, EntityPlayer player,
+ World world, int i, int j, int k, int l) {
+ return false;
+ }
+
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
{
return false;
@@ -219,6 +231,13 @@
return 1.0F; return 1.0F;
} }
@ -32,7 +47,7 @@
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{ {
return itemstack; return itemstack;
@@ -266,6 +277,29 @@ @@ -266,6 +285,29 @@
return maxDamage > 0 && !hasSubtypes; return maxDamage > 0 && !hasSubtypes;
} }
@ -62,7 +77,7 @@
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{ {
return false; return false;
@@ -414,6 +448,12 @@ @@ -414,6 +456,12 @@
return 0; return 0;
} }

View file

@ -1,16 +1,15 @@
--- ../src_base/minecraft_server/net/minecraft/src/ItemInWorldManager.java 0000-00-00 00:00:00.000000000 -0000 --- ../src_base/minecraft_server/net/minecraft/src/ItemInWorldManager.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft_server/net/minecraft/src/ItemInWorldManager.java 0000-00-00 00:00:00.000000000 -0000 +++ ../src_work/minecraft_server/net/minecraft/src/ItemInWorldManager.java 0000-00-00 00:00:00.000000000 -0000
@@ -3,7 +3,8 @@ @@ -3,7 +3,7 @@
// Decompiler options: packimports(3) braces deadcode fieldsfirst // Decompiler options: packimports(3) braces deadcode fieldsfirst
package net.minecraft.src; package net.minecraft.src;
- -
+import net.minecraft.src.forge.ForgeHooks; +import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.IUseItemFirst;
// Referenced classes of package net.minecraft.src: // Referenced classes of package net.minecraft.src:
// EntityPlayer, PlayerCapabilities, World, Block, // EntityPlayer, PlayerCapabilities, World, Block,
@@ -81,7 +82,8 @@ @@ -81,7 +81,8 @@
if(j != 0) if(j != 0)
{ {
Block block = Block.blocksList[j]; Block block = Block.blocksList[j];
@ -20,7 +19,7 @@
if(f >= 1.0F) if(f >= 1.0F)
{ {
field_22050_k = false; field_22050_k = false;
@@ -108,7 +110,7 @@ @@ -108,7 +109,7 @@
{ {
Block.blocksList[i1].onBlockClicked(thisWorld, i, j, k, thisPlayer); Block.blocksList[i1].onBlockClicked(thisWorld, i, j, k, thisPlayer);
} }
@ -29,7 +28,7 @@
{ {
blockHarvessted(i, j, k); blockHarvessted(i, j, k);
} else } else
@@ -128,7 +130,7 @@ @@ -128,7 +129,7 @@
if(i1 != 0) if(i1 != 0)
{ {
Block block = Block.blocksList[i1]; Block block = Block.blocksList[i1];
@ -38,7 +37,7 @@
if(f >= 0.7F) if(f >= 0.7F)
{ {
blockHarvessted(i, j, k); blockHarvessted(i, j, k);
@@ -150,16 +152,19 @@ @@ -150,16 +151,19 @@
{ {
Block block = Block.blocksList[thisWorld.getBlockId(i, j, k)]; Block block = Block.blocksList[thisWorld.getBlockId(i, j, k)];
int l = thisWorld.getBlockMetadata(i, j, k); int l = thisWorld.getBlockMetadata(i, j, k);
@ -63,7 +62,7 @@
int l = thisWorld.getBlockId(i, j, k); int l = thisWorld.getBlockId(i, j, k);
int i1 = thisWorld.getBlockMetadata(i, j, k); int i1 = thisWorld.getBlockMetadata(i, j, k);
thisWorld.playAuxSFXAtEntity(thisPlayer, 2001, i, j, k, l + thisWorld.getBlockMetadata(i, j, k) * 256); thisWorld.playAuxSFXAtEntity(thisPlayer, 2001, i, j, k, l + thisWorld.getBlockMetadata(i, j, k) * 256);
@@ -169,8 +174,7 @@ @@ -169,8 +173,7 @@
((EntityPlayerMP)thisPlayer).playerNetServerHandler.sendPacket(new Packet53BlockChange(i, j, k, thisWorld)); ((EntityPlayerMP)thisPlayer).playerNetServerHandler.sendPacket(new Packet53BlockChange(i, j, k, thisWorld));
} else } else
{ {
@ -73,7 +72,7 @@
if(itemstack != null) if(itemstack != null)
{ {
itemstack.onDestroyBlock(l, i, j, k, thisPlayer); itemstack.onDestroyBlock(l, i, j, k, thisPlayer);
@@ -204,6 +208,7 @@ @@ -204,6 +207,7 @@
if(itemstack1.stackSize == 0) if(itemstack1.stackSize == 0)
{ {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null;
@ -81,14 +80,15 @@
} }
return true; return true;
} else } else
@@ -214,6 +219,11 @@ @@ -214,6 +218,12 @@
public boolean activeBlockOrUseItem(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l) public boolean activeBlockOrUseItem(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l)
{ {
+ if(itemstack!=null && itemstack.getItem() instanceof IUseItemFirst) { + if (itemstack != null) {
+ IUseItemFirst iuif=(IUseItemFirst)itemstack.getItem(); + Item it=itemstack.getItem();
+ if(iuif.onItemUseFirst(itemstack,entityplayer,world,i,j,k,l)) + if (it.onItemUseFirst(itemstack, entityplayer, world, i, j, k, l)) {
+ return true; + return true;
+ }
+ } + }
int i1 = world.getBlockId(i, j, k); int i1 = world.getBlockId(i, j, k);
if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer)) if(i1 > 0 && Block.blocksList[i1].blockActivated(world, i, j, k, entityplayer))