package net.mcreator.ak.entity;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.fmllegacy.network.NetworkHooks;
import net.minecraftforge.fmllegacy.network.FMLPlayMessages;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.common.DungeonHooks;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.monster.RangedAttackMob;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.RangedAttackGoal;
import net.minecraft.world.entity.ai.goal.RandomStrollGoal;
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
import net.minecraft.world.entity.ai.goal.PanicGoal;
import net.minecraft.world.entity.ai.goal.OpenDoorGoal;
import net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal;
import net.minecraft.world.entity.ai.goal.LeapAtTargetGoal;
import net.minecraft.world.entity.ai.goal.FloatGoal;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.SpawnPlacements;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;
import net.minecraft.core.BlockPos;
import net.mcreator.ak.init.AkModItems;
import net.mcreator.ak.init.AkModEntities;
import java.util.Set;
@Mod.EventBusSubscriber
public class BandinNewEntity extends Monster implements RangedAttackMob {
private static final Set<ResourceLocation> SPAWN_BIOMES = Set.of(new ResourceLocation("forest"), new ResourceLocation("plains"),
new ResourceLocation("savanna"), new ResourceLocation("swamp"), new ResourceLocation("desert"));
@SubscribeEvent
public static void addLivingEntityToBiomes(BiomeLoadingEvent event) {
if (SPAWN_BIOMES.contains(event.getName()))
event.getSpawns().getSpawner(MobCategory.CREATURE).add(new MobSpawnSettings.SpawnerData(AkModEntities.BANDIN_NEW, 20, 3, 5));
}
public BandinNewEntity(FMLPlayMessages.SpawnEntity packet, Level world) {
this(AkModEntities.BANDIN_NEW, world);
}
public BandinNewEntity(EntityType<BandinNewEntity> type, Level world) {
super(type, world);
xpReward = 5;
setNoAi(false);
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(AkModItems.AK_47));
}
@Override
public Packet<?> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this);
}
@Override
protected void registerGoals() {
super.registerGoals();
this.targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, Player.class, true, false));
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, Monster.class, true, false));
this.goalSelector.addGoal(3, new RandomStrollGoal(this, 1));
this.goalSelector.addGoal(4, new OpenDoorGoal(this, true));
this.goalSelector.addGoal(5, new MoveBackToVillageGoal(this, 0.6, false));
this.goalSelector.addGoal(6, new RandomLookAroundGoal(this));
this.goalSelector.addGoal(7, new FloatGoal(this));
this.goalSelector.addGoal(8, new LeapAtTargetGoal(this, (float) 0.8));
this.goalSelector.addGoal(9, new PanicGoal(this, 1.2));
this.targetSelector.addGoal(10, new HurtByTargetGoal(this).setAlertOthers(this.getClass()));
this.goalSelector.addGoal(1, new RangedAttackGoal(this, 1.25, 2, 10) {
@Override
public boolean canContinueToUse() {
return this.canUse();
}
});
}
@Override
public MobType getMobType() {
return MobType.UNDEFINED;
}
@Override
public SoundEvent getAmbientSound() {
return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.sheep.step"));
}
@Override
public void playStepSound(BlockPos pos, BlockState blockIn) {
this.playSound(ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.zombie_villager.step")), 0.15f, 1);
}
@Override
public SoundEvent getHurtSound(DamageSource ds) {
return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.generic.hurt"));
}
@Override
public SoundEvent getDeathSound() {
return ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.generic.death"));
}
@Override
public void performRangedAttack(LivingEntity target, float flval) {
Ak47Entity.shoot(this, target);
}
public static void init() {
SpawnPlacements.register(AkModEntities.BANDIN_NEW, SpawnPlacements.Type.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES,
(entityType, world, reason, pos,
random) -> (world.getBlockState(pos.below()).getMaterial() == Material.GRASS && world.getRawBrightness(pos, 0) > 8));
DungeonHooks.addDungeonMob(AkModEntities.BANDIN_NEW, 180);
}
public static AttributeSupplier.Builder createAttributes() {
AttributeSupplier.Builder builder = Mob.createMobAttributes();
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.3);
builder = builder.add(Attributes.MAX_HEALTH, 25);
builder = builder.add(Attributes.ARMOR, 0);
builder = builder.add(Attributes.ATTACK_DAMAGE, 1);
return builder;
}
}