Snowman performance change

This commit is contained in:
fullwall 2023-01-27 01:54:13 +08:00
parent 126d4f9519
commit e828782be6
14 changed files with 21 additions and 156 deletions

View File

@ -13,12 +13,14 @@ import org.bukkit.entity.FishHook;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowman;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustByBlockEvent;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
@ -211,6 +213,16 @@ public class EventListen implements Listener {
checkCreationEvent(event);
}
@EventHandler
public void onEntityBlockForm(EntityBlockFormEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
if (npc == null)
return;
if (npc.getEntity() instanceof Snowman) {
event.setCancelled(true);
}
}
/*
* Entity events
*/

View File

@ -123,6 +123,7 @@ import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.MirrorTrait;
import net.citizensnpcs.trait.MountTrait;
import net.citizensnpcs.trait.OcelotModifiers;
import net.citizensnpcs.trait.PacketNPC;
import net.citizensnpcs.trait.Poses;
import net.citizensnpcs.trait.Powered;
import net.citizensnpcs.trait.RabbitType;
@ -638,9 +639,9 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name])",
usage = "create [name] ((-b(aby),u(nspawned),s(ilent),t(emporary),c(enter),p(acket)) --at [x:y:z:world] --type [type] --item (item) --trait ['trait1, trait2...'] --nameplate [true|false|hover] --temporaryticks [ticks] --registry [registry name])",
desc = "Create a new NPC",
flags = "bustc",
flags = "bustpc",
modifiers = { "create" },
min = 2,
permission = "citizens.npc.create")
@ -729,6 +730,10 @@ public class NPCCommands {
npc.getOrAddTrait(MobType.class).setType(type);
if (args.hasFlag('p')) {
npc.addTrait(PacketNPC.class);
}
Location spawnLoc = null;
if (sender instanceof Player) {
spawnLoc = args.getSenderLocation();

View File

@ -279,8 +279,8 @@ public class Text extends Trait implements Runnable, Listener {
sendText(player);
int delay = this.delay == -1
? Util.getFastRandom().nextInt(Setting.DEFAULT_TEXT_DELAY_MIN.asInt(),
Setting.DEFAULT_TEXT_DELAY_MAX.asInt())
? Setting.DEFAULT_TEXT_DELAY_MIN.asInt() + Util.getFastRandom()
.nextInt(Setting.DEFAULT_TEXT_DELAY_MAX.asInt() - Setting.DEFAULT_TEXT_DELAY_MIN.asInt())
: this.delay;
if (delay <= 0)
return;

View File

@ -174,18 +174,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void n() {
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
if (npc != null) {
this.world.getGameRules().set("mobGriefing", "false");
}
super.n();
if (npc != null) {
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing));
}
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {

View File

@ -174,18 +174,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void n() {
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
if (npc != null) {
this.world.getGameRules().set("mobGriefing", "false");
}
super.n();
if (npc != null) {
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing));
}
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {

View File

@ -177,18 +177,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void n() {
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
if (npc != null) {
this.world.getGameRules().set("mobGriefing", "false");
}
super.n();
if (npc != null) {
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing));
}
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.nms.v1_13_R2.entity;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
@ -15,7 +13,6 @@ import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.nms.v1_13_R2.util.NMSImpl;
import net.citizensnpcs.npc.CitizensNPC;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.DamageSource;
@ -189,27 +186,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void movementTick() {
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
if (npc != null) {
this.world.getGameRules().set("mobGriefing", "false", this.world.getMinecraftServer());
}
try {
super.movementTick();
} catch (NoSuchMethodError ex) {
try {
MOVEMENT_TICK.invoke(this);
} catch (Throwable ex2) {
ex2.printStackTrace();
}
}
if (npc != null) {
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing),
this.world.getMinecraftServer());
}
}
@Override
protected boolean n(Entity entity) {
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {
@ -235,8 +211,6 @@ public class SnowmanController extends MobEntityController {
return false;
}
}
private static final Method MOVEMENT_TICK = NMS.getMethod(EntitySnowman.class, "k", false);
}
public static class SnowmanNPC extends CraftSnowman implements NPCHolder {

View File

@ -22,7 +22,6 @@ import net.minecraft.server.v1_14_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_14_R1.EntitySnowman;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.FluidType;
import net.minecraft.server.v1_14_R1.GameRules;
import net.minecraft.server.v1_14_R1.IBlockData;
import net.minecraft.server.v1_14_R1.NBTTagCompound;
import net.minecraft.server.v1_14_R1.SoundEffect;
@ -195,18 +194,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void movementTick() {
boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false");
}
super.movementTick();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing));
}
}
@Override
protected boolean n(Entity entity) {
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {

View File

@ -23,7 +23,6 @@ import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntitySnowman;
import net.minecraft.server.v1_15_R1.EntityTypes;
import net.minecraft.server.v1_15_R1.FluidType;
import net.minecraft.server.v1_15_R1.GameRules;
import net.minecraft.server.v1_15_R1.IBlockData;
import net.minecraft.server.v1_15_R1.NBTTagCompound;
import net.minecraft.server.v1_15_R1.SoundEffect;
@ -198,18 +197,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void movementTick() {
boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false");
}
super.movementTick();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing));
}
}
@Override
protected boolean n(Entity entity) {
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {

View File

@ -23,7 +23,6 @@ import net.minecraft.server.v1_16_R3.EntityMinecartAbstract;
import net.minecraft.server.v1_16_R3.EntitySnowman;
import net.minecraft.server.v1_16_R3.EntityTypes;
import net.minecraft.server.v1_16_R3.FluidType;
import net.minecraft.server.v1_16_R3.GameRules;
import net.minecraft.server.v1_16_R3.IBlockData;
import net.minecraft.server.v1_16_R3.NBTTagCompound;
import net.minecraft.server.v1_16_R3.SoundEffect;
@ -198,18 +197,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void movementTick() {
boolean allowsGriefing = this.world.getGameRules().get(GameRules.MOB_GRIEFING).a();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue("false");
}
super.movementTick();
if (npc != null) {
this.world.getGameRules().get(GameRules.MOB_GRIEFING).setValue(Boolean.toString(allowsGriefing));
}
}
@Override
protected boolean n(Entity entity) {
if (npc != null && (entity instanceof EntityBoat || entity instanceof EntityMinecartAbstract)) {

View File

@ -24,7 +24,6 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
@ -52,18 +51,6 @@ public class SnowmanController extends MobEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void aiStep() {
boolean allowsGriefing = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
if (npc != null) {
this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(false, getServer());
}
super.aiStep();
if (npc != null) {
this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(allowsGriefing, getServer());
}
}
@Override
protected boolean canRide(Entity entity) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {

View File

@ -25,7 +25,6 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
@ -53,18 +52,6 @@ public class SnowmanController extends MobEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void aiStep() {
boolean allowsGriefing = this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
if (npc != null) {
this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(false, getServer());
}
super.aiStep();
if (npc != null) {
this.level.getGameRules().getRule(GameRules.RULE_MOBGRIEFING).set(allowsGriefing, getServer());
}
}
@Override
protected boolean canRide(Entity entity) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.nms.v1_19_R2.entity;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftSnowman;
@ -54,18 +53,6 @@ public class SnowmanController extends MobEntityController {
this.npc = (CitizensNPC) npc;
}
@Override
public void aiStep() {
boolean allowsGriefing = this.level.getWorld().getGameRuleValue(GameRule.MOB_GRIEFING);
if (npc != null) {
this.level.getWorld().setGameRule(GameRule.MOB_GRIEFING, false);
}
super.aiStep();
if (npc != null) {
this.level.getWorld().setGameRule(GameRule.MOB_GRIEFING, allowsGriefing);
}
}
@Override
protected boolean canRide(Entity entity) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {

View File

@ -168,18 +168,6 @@ public class SnowmanController extends MobEntityController {
}
}
@Override
public void m() {
boolean allowsGriefing = this.world.getGameRules().getBoolean("mobGriefing");
if (npc != null) {
this.world.getGameRules().set("mobGriefing", "false");
}
super.m();
if (npc != null) {
this.world.getGameRules().set("mobGriefing", Boolean.toString(allowsGriefing));
}
}
@Override
public void setSize(float f, float f1) {
if (npc == null) {