This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Add the PlayerXpEvent events (add XP points/level, pickup XP orb) #89
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c5df81c
Add the PlayerXpEvent events (add XP points/level, pickup XP orb)
ZNixian d5f0ff4
Fix the Javadoc for PlayerXpEvent.PickupXp
ZNixian 647854a
Merge remote-tracking branch 'origin/master' into player-xp-events
ZNixian ed8c8d4
Bump patchwork-events-entity from v0.3.0 to v0.4.0
ZNixian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...ents-entity/src/main/java/net/minecraftforge/event/entity/player/PlayerPickupXpEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Minecraft Forge, Patchwork Project | ||
* Copyright (c) 2016-2020, 2019-2020 | ||
* | ||
* 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.ExperienceOrbEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
/** | ||
* Legacy version of PlayerXpEvent.PickupXp. Mods should move to PickupXp, and | ||
* this class is removed in 1.15. | ||
*/ | ||
@Deprecated | ||
public class PlayerPickupXpEvent extends PlayerXpEvent.PickupXp { | ||
public PlayerPickupXpEvent(PlayerEntity player, ExperienceOrbEntity orb) { | ||
super(player, orb); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
...ork-events-entity/src/main/java/net/minecraftforge/event/entity/player/PlayerXpEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Minecraft Forge, Patchwork Project | ||
* Copyright (c) 2016-2020, 2019-2020 | ||
* | ||
* 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.ExperienceOrbEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
public abstract class PlayerXpEvent extends PlayerEvent { | ||
public PlayerXpEvent(PlayerEntity player) { | ||
super(player); | ||
} | ||
|
||
// For legacy reasons, the instances of this class should actually be of | ||
// type PlayerPickupXpEvent | ||
public static class PickupXp extends CancelablePlayerXpEvent { | ||
private final ExperienceOrbEntity orb; | ||
|
||
public PickupXp(PlayerEntity player, ExperienceOrbEntity orb) { | ||
super(player); | ||
this.orb = orb; | ||
} | ||
|
||
public ExperienceOrbEntity getOrb() { | ||
return orb; | ||
} | ||
} | ||
|
||
public static class XpChange extends CancelablePlayerXpEvent { | ||
private int amount; | ||
|
||
public XpChange(PlayerEntity player, int amount) { | ||
super(player); | ||
this.amount = amount; | ||
} | ||
|
||
public int getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(int amount) { | ||
this.amount = amount; | ||
} | ||
} | ||
|
||
public static class LevelChange extends CancelablePlayerXpEvent { | ||
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; | ||
} | ||
} | ||
|
||
// Helper, so we don't have to repeat isCancelable all the time | ||
private static class CancelablePlayerXpEvent extends PlayerXpEvent { | ||
private CancelablePlayerXpEvent(PlayerEntity player) { | ||
super(player); | ||
} | ||
|
||
@Override | ||
public boolean isCancelable() { | ||
return true; | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...nts-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinExperienceOrbEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Minecraft Forge, Patchwork Project | ||
* Copyright (c) 2016-2020, 2019-2020 | ||
* | ||
* 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.patchworkmc.mixin.event.entity; | ||
|
||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.entity.player.PlayerPickupXpEvent; | ||
import org.objectweb.asm.Opcodes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.ExperienceOrbEntity; | ||
|
||
@Mixin(ExperienceOrbEntity.class) | ||
public class MixinExperienceOrbEntity { | ||
// After checking we're on the server and the player is ready to pick up the orb, the first | ||
// thing the target method does is set experiencePickUpDelay, hence hook just before that. | ||
@Inject(method = "onPlayerCollision", cancellable = true, at = @At(value = "FIELD", opcode = Opcodes.H_PUTFIELD, ordinal = 0, | ||
ZNixian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
target = "net/minecraft/entity/player/PlayerEntity.experiencePickUpDelay:I")) | ||
private void hookOnPlayerCollisionForPickup(PlayerEntity player, CallbackInfo ci) { | ||
@SuppressWarnings("ConstantConditions") | ||
ExperienceOrbEntity entity = (ExperienceOrbEntity) (Object) this; | ||
|
||
if (MinecraftForge.EVENT_BUS.post(new PlayerPickupXpEvent(player, entity))) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.