Skip to content

Commit

Permalink
Bug fixes found in MP
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Sep 13, 2024
1 parent 38e7376 commit 87a6b7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public AreaAffectingData getAreaAffectingData() {
return areaAffectingData;
}

public void changeSettings(int targetExp, boolean ownerOnly, boolean collectExp) {
public void changeSettings(Player player, int targetExp, boolean ownerOnly, boolean collectExp) {
if (this.ownerOnly && !player.getUUID().equals(placedByUUID)) return;
this.targetExp = targetExp;
this.ownerOnly = ownerOnly;
this.collectExp = collectExp;
Expand All @@ -87,6 +88,7 @@ public int subExp(int subtraction) {
}

public void storeExp(Player player, int levelChange) {
if (ownerOnly && !player.getUUID().equals(placedByUUID)) return;
if (levelChange == -1) {
// Move all experience from player
int totalExp = ExperienceUtils.getPlayerTotalExperience(player);
Expand Down Expand Up @@ -123,6 +125,7 @@ public void storeExp(Player player, int levelChange) {

public void extractExp(Player player, int levelChange) {
if (exp == 0) return; // No experience in the block, exit early
if (ownerOnly && !player.getUUID().equals(placedByUUID)) return;

if (levelChange == -1) {
// Move all experience from block to player
Expand Down Expand Up @@ -194,12 +197,12 @@ private void handleExperience() {
if (currentPlayer == null) return;

int currentLevel = currentPlayer.experienceLevel;
if (currentLevel < targetExp) {
if (currentLevel < targetExp && exp > 0) {
extractExp(currentPlayer, 1);
doParticles(new ItemStack(Items.EXPERIENCE_BOTTLE), currentPlayer.getEyePosition().subtract(0, 0.25f, 0), false);
if (exp == 0)
currentPlayer = null; //Clear current target if we run out of exp
} else if (currentLevel > targetExp || currentPlayer.experienceProgress > 0.01f) {
} else if (currentLevel > targetExp || (currentLevel == targetExp && currentPlayer.experienceProgress > 0.01f)) {
storeExp(currentPlayer, 1);
doParticles(new ItemStack(Items.EXPERIENCE_BOTTLE), currentPlayer.getEyePosition().subtract(0, 0.25f, 0), true);
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void handle(final ExperienceHolderSettingsPayload payload, final IPayload
AbstractContainerMenu container = sender.containerMenu;

if (container instanceof ExperienceHolderContainer experienceHolderContainer && experienceHolderContainer.baseMachineBE instanceof ExperienceHolderBE experienceHolderBE) {
experienceHolderBE.changeSettings(payload.targetExp(), payload.ownerOnly(), payload.collectExp());
experienceHolderBE.changeSettings(sender, payload.targetExp(), payload.ownerOnly(), payload.collectExp());
}
});
}
Expand Down

0 comments on commit 87a6b7c

Please sign in to comment.