Re-add PlayerGiveXpEvent & PlayerChangeLevelEvent (#6165)

This commit is contained in:
FireController1847 2019-10-14 11:37:44 -06:00 committed by LexManos
parent 8248eb6ea1
commit 94cbf72e39
5 changed files with 207 additions and 14 deletions

View file

@ -425,7 +425,29 @@
}
}
@@ -1703,7 +1818,10 @@
@@ -1462,6 +1577,10 @@
}
public void func_195068_e(int p_195068_1_) {
+ net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange event = new net.minecraftforge.event.entity.player.PlayerXpEvent.XpChange(this, p_195068_1_);
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
+ p_195068_1_ = event.getAmount();
+
this.func_85039_t(p_195068_1_);
this.field_71106_cc += (float)p_195068_1_ / (float)this.func_71050_bK();
this.field_71067_cb = MathHelper.func_76125_a(this.field_71067_cb + p_195068_1_, 0, Integer.MAX_VALUE);
@@ -1501,6 +1620,10 @@
}
public void func_82242_a(int p_82242_1_) {
+ net.minecraftforge.event.entity.player.PlayerXpEvent.LevelChange event = new net.minecraftforge.event.entity.player.PlayerXpEvent.LevelChange(this, p_82242_1_);
+ if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) return;
+ p_82242_1_ = event.getLevels();
+
this.field_71068_ca += p_82242_1_;
if (this.field_71068_ca < 0) {
this.field_71068_ca = 0;
@@ -1703,7 +1826,10 @@
}
public ITextComponent func_145748_c_() {
@ -437,7 +459,7 @@
return this.func_208016_c(itextcomponent);
}
@@ -1939,4 +2057,44 @@
@@ -1939,4 +2065,44 @@
return this.field_221260_g;
}
}

View file

@ -19,27 +19,21 @@
package net.minecraftforge.event.entity.player;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraft.entity.item.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* 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.
* Use {@link PlayerXpEvent.PickupXp}
*/
@Cancelable
public class PlayerPickupXpEvent extends PlayerEvent
@Deprecated
public class PlayerPickupXpEvent extends PlayerXpEvent.PickupXp
{
private final ExperienceOrbEntity orb;
public PlayerPickupXpEvent(PlayerEntity player, ExperienceOrbEntity orb)
{
super(player);
this.orb = orb;
super(player, orb);
}
public ExperienceOrbEntity getOrb()
{
return orb;
}
}

View file

@ -0,0 +1,121 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity.player;
import net.minecraft.entity.item.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
/**
* PlayerXpEvent is fired whenever an event involving player experience occurs. <br>
* If a method utilizes this {@link net.minecraftforge.eventbus.api.Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.
*/
public class PlayerXpEvent extends PlayerEvent
{
public PlayerXpEvent(PlayerEntity player)
{
super(player);
}
/**
* This event is fired after the player collides with an experience orb, but before the player has been given the experience.
* It can be cancelled, and no further processing will be done.
*/
@Cancelable
public static class PickupXp extends PlayerXpEvent
{
private final ExperienceOrbEntity orb;
public PickupXp(PlayerEntity player, ExperienceOrbEntity orb)
{
super(player);
this.orb = orb;
}
public ExperienceOrbEntity getOrb()
{
return orb;
}
}
/**
* This event is fired when the player's experience changes through the {@link PlayerEntity#giveExperiencePoints} method.
* It can be cancelled, and no further processing will be done.
*/
@Cancelable
public static class XpChange extends PlayerXpEvent
{
private int amount;
public XpChange(PlayerEntity player, int amount)
{
super(player);
this.amount = amount;
}
public int getAmount()
{
return this.amount;
}
public void setAmount(int amount)
{
this.amount = amount;
}
}
/**
* This event is fired when the player's experience level changes through the {@link PlayerEntity#addExperienceLevel} method.
* It can be cancelled, and no further processing will be done.
*/
@Cancelable
public static class LevelChange extends PlayerXpEvent
{
private int levels;
public LevelChange(PlayerEntity player, int levels)
{
super(player);
this.levels = levels;
}
public int getLevels()
{
return this.levels;
}
public void setLevels(int levels)
{
this.levels = levels;
}
}
}

View file

@ -0,0 +1,54 @@
package net.minecraftforge.debug.entity.player;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraftforge.event.entity.player.PlayerPickupXpEvent;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod("player_xp_event_test")
@Mod.EventBusSubscriber()
public class PlayerXpEventTest
{
private static final boolean ENABLE = false;
private static Logger logger = LogManager.getLogger(PlayerXpEventTest.class);
@SubscribeEvent
public static void onPlayerXpEvent(PlayerXpEvent event)
{
if (!ENABLE) return;
logger.info("The PlayerXpEvent has been called!");
}
@SubscribeEvent
public static void onPlayerPickupXpOld(PlayerPickupXpEvent event)
{
if (!ENABLE) return;
logger.info("The deprecated PlayerPickupXpEvent has been called!");
}
@SubscribeEvent
public static void onPlayerPickupXp(PlayerXpEvent.PickupXp event)
{
if (!ENABLE) return;
logger.info("{} picked up an experience orb worth {}", event.getPlayer().getName().getString(), event.getOrb().getXpValue());
}
@SubscribeEvent
public static void onPlayerXpChange(PlayerXpEvent.XpChange event)
{
if (!ENABLE) return;
logger.info("{} has been given {} experience", event.getPlayer().getName().getString(), event.getAmount());
}
@SubscribeEvent
public static void onPlayerLevelChange(PlayerXpEvent.LevelChange event)
{
if (!ENABLE) return;
logger.info("{} has changed {} levels", event.getPlayer().getName().getString(), event.getLevels());
}
}

View file

@ -53,5 +53,7 @@ loaderVersion="[28,)"
modId="piston_event_test"
[[mods]]
modId="flower_pot_test"
[[mods]]
modId="player_xp_event_test"
[[mods]]
modId="forgeblockstatesloader"