重做标靶

This commit is contained in:
17146 2024-08-25 02:08:46 +08:00
parent 21d28f41c1
commit f0a0e076af
3 changed files with 33 additions and 42 deletions

View file

@ -37,4 +37,9 @@ public class TargetRenderer extends GeoEntityRenderer<TargetEntity> {
protected float getDeathMaxRotation(TargetEntity entityLivingBaseIn) {
return 0.0F;
}
@Override
public boolean shouldShowName(TargetEntity animatable) {
return animatable.hasCustomName();
}
}

View file

@ -65,11 +65,6 @@ public class ClaymoreEntity extends LivingEntity implements GeoEntity, AnimatedE
this.entityData.define(OWNER_UUID, Optional.empty());
}
@Override
public boolean isCustomNameVisible() {
return false;
}
@Override
public MobType getMobType() {
return super.getMobType();

View file

@ -7,10 +7,9 @@ import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.tools.SoundTool;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
@ -22,27 +21,22 @@ import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil;
// TODO 重置靶子
@Mod.EventBusSubscriber
public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEntity {
public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Integer> DOWN_TIME = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.INT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -55,9 +49,6 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
public TargetEntity(EntityType<TargetEntity> type, Level world) {
super(type, world);
xpReward = 0;
setNoAi(true);
setPersistenceRequired();
}
@Override
@ -67,24 +58,24 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
this.entityData.define(DOWN_TIME, 0);
}
@Override
public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
protected PathNavigation createNavigation(Level world) {
return new FlyingPathNavigation(this, world);
}
@Override
public MobType getMobType() {
return super.getMobType();
}
@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return false;
public Iterable<ItemStack> getArmorSlots() {
return NonNullList.withSize(1, ItemStack.EMPTY);
}
@Override
public ItemStack getItemBySlot(EquipmentSlot pSlot) {
return ItemStack.EMPTY;
}
@Override
public void setItemSlot(EquipmentSlot pSlot, ItemStack pStack) {
}
@Override
@ -127,9 +118,10 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
if (compound.contains("DownTime"))
if (compound.contains("DownTime")) {
this.entityData.set(DOWN_TIME, compound.getInt("DownTime"));
}
}
@SubscribeEvent
public static void onTarget1Down(LivingDeathEvent event) {
@ -139,7 +131,6 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
if (entity == null) return;
if (entity instanceof TargetEntity target1) {
event.setCanceled(true);
target1.setHealth(target1.getMaxHealth());
@ -160,16 +151,15 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
}
@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
InteractionResult result = InteractionResult.sidedSuccess(this.level().isClientSide());
super.mobInteract(player, hand);
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
if (!this.level().isClientSide()) {
this.discard();
}
if (!player.getAbilities().instabuild) {
player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get()));
}
} else {
if (!(player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zooming) {
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
@ -185,12 +175,12 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
}
}
return result;
return InteractionResult.sidedSuccess(this.level().isClientSide());
}
@Override
public void baseTick() {
super.baseTick();
public void tick() {
super.tick();
if (this.entityData.get(DOWN_TIME) > 0) {
this.entityData.set(DOWN_TIME, this.entityData.get(DOWN_TIME) - 1);
}
@ -201,6 +191,11 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
return false;
}
@Override
public HumanoidArm getMainArm() {
return HumanoidArm.RIGHT;
}
@Override
protected void doPush(Entity entityIn) {
}
@ -209,10 +204,6 @@ public class TargetEntity extends PathfinderMob implements GeoEntity, AnimatedEn
protected void pushEntities() {
}
@Override
protected void checkFallDamage(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
}
@Override
public void setNoGravity(boolean ignored) {
super.setNoGravity(true);