Skip to content

Commit

Permalink
Implement a less CPU-intensive method of clearing advancement progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 9, 2018
1 parent 3fafa7a commit 8054667
Showing 1 changed file with 4 additions and 13 deletions.
@@ -1,7 +1,6 @@
package net.citizensnpcs.nms.v1_12_R1.entity;

import java.io.IOException;
import java.lang.reflect.Field;
import java.net.Socket;
import java.util.List;
import java.util.Map;
Expand All @@ -17,6 +16,7 @@
import org.bukkit.util.Vector;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.mojang.authlib.GameProfile;

Expand Down Expand Up @@ -46,6 +46,7 @@
import net.minecraft.server.v1_12_R1.AttributeInstance;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.ChatComponentText;
import net.minecraft.server.v1_12_R1.Criterion;
import net.minecraft.server.v1_12_R1.DamageSource;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityHuman;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void B_() {
return;
if (this.getAdvancementData().data != null) {
for (AdvancementProgress progress : this.getAdvancementData().data.values()) {
clearProgress(progress);
progress.a(EMPTY_PROGRESS_MAP, EMPTY_PROGRESS);
}
}
this.noclip = isSpectator();
Expand Down Expand Up @@ -158,16 +159,6 @@ public void B_() {
npc.update();
}

private void clearProgress(AdvancementProgress progress) {
try {
PROGRESS_TRACKER_FIELD.set(progress, EMPTY_PROGRESS);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

@Override
public void collide(net.minecraft.server.v1_12_R1.Entity entity) {
// this method is called by both the entities involved - cancelling
Expand Down Expand Up @@ -543,7 +534,7 @@ public void setSkinPersistent(String skinName, String signature, String data) {
}

private static final String[][] EMPTY_PROGRESS = new String[0][0];
private static final Map<String, Criterion> EMPTY_PROGRESS_MAP = ImmutableMap.of();
private static final float EPSILON = 0.005F;
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
private static final Field PROGRESS_TRACKER_FIELD = NMS.getField(AdvancementProgress.class, "b");
}

0 comments on commit 8054667

Please sign in to comment.