superb-warfare/src/main/java/net/mcreator/target/entity/Target1Entity.java
2024-05-05 15:44:33 +08:00

275 lines
9.8 KiB
Java

package net.mcreator.target.entity;
import net.mcreator.target.init.TargetModEntities;
import net.mcreator.target.procedures.*;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
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;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
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.control.FlyingMoveControl;
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.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
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.core.animation.AnimationController;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.animation.RawAnimation;
import software.bernie.geckolib.core.object.PlayState;
import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable;
public class Target1Entity extends PathfinderMob implements GeoEntity {
public static final EntityDataAccessor<Boolean> SHOOT = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<String> ANIMATION = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<String> TEXTURE = SynchedEntityData.defineId(Target1Entity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private boolean swinging;
private boolean lastloop;
private long lastSwing;
public String animationprocedure = "empty";
public Target1Entity(PlayMessages.SpawnEntity packet, Level world) {
this(TargetModEntities.TARGET_1.get(), world);
}
public Target1Entity(EntityType<Target1Entity> type, Level world) {
super(type, world);
xpReward = 0;
setNoAi(true);
setPersistenceRequired();
this.moveControl = new FlyingMoveControl(this, 10, true);
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(SHOOT, false);
this.entityData.define(ANIMATION, "undefined");
this.entityData.define(TEXTURE, "target");
}
public void setTexture(String texture) {
this.entityData.set(TEXTURE, texture);
}
public String getTexture() {
return this.entityData.get(TEXTURE);
}
@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 MobType.UNDEFINED;
}
@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return false;
}
@Override
public boolean causeFallDamage(float l, float d, DamageSource source) {
return false;
}
@Override
public boolean hurt(DamageSource source, float amount) {
Target1DangShiTiShouShangShiProcedure.execute(this.level(), this.getX(), this.getY(), this.getZ());
if (source.is(DamageTypes.IN_FIRE))
return false;
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.LIGHTNING_BOLT))
return false;
if (source.is(DamageTypes.FALLING_ANVIL))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
return super.hurt(source, amount);
}
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType reason, @Nullable SpawnGroupData livingdata, @Nullable CompoundTag tag) {
SpawnGroupData retval = super.finalizeSpawn(world, difficulty, reason, livingdata, tag);
Target1ShiTiChuShiShengChengShiProcedure.execute(this);
return retval;
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
compound.putString("Texture", this.getTexture());
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
if (compound.contains("Texture"))
this.setTexture(compound.getString("Texture"));
}
@Override
public InteractionResult mobInteract(Player sourceentity, InteractionHand hand) {
ItemStack itemstack = sourceentity.getItemInHand(hand);
InteractionResult retval = InteractionResult.sidedSuccess(this.level().isClientSide());
super.mobInteract(sourceentity, hand);
double x = this.getX();
double y = this.getY();
double z = this.getZ();
Entity entity = this;
Level world = this.level();
Target1DangYouJiShiTiShiProcedure.execute(y, entity, sourceentity);
return retval;
}
@Override
public void baseTick() {
super.baseTick();
Target1DangShiTiGengXinKeShiProcedure.execute(this);
this.refreshDimensions();
}
@Override
public EntityDimensions getDimensions(Pose p_33597_) {
Entity entity = this;
Level world = this.level();
double x = this.getX();
double y = entity.getY();
double z = entity.getZ();
return super.getDimensions(p_33597_).scale((float) BazipengzhuangProcedure.execute(entity));
}
@Override
public boolean isPushable() {
return false;
}
@Override
protected void doPush(Entity entityIn) {
}
@Override
protected void pushEntities() {
}
@Override
protected void checkFallDamage(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
}
@Override
public void setNoGravity(boolean ignored) {
super.setNoGravity(true);
}
@Override
public void aiStep() {
super.aiStep();
this.updateSwingTime();
this.setNoGravity(true);
}
public static void init() {
}
public static AttributeSupplier.Builder createAttributes() {
AttributeSupplier.Builder builder = Mob.createMobAttributes();
builder = builder.add(Attributes.MOVEMENT_SPEED, 0);
builder = builder.add(Attributes.MAX_HEALTH, 40);
builder = builder.add(Attributes.ARMOR, 0);
builder = builder.add(Attributes.ATTACK_DAMAGE, 0);
builder = builder.add(Attributes.FOLLOW_RANGE, 16);
builder = builder.add(Attributes.KNOCKBACK_RESISTANCE, 10);
builder = builder.add(Attributes.FLYING_SPEED, 0);
return builder;
}
private PlayState movementPredicate(AnimationState event) {
if (this.animationprocedure.equals("empty")) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.target.idle"));
}
return PlayState.STOP;
}
private PlayState procedurePredicate(AnimationState event) {
if (!animationprocedure.equals("empty") && event.getController().getAnimationState() == AnimationController.State.STOPPED) {
event.getController().setAnimation(RawAnimation.begin().thenPlay(this.animationprocedure));
if (event.getController().getAnimationState() == AnimationController.State.STOPPED) {
this.animationprocedure = "empty";
event.getController().forceAnimationReset();
}
} else if (animationprocedure.equals("empty")) {
return PlayState.STOP;
}
return PlayState.CONTINUE;
}
@Override
protected void tickDeath() {
++this.deathTime;
if (this.deathTime == 100) {
this.remove(Target1Entity.RemovalReason.KILLED);
this.dropExperience();
}
}
public String getSyncedAnimation() {
return this.entityData.get(ANIMATION);
}
public void setAnimation(String animation) {
this.entityData.set(ANIMATION, animation);
}
@Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));
data.add(new AnimationController<>(this, "procedure", 0, this::procedurePredicate));
}
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache;
}
}