From 6c6f664c301b3cf2b690e752e518b8092ad12b5e Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Fri, 24 Jan 2014 16:31:38 -0800 Subject: [PATCH] Implement PlayerPickupXpEvent, fired when a player aquires XP from a EntityXPOrb. Closes #942 --- .../net/minecraft/client/Minecraft.java.patch | 18 ++++++++-------- .../entity/item/EntityXPOrb.java.patch | 19 +++++++++++++++++ .../entity/player/PlayerPickupXpEvent.java | 21 +++++++++++++++++++ src/main/resources/forge_at.cfg | 4 +++- 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 patches/minecraft/net/minecraft/entity/item/EntityXPOrb.java.patch create mode 100644 src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java diff --git a/patches/minecraft/net/minecraft/client/Minecraft.java.patch b/patches/minecraft/net/minecraft/client/Minecraft.java.patch index aba313962a..b131501bf6 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.java.patch +++ b/patches/minecraft/net/minecraft/client/Minecraft.java.patch @@ -72,7 +72,7 @@ if (p_147108_1_ instanceof GuiMainMenu) { this.gameSettings.showDebugInfo = false; -@@ -1338,7 +1352,7 @@ +@@ -1337,7 +1351,7 @@ if (this.thePlayer.isCurrentToolAdventureModeExempt(i, j, k)) { @@ -81,7 +81,7 @@ this.thePlayer.swingItem(); } } -@@ -1419,11 +1433,12 @@ +@@ -1418,11 +1432,12 @@ int j = this.objectMouseOver.blockY; int k = this.objectMouseOver.blockZ; @@ -96,7 +96,7 @@ { flag = false; this.thePlayer.swingItem(); -@@ -1450,7 +1465,8 @@ +@@ -1449,7 +1464,8 @@ { ItemStack itemstack1 = this.thePlayer.inventory.getCurrentItem(); @@ -106,7 +106,7 @@ { this.entityRenderer.itemRenderer.resetEquippedProgress2(); } -@@ -1652,6 +1668,8 @@ +@@ -1651,6 +1667,8 @@ while (Mouse.next()) { @@ -115,7 +115,7 @@ i = Mouse.getEventButton(); if (isRunningOnMac && i == 0 && (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157))) -@@ -2122,6 +2140,11 @@ +@@ -2121,6 +2139,11 @@ // JAVADOC METHOD $$ func_71353_a public void loadWorld(WorldClient par1WorldClient, String par2Str) { @@ -127,7 +127,7 @@ if (par1WorldClient == null) { NetHandlerPlayClient nethandlerplayclient = this.func_147114_u(); -@@ -2134,6 +2157,18 @@ +@@ -2133,6 +2156,18 @@ if (this.theIntegratedServer != null) { this.theIntegratedServer.initiateShutdown(); @@ -146,7 +146,7 @@ } this.theIntegratedServer = null; -@@ -2289,113 +2324,10 @@ +@@ -2288,113 +2323,10 @@ if (this.objectMouseOver != null) { boolean flag = this.thePlayer.capabilities.isCreativeMode; @@ -262,7 +262,7 @@ if (flag) { j = this.thePlayer.inventoryContainer.inventorySlots.size() - 9 + this.thePlayer.inventory.currentItem; -@@ -2565,9 +2497,16 @@ +@@ -2564,9 +2496,16 @@ par1PlayerUsageSnooper.addData("gl_max_texture_size", Integer.valueOf(getGLMaximumTextureSize())); } @@ -279,7 +279,7 @@ for (int i = 16384; i > 0; i >>= 1) { GL11.glTexImage2D(GL11.GL_PROXY_TEXTURE_2D, 0, GL11.GL_RGBA, i, i, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)null); -@@ -2575,6 +2514,7 @@ +@@ -2574,6 +2513,7 @@ if (j != 0) { diff --git a/patches/minecraft/net/minecraft/entity/item/EntityXPOrb.java.patch b/patches/minecraft/net/minecraft/entity/item/EntityXPOrb.java.patch new file mode 100644 index 0000000000..07f12704ac --- /dev/null +++ b/patches/minecraft/net/minecraft/entity/item/EntityXPOrb.java.patch @@ -0,0 +1,19 @@ +--- ../src-base/minecraft/net/minecraft/entity/item/EntityXPOrb.java ++++ ../src-work/minecraft/net/minecraft/entity/item/EntityXPOrb.java +@@ -9,6 +9,8 @@ + import net.minecraft.util.DamageSource; + import net.minecraft.util.MathHelper; + import net.minecraft.world.World; ++import net.minecraftforge.common.MinecraftForge; ++import net.minecraftforge.event.entity.player.PlayerPickupXpEvent; + + public class EntityXPOrb extends Entity + { +@@ -218,6 +220,7 @@ + { + if (this.field_70532_c == 0 && par1EntityPlayer.xpCooldown == 0) + { ++ if (MinecraftForge.EVENT_BUS.post(new PlayerPickupXpEvent(par1EntityPlayer, this))) return; + par1EntityPlayer.xpCooldown = 2; + this.worldObj.playSoundAtEntity(par1EntityPlayer, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F)); + par1EntityPlayer.onItemPickup(this, 1); diff --git a/src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java b/src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java new file mode 100644 index 0000000000..9b27a80cf7 --- /dev/null +++ b/src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java @@ -0,0 +1,21 @@ +package net.minecraftforge.event.entity.player; + +import cpw.mods.fml.common.eventhandler.Cancelable; +import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; + +/** + * This event is called when a player collides with a EntityXPOrb on the ground. + * The event can be canceled, and no further processing will be done. + */ +@Cancelable +public class PlayerPickupXpEvent extends PlayerEvent +{ + public final EntityXPOrb orb; + + public PlayerPickupXpEvent(EntityPlayer player, EntityXPOrb orb) + { + super(player); + this.orb = orb; + } +} diff --git a/src/main/resources/forge_at.cfg b/src/main/resources/forge_at.cfg index 988df1dae4..5a7f8cb960 100644 --- a/src/main/resources/forge_at.cfg +++ b/src/main/resources/forge_at.cfg @@ -169,4 +169,6 @@ public net.minecraft.util.DamageSource *() #All methods public, most are already # ItemBlock public net.minecraft.item.ItemBlock field_150939_a # block # EntityAITasks -public net.minecraft.entity.ai.EntityAITasks field_75782_a # taskEntries \ No newline at end of file +public net.minecraft.entity.ai.EntityAITasks field_75782_a # taskEntries +# EntityXPOrb +public net.minecraft.entity.item.EntityXPOrb field_70530_e # xpValue \ No newline at end of file