Added new tool harvest intercept hook. Removed mlprop.patch.

This commit is contained in:
Eloraam 2011-12-02 04:08:15 +00:00
parent a2c606e98c
commit 9c6f5bd8ee
8 changed files with 82 additions and 90 deletions

View file

@ -1,70 +0,0 @@
diff -ru src/minecraft/net/minecraft/src/MLProp.java src_fix/minecraft/net/minecraft/src/MLProp.java
--- src/minecraft/net/minecraft/src/MLProp.java 2011-08-04 20:10:17.000000000 -0400
+++ src_fix/minecraft/net/minecraft/src/MLProp.java 2011-08-04 20:12:55.000000000 -0400
@@ -1,20 +1,11 @@
-// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
-// Jad home page: http://www.kpdus.com/jad.html
-// Decompiler options: packimports(3) braces deadcode
-
-package net.minecraft.src;
-
-import java.lang.annotation.Annotation;
-
-public interface MLProp
- extends Annotation
-{
-
- public abstract String name();
-
- public abstract String info();
-
- public abstract double min();
-
- public abstract double max();
-}
+package net.minecraft.src;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface MLProp {
+ String name() default "";
+ String info() default "";
+ double min() default Double.NEGATIVE_INFINITY;
+ double max() default Double.POSITIVE_INFINITY;
+}
diff -ru src/minecraft_server/net/minecraft/src/MLProp.java src_fix/minecraft_server/net/minecraft/src/MLProp.java
--- src/minecraft_server/net/minecraft/src/MLProp.java 2011-08-04 20:10:17.000000000 -0400
+++ src_fix/minecraft_server/net/minecraft/src/MLProp.java 2011-08-04 20:13:00.000000000 -0400
@@ -1,20 +1,11 @@
-// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
-// Jad home page: http://www.kpdus.com/jad.html
-// Decompiler options: packimports(3) braces deadcode
-
-package net.minecraft.src;
-
-import java.lang.annotation.Annotation;
-
-public interface MLProp
- extends Annotation
-{
-
- public abstract String name();
-
- public abstract String info();
-
- public abstract double min();
-
- public abstract double max();
-}
+package net.minecraft.src;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface MLProp {
+ String name() default "";
+ String info() default "";
+ double min() default Double.NEGATIVE_INFINITY;
+ double max() default Double.POSITIVE_INFINITY;
+}

View file

