mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-25 03:55:30 +01:00
Prevent armadillo scutes from dropping in protected npcs
This commit is contained in:
parent
5620d3373f
commit
6e27ec8920
@ -19,12 +19,17 @@ import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.animal.armadillo.Armadillo;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
@ -94,6 +99,9 @@ public class ArmadilloController extends MobEntityController {
|
||||
if (npc != null) {
|
||||
NMSImpl.updateMinecraftAIState(npc, this);
|
||||
npc.update();
|
||||
if (npc.isProtected()) {
|
||||
NMSImpl.setScuteTime(this, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,6 +170,16 @@ public class ArmadilloController extends MobEntityController {
|
||||
return NMSBoundingBox.makeBB(npc, super.makeBoundingBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult mobInteract(Player entityhuman, InteractionHand enumhand) {
|
||||
if (npc == null || !npc.isProtected())
|
||||
return super.mobInteract(entityhuman, enumhand);
|
||||
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
||||
if (itemstack.getItem() == Items.BRUSH)
|
||||
return InteractionResult.FAIL;
|
||||
return super.mobInteract(entityhuman, enumhand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClimbable() {
|
||||
if (npc == null || !npc.isFlyable())
|
||||
|
@ -2447,6 +2447,16 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setScuteTime(Entity armadillo, int scuteTime) {
|
||||
if (ARMADILLO_SCUTE_TIME == null)
|
||||
return;
|
||||
try {
|
||||
ARMADILLO_SCUTE_TIME.invoke(armadillo, scuteTime);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSize(Entity entity, boolean justCreated) {
|
||||
try {
|
||||
EntityDimensions entitysize = (EntityDimensions) SIZE_FIELD_GETTER.invoke(entity);
|
||||
@ -2544,6 +2554,8 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
|
||||
PlayerAdvancements.class);
|
||||
|
||||
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cj");
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
|
||||
Map.class);
|
||||
|
@ -58,7 +58,6 @@ public class AllayController extends MobEntityController {
|
||||
|
||||
public static class EntityAllayNPC extends Allay implements NPCHolder {
|
||||
private final CitizensNPC npc;
|
||||
|
||||
private int taskId = -1;
|
||||
|
||||
public EntityAllayNPC(EntityType<? extends Allay> types, Level level) {
|
||||
@ -84,6 +83,13 @@ public class AllayController extends MobEntityController {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity changeDimension(DimensionTransition transition) {
|
||||
if (npc == null)
|
||||
return super.changeDimension(transition);
|
||||
return NMSImpl.teleportAcrossWorld(this, transition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDespawn() {
|
||||
if (npc == null) {
|
||||
@ -217,13 +223,6 @@ public class AllayController extends MobEntityController {
|
||||
return npc == null ? super.save(save) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity changeDimension(DimensionTransition transition) {
|
||||
if (npc == null)
|
||||
return super.changeDimension(transition);
|
||||
return NMSImpl.teleportAcrossWorld(this, transition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void travel(Vec3 vec3d) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -18,12 +18,17 @@ import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.animal.armadillo.Armadillo;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Fluid;
|
||||
@ -74,6 +79,13 @@ public class ArmadilloController extends MobEntityController {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity changeDimension(DimensionTransition transition) {
|
||||
if (npc == null)
|
||||
return super.changeDimension(transition);
|
||||
return NMSImpl.teleportAcrossWorld(this, transition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDespawn() {
|
||||
if (npc == null) {
|
||||
@ -94,6 +106,9 @@ public class ArmadilloController extends MobEntityController {
|
||||
if (npc != null) {
|
||||
NMSImpl.updateMinecraftAIState(npc, this);
|
||||
npc.update();
|
||||
if (npc.isProtected()) {
|
||||
NMSImpl.setScuteTime(this, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,6 +177,16 @@ public class ArmadilloController extends MobEntityController {
|
||||
return NMSBoundingBox.makeBB(npc, super.makeBoundingBox());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult mobInteract(Player entityhuman, InteractionHand enumhand) {
|
||||
if (npc == null || !npc.isProtected())
|
||||
return super.mobInteract(entityhuman, enumhand);
|
||||
ItemStack itemstack = entityhuman.getItemInHand(enumhand);
|
||||
if (itemstack.getItem() == Items.BRUSH)
|
||||
return InteractionResult.FAIL;
|
||||
return super.mobInteract(entityhuman, enumhand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClimbable() {
|
||||
if (npc == null || !npc.isFlyable())
|
||||
@ -194,13 +219,6 @@ public class ArmadilloController extends MobEntityController {
|
||||
return npc == null ? super.save(save) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity changeDimension(DimensionTransition transition) {
|
||||
if (npc == null)
|
||||
return super.changeDimension(transition);
|
||||
return NMSImpl.teleportAcrossWorld(this, transition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void travel(Vec3 vec3d) {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
|
@ -937,7 +937,6 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
private void loadEntityTypes() {
|
||||
|
||||
EntityControllers.setEntityControllerForType(EntityType.ALLAY, AllayController.class);
|
||||
EntityControllers.setEntityControllerForType(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloudController.class);
|
||||
EntityControllers.setEntityControllerForType(EntityType.ARMADILLO, ArmadilloController.class);
|
||||
@ -2426,6 +2425,16 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setScuteTime(Entity armadillo, int scuteTime) {
|
||||
if (ARMADILLO_SCUTE_TIME == null)
|
||||
return;
|
||||
try {
|
||||
ARMADILLO_SCUTE_TIME.invoke(armadillo, scuteTime);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSize(Entity entity, boolean justCreated) {
|
||||
try {
|
||||
EntityDimensions entitysize = (EntityDimensions) SIZE_FIELD_GETTER.invoke(entity);
|
||||
@ -2511,6 +2520,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
private static final MethodHandle ADVANCEMENTS_PLAYER_SETTER = NMS.getFirstFinalSetter(ServerPlayer.class,
|
||||
PlayerAdvancements.class);
|
||||
private static final MethodHandle ARMADILLO_SCUTE_TIME = NMS.getSetter(Armadillo.class, "cn");
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getFirstGetter(AttributeSupplier.class, Map.class);
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFirstFinalSetter(AttributeSupplier.class,
|
||||
Map.class);
|
||||
@ -2562,10 +2572,10 @@ public class NMSImpl implements NMSBridge {
|
||||
private static final MethodHandle NAVIGATION_CREATE_PATHFINDER = NMS
|
||||
.getFirstMethodHandleWithReturnType(PathNavigation.class, true, PathFinder.class, int.class);
|
||||
private static final MethodHandle NAVIGATION_PATH = NMS.getFirstGetter(PathNavigation.class, Path.class);
|
||||
|
||||
private static final MethodHandle NAVIGATION_PATHFINDER = NMS.getFirstFinalSetter(PathNavigation.class,
|
||||
PathFinder.class);
|
||||
private static final MethodHandle NAVIGATION_WORLD_FIELD = NMS.getFirstSetter(PathNavigation.class, Level.class);
|
||||
|
||||
private static final MethodHandle PLAYER_INFO_ENTRIES_LIST = NMS
|
||||
.getFirstFinalSetter(ClientboundPlayerInfoUpdatePacket.class, List.class);
|
||||
private static final MethodHandle PLAYERINFO_ENTRIES = PLAYER_INFO_ENTRIES_LIST;
|
||||
|
Loading…
Reference in New Issue
Block a user