Added new pick block hook for blocks and entites to allow for better grained control of the result.
This commit is contained in:
parent
d14b1b4e1f
commit
acdcfd0a56
4 changed files with 215 additions and 3 deletions
|
@ -221,7 +221,68 @@ public class ForgeHooks
|
|||
|
||||
public static boolean onEntityInteract(EntityPlayer entityPlayer, Entity par1Entity, boolean b)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player uses 'pick block', calls new Entity and Block hooks.
|
||||
*/
|
||||
public static boolean onPickBlock(MovingObjectPosition target, EntityPlayer player, World world)
|
||||
{
|
||||
ItemStack result = null;
|
||||
boolean isCreative = player.capabilities.isCreativeMode;
|
||||
|
||||
if (target.typeOfHit == EnumMovingObjectType.TILE)
|
||||
{
|
||||
int x = target.blockX;
|
||||
int y = target.blockY;
|
||||
int z = target.blockZ;
|
||||
Block var8 = Block.blocksList[world.getBlockId(x, y, z)];
|
||||
|
||||
if (var8 == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = var8.getPickBlock(target, world, x, y, z);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (target.typeOfHit != EnumMovingObjectType.ENTITY || target.entityHit == null || !isCreative)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = target.entityHit.getPickedResult(target);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ItemStack stack = player.inventory.getStackInSlot(x);
|
||||
if (stack != null && stack.isItemEqual(result))
|
||||
{
|
||||
player.inventory.currentItem = x;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isCreative)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int slot = player.inventory.getFirstEmptyStack();
|
||||
if (slot < 0 || slot >= 9)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents(slot, result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@
|
|||
{
|
||||
ItemStack var8 = this.createStackedBlock(par6);
|
||||
|
||||
@@ -1249,4 +1257,645 @@
|
||||
@@ -1249,4 +1257,669 @@
|
||||
canBlockGrass[0] = true;
|
||||
StatList.initBreakableStats();
|
||||
}
|
||||
|
@ -748,5 +748,29 @@
|
|||
+ public boolean canRenderInPass(int pass)
|
||||
+ {
|
||||
+ return pass == getRenderBlockPass();
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Called when a user uses the creative pick block button on this block
|
||||
+ *
|
||||
+ * @param target The full target the player is looking at
|
||||
+ * @return A ItemStack to add to the player's inventory, Null if nothing should be added.
|
||||
+ */
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ return new ItemStack(id, 1, getDamageValue(world, x, y, z));
|
||||
+ }
|
||||
}
|
||||
|
|
|
@ -67,11 +67,12 @@
|
|||
}
|
||||
|
||||
/**
|
||||
@@ -2107,4 +2128,27 @@
|
||||
@@ -2107,4 +2128,59 @@
|
||||
{
|
||||
return String.format("%s[\'%s\'/%d, l=\'%s\', x=%.2f, y=%.2f, z=%.2f]", new Object[] {this.getClass().getSimpleName(), this.getEntityName(), Integer.valueOf(this.entityId), this.worldObj == null ? "~NULL~" : this.worldObj.getWorldInfo().getWorldName(), Double.valueOf(this.posX), Double.valueOf(this.posY), Double.valueOf(this.posZ)});
|
||||
}
|
||||
+
|
||||
+ /* ================================== Forge Start =====================================*/
|
||||
+ /**
|
||||
+ * Returns a NBTTagCompound that can be used to store custom data for this entity.
|
||||
+ * It will be written, and read from disc, so it persists over world saves.
|
||||
|
@ -93,5 +94,36 @@
|
|||
+ public boolean shouldRiderSit()
|
||||
+ {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Called when a user uses the creative pick block button on this entity.
|
||||
+ *
|
||||
+ * @param target The full target the player is looking at
|
||||
+ * @return A ItemStack to add to the player's inventory, Null if nothing should be added.
|
||||
+ */
|
||||
+ public ItemStack getPickedResult(MovingObjectPosition target)
|
||||
+ {
|
||||
+ if (this instanceof EntityPainting)
|
||||
+ {
|
||||
+ return new ItemStack(Item.painting);
|
||||
+ }
|
||||
+ else if (this instanceof EntityMinecart)
|
||||
+ {
|
||||
+ return ((EntityMinecart)this).getCartItem();
|
||||
+ }
|
||||
+ else if (this instanceof EntityBoat)
|
||||
+ {
|
||||
+ return new ItemStack(Item.boat);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ int id = EntityList.getEntityID(this);
|
||||
+ if (id > 0 || EntityList.entityEggs.containsKey(id))
|
||||
+ {
|
||||
+ return new ItemStack(Item.monsterPlacer, 1, id);
|
||||
+ }
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
}
|
||||
|
|
95
patches/minecraft/net/minecraft/client/Minecraft.java.patch
Normal file
95
patches/minecraft/net/minecraft/client/Minecraft.java.patch
Normal file
|
@ -0,0 +1,95 @@
|
|||
--- ../src_base/minecraft/net/minecraft/client/Minecraft.java
|
||||
+++ ../src_work/minecraft/net/minecraft/client/Minecraft.java
|
||||
@@ -17,6 +17,7 @@
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.minecraft.src.*;
|
||||
+import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.Sys;
|
||||
@@ -2102,80 +2103,12 @@
|
||||
if (this.objectMouseOver != null)
|
||||
{
|
||||
boolean var1 = this.thePlayer.capabilities.isCreativeMode;
|
||||
- int var3 = 0;
|
||||
- boolean var4 = false;
|
||||
- int var2;
|
||||
int var5;
|
||||
|
||||
- if (this.objectMouseOver.typeOfHit == EnumMovingObjectType.TILE)
|
||||
- {
|
||||
- var5 = this.objectMouseOver.blockX;
|
||||
- int var6 = this.objectMouseOver.blockY;
|
||||
- int var7 = this.objectMouseOver.blockZ;
|
||||
- Block var8 = Block.blocksList[this.theWorld.getBlockId(var5, var6, var7)];
|
||||
-
|
||||
- if (var8 == null)
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- var2 = var8.idPicked(this.theWorld, var5, var6, var7);
|
||||
-
|
||||
- if (var2 == 0)
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- var4 = Item.itemsList[var2].getHasSubtypes();
|
||||
- int var9 = var2 >= 256 ? var8.blockID : var2;
|
||||
- var3 = Block.blocksList[var9].getDamageValue(this.theWorld, var5, var6, var7);
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
- if (this.objectMouseOver.typeOfHit != EnumMovingObjectType.ENTITY || this.objectMouseOver.entityHit == null || !var1)
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
-
|
||||
- if (this.objectMouseOver.entityHit instanceof EntityPainting)
|
||||
- {
|
||||
- var2 = Item.painting.shiftedIndex;
|
||||
- }
|
||||
- else if (this.objectMouseOver.entityHit instanceof EntityMinecart)
|
||||
- {
|
||||
- EntityMinecart var10 = (EntityMinecart)this.objectMouseOver.entityHit;
|
||||
-
|
||||
- if (var10.minecartType == 2)
|
||||
- {
|
||||
- var2 = Item.minecartPowered.shiftedIndex;
|
||||
- }
|
||||
- else if (var10.minecartType == 1)
|
||||
- {
|
||||
- var2 = Item.minecartCrate.shiftedIndex;
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
- var2 = Item.minecartEmpty.shiftedIndex;
|
||||
- }
|
||||
- }
|
||||
- else if (this.objectMouseOver.entityHit instanceof EntityBoat)
|
||||
- {
|
||||
- var2 = Item.boat.shiftedIndex;
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
- var2 = Item.monsterPlacer.shiftedIndex;
|
||||
- var3 = EntityList.getEntityID(this.objectMouseOver.entityHit);
|
||||
- var4 = true;
|
||||
-
|
||||
- if (var3 <= 0 || !EntityList.entityEggs.containsKey(Integer.valueOf(var3)))
|
||||
- {
|
||||
- return;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- this.thePlayer.inventory.setCurrentItem(var2, var3, var4, var1);
|
||||
+ if (!ForgeHooks.onPickBlock(this.objectMouseOver, this.thePlayer, this.theWorld))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
if (var1)
|
||||
{
|
Loading…
Reference in a new issue