@ -101,7 +101,7 @@
} }
} }
@@ -805,6 +819,104 @@ @@ -805,6 +819,107 @@
return iblockaccess.isBlockNormalCube(i, j, k) ? 0.2F : 1.0F; return iblockaccess.isBlockNormalCube(i, j, k) ? 0.2F : 1.0F;
} }
@ -189,6 +189,9 @@
+ * actually destroying the block, and the block is intact at time of call. + * actually destroying the block, and the block is intact at time of call.
+ * This is called regardless of whether the player can harvest the block or + * This is called regardless of whether the player can harvest the block or
+ * not. Return true if the block is actually destroyed. + * not. Return true if the block is actually destroyed.
+ *
+ * Note: When used in multiplayer, this is called on both client and
+ * server sides!
+ */ + */
+ public boolean removeBlockByPlayer(World world, EntityPlayer player, + public boolean removeBlockByPlayer(World world, EntityPlayer player,
+ int i, int j, int k) { + int i, int j, int k) {

View file

@ -32,7 +32,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,19 @@ @@ -278,6 +289,29 @@
return maxDamage > 0 && !hasSubtypes; return maxDamage > 0 && !hasSubtypes;
} }
@ -48,6 +48,16 @@
+ canRepair=false; + canRepair=false;
+ return this; + return this;
+ } + }
+
+ /* FORGE: Called before a block is broken. Return true to prevent default
+ * block harvesting.
+ *
+ * Note: In SMP, this is called on both client and server sides!
+ */
+ public boolean onBlockStartBreak(ItemStack itemstack, int i, int j, int k,
+ EntityPlayer player) {
+ return false;
+ }
+ +
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{ {

View file

@ -10,7 +10,25 @@
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
// Referenced classes of package net.minecraft.src: // Referenced classes of package net.minecraft.src:
@@ -103,7 +106,7 @@ @@ -68,13 +71,16 @@
public boolean sendBlockRemoved(int i, int j, int k, int l)
{
+ ItemStack itemstack = mc.thePlayer.getCurrentEquippedItem();
+ if(itemstack!=null && itemstack.getItem().onBlockStartBreak(itemstack,
+ i,j,k,mc.thePlayer))
+ return false;
if(creativeMode)
{
return super.sendBlockRemoved(i, j, k, l);
}
int i1 = mc.theWorld.getBlockId(i, j, k);
boolean flag = super.sendBlockRemoved(i, j, k, l);
- ItemStack itemstack = mc.thePlayer.getCurrentEquippedItem();
if(itemstack != null)
{
itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer);
@@ -103,7 +109,7 @@
{ {
Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer); Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer);
} }
@ -19,7 +37,7 @@
{ {
sendBlockRemoved(i, j, k, l); sendBlockRemoved(i, j, k, l);
} else } else
@@ -149,7 +152,7 @@ @@ -149,7 +155,7 @@
return; return;
} }
Block block = Block.blocksList[i1]; Block block = Block.blocksList[i1];
@ -28,7 +46,7 @@
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 +219,13 @@ @@ -216,6 +222,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()));
@ -42,7 +60,7 @@
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 +245,11 @@ @@ -235,7 +248,11 @@
return flag; return flag;
} else } else
{ {

View file

@ -9,16 +9,24 @@
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@@ -50,7 +52,7 @@ @@ -46,11 +48,14 @@
public boolean sendBlockRemoved(int i, int j, int k, int l)
{
+ ItemStack itemstack = mc.thePlayer.getCurrentEquippedItem();
+ if(itemstack!=null && itemstack.getItem().onBlockStartBreak(itemstack,
+ i,j,k,mc.thePlayer))
+ return false;
int i1 = mc.theWorld.getBlockId(i, j, k);
int j1 = mc.theWorld.getBlockMetadata(i, j, k); int j1 = mc.theWorld.getBlockMetadata(i, j, k);
boolean flag = super.sendBlockRemoved(i, j, k, l); boolean flag = super.sendBlockRemoved(i, j, k, l);
ItemStack itemstack = mc.thePlayer.getCurrentEquippedItem(); - ItemStack itemstack = mc.thePlayer.getCurrentEquippedItem();
- boolean flag1 = mc.thePlayer.canHarvestBlock(Block.blocksList[i1]); - boolean flag1 = mc.thePlayer.canHarvestBlock(Block.blocksList[i1]);
+ boolean flag1 = Block.blocksList[i1].canHarvestBlock(mc.thePlayer,j1); + boolean flag1 = Block.blocksList[i1].canHarvestBlock(mc.thePlayer,j1);
if(itemstack != null) if(itemstack != null)
{ {
itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer); itemstack.onDestroyBlock(i1, i, j, k, mc.thePlayer);
@@ -79,7 +81,7 @@ @@ -79,7 +84,7 @@
{ {
Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer); Block.blocksList[i1].onBlockClicked(mc.theWorld, i, j, k, mc.thePlayer);
} }
@ -27,7 +35,7 @@
{ {
sendBlockRemoved(i, j, k, l); sendBlockRemoved(i, j, k, l);
} }
@@ -110,7 +112,7 @@ @@ -110,7 +115,7 @@
return; return;
} }
Block block = Block.blocksList[i1]; Block block = Block.blocksList[i1];
@ -36,7 +44,7 @@
if(field_1069_h % 4F == 0.0F && block != null) if(field_1069_h % 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 +175,12 @@ @@ -173,6 +178,12 @@
public boolean sendPlaceBlock(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l) public boolean sendPlaceBlock(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l)
{ {
@ -49,7 +57,7 @@
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 +191,11 @@ @@ -183,7 +194,11 @@
return false; return false;
} else } else
{ {

View file

@ -85,7 +85,7 @@
} }
} }
@@ -725,6 +737,96 @@ @@ -725,6 +737,99 @@
return blockMaterial.getMaterialMobility(); return blockMaterial.getMaterialMobility();
} }
@ -173,6 +173,9 @@
+ * actually destroying the block, and the block is intact at time of call. + * actually destroying the block, and the block is intact at time of call.
+ * This is called regardless of whether the player can harvest the block or + * This is called regardless of whether the player can harvest the block or
+ * not. Return true if the block is actually destroyed. + * not. Return true if the block is actually destroyed.
+ *
+ * Note: When used in multiplayer, this is called on both client and
+ * server sides!
+ */ + */
+ public boolean removeBlockByPlayer(World world, EntityPlayer player, + public boolean removeBlockByPlayer(World world, EntityPlayer player,
+ int i, int j, int k) { + int i, int j, int k) {

View file

@ -24,7 +24,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 +276,19 @@ @@ -266,6 +276,29 @@
return maxDamage > 0 && !hasSubtypes; return maxDamage > 0 && !hasSubtypes;
} }
@ -40,6 +40,16 @@
+ canRepair=false; + canRepair=false;
+ return this; + return this;
+ } + }
+
+ /* FORGE: Called before a block is broken. Return true to prevent default
+ * block harvesting.
+ *
+ * Note: In SMP, this is called on both client and server sides!
+ */
+ public boolean onBlockStartBreak(ItemStack itemstack, int i, int j, int k,
+ EntityPlayer player) {
+ return false;
+ }
+ +
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1) public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{ {

View file

@ -38,7 +38,7 @@
if(f >= 0.7F) if(f >= 0.7F)
{ {
blockHarvessted(i, j, k); blockHarvessted(i, j, k);
@@ -150,11 +152,10 @@ @@ -150,16 +152,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);
@ -54,16 +54,26 @@
return flag; return flag;
} }
@@ -170,7 +171,7 @@ public boolean blockHarvessted(int i, int j, int k)
{
+ ItemStack itemstack = thisPlayer.getCurrentEquippedItem();
+ if(itemstack!=null && itemstack.getItem().onBlockStartBreak(itemstack,
+ i,j,k,thisPlayer))
+ return false;
int l = thisWorld.getBlockId(i, j, k);
int i1 = thisWorld.getBlockMetadata(i, j, k);
thisWorld.playAuxSFXAtEntity(thisPlayer, 2001, i, j, k, l + thisWorld.getBlockMetadata(i, j, k) * 256);
@@ -169,8 +174,7 @@
((EntityPlayerMP)thisPlayer).playerNetServerHandler.sendPacket(new Packet53BlockChange(i, j, k, thisWorld));
} else } else
{ {
ItemStack itemstack = thisPlayer.getCurrentEquippedItem(); - ItemStack itemstack = thisPlayer.getCurrentEquippedItem();
- boolean flag1 = thisPlayer.canHarvestBlock(Block.blocksList[l]); - boolean flag1 = thisPlayer.canHarvestBlock(Block.blocksList[l]);
+ boolean flag1 = Block.blocksList[l].canHarvestBlock(thisPlayer, i1); + boolean flag1 = Block.blocksList[l].canHarvestBlock(thisPlayer, i1);
if(itemstack != null) if(itemstack != null)
{ {
itemstack.onDestroyBlock(l, i, j, k, thisPlayer); itemstack.onDestroyBlock(l, i, j, k, thisPlayer);
@@ -204,6 +205,7 @@ @@ -204,6 +208,7 @@
if(itemstack1.stackSize == 0) if(itemstack1.stackSize == 0)
{ {
entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null;
@ -71,7 +81,7 @@
} }
return true; return true;
} else } else
@@ -214,6 +216,11 @@ @@ -214,6 +219,11 @@
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)
{ {
@ -83,7 +93,7 @@
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))
{ {
@@ -233,7 +240,11 @@ @@ -233,7 +243,11 @@
return flag; return flag;
} else } else
{ {