diff --git a/src/main/java/ru/betterend/entity/SilkMothEntity.java b/src/main/java/ru/betterend/entity/SilkMothEntity.java index 7c4809f4..c5b625ca 100644 --- a/src/main/java/ru/betterend/entity/SilkMothEntity.java +++ b/src/main/java/ru/betterend/entity/SilkMothEntity.java @@ -1,16 +1,76 @@ package ru.betterend.entity; +import java.util.EnumSet; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.block.BlockState; import net.minecraft.entity.EntityType; import net.minecraft.entity.Flutterer; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.TargetFinder; +import net.minecraft.entity.ai.control.FlightMoveControl; +import net.minecraft.entity.ai.control.LookControl; +import net.minecraft.entity.ai.goal.AnimalMateGoal; +import net.minecraft.entity.ai.goal.FollowParentGoal; +import net.minecraft.entity.ai.goal.Goal; +import net.minecraft.entity.ai.goal.SwimGoal; +import net.minecraft.entity.ai.pathing.BirdNavigation; +import net.minecraft.entity.ai.pathing.EntityNavigation; +import net.minecraft.entity.ai.pathing.PathNodeType; +import net.minecraft.entity.attribute.DefaultAttributeContainer; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.PassiveEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import ru.betterend.registry.EndEntities; public class SilkMothEntity extends AnimalEntity implements Flutterer { public SilkMothEntity(EntityType entityType, World world) { super(entityType, world); + this.moveControl = new FlightMoveControl(this, 20, true); + this.lookControl = new MothLookControl(this); + this.setPathfindingPenalty(PathNodeType.WATER, -1.0F); + this.setPathfindingPenalty(PathNodeType.DANGER_FIRE, -1.0F); + this.experiencePoints = 1; + } + + public static DefaultAttributeContainer.Builder createMobAttributes() { + return LivingEntity.createLivingAttributes() + .add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0D) + .add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D) + .add(EntityAttributes.GENERIC_FLYING_SPEED, 0.4D) + .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.1D); + } + + @Override + protected void initGoals() { + this.goalSelector.add(2, new AnimalMateGoal(this, 1.0D)); + this.goalSelector.add(5, new FollowParentGoal(this, 1.25D)); + this.goalSelector.add(8, new WanderAroundGoal()); + this.goalSelector.add(9, new SwimGoal(this)); + } + + @Override + protected EntityNavigation createNavigation(World world) { + BirdNavigation birdNavigation = new BirdNavigation(this, world) { + public boolean isValidPosition(BlockPos pos) { + BlockState state = this.world.getBlockState(pos); + return state.isAir() || !state.getMaterial().blocksMovement(); + } + + public void tick() { + super.tick(); + } + }; + birdNavigation.setCanPathThroughDoors(false); + birdNavigation.setCanSwim(false); + birdNavigation.setCanEnterOpenDoors(true); + return birdNavigation; } @Override @@ -42,4 +102,46 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer { public PassiveEntity createChild(ServerWorld world, PassiveEntity entity) { return EndEntities.SILK_MOTH.create(world); } + + class MothLookControl extends LookControl { + MothLookControl(MobEntity entity) { + super(entity); + } + + protected boolean shouldStayHorizontal() { + return true; + } + } + + class WanderAroundGoal extends Goal { + WanderAroundGoal() { + this.setControls(EnumSet.of(Goal.Control.MOVE)); + } + + public boolean canStart() { + return SilkMothEntity.this.navigation.isIdle() && SilkMothEntity.this.random.nextInt(10) == 0; + } + + public boolean shouldContinue() { + return SilkMothEntity.this.navigation.isFollowingPath(); + } + + public void start() { + Vec3d vec3d = this.getRandomLocation(); + if (vec3d != null) { + try { + SilkMothEntity.this.navigation.startMovingAlong(SilkMothEntity.this.navigation.findPathTo((BlockPos) (new BlockPos(vec3d)), 1), 1.0D); + } + catch (Exception e) {} + } + + } + + @Nullable + private Vec3d getRandomLocation() { + Vec3d vec3d3 = SilkMothEntity.this.getRotationVec(0.0F); + Vec3d vec3d4 = TargetFinder.findAirTarget(SilkMothEntity.this, 8, 7, vec3d3, 1.5707964F, 2, 1); + return vec3d4 != null ? vec3d4 : TargetFinder.findGroundTarget(SilkMothEntity.this, 8, 4, -2, vec3d3, 1.5707963705062866D); + } + } } diff --git a/src/main/resources/assets/betterend/materialmaps/block/creeping_moss.json b/src/main/resources/assets/betterend/materialmaps/block/creeping_moss.json index 3b73d687..3af6aa5a 100644 --- a/src/main/resources/assets/betterend/materialmaps/block/creeping_moss.json +++ b/src/main/resources/assets/betterend/materialmaps/block/creeping_moss.json @@ -3,7 +3,7 @@ "spriteMap": [ { "sprite": "betterend:block/creeping_moss_spores", - "material": "betterend:wave_glow_50_half" + "material": "betterend:waving_floor_glow_half" }, { "sprite": "betterend:block/creeping_moss_leaves", diff --git a/src/main/resources/assets/betterend/materials/waving_floor_glow_half.json b/src/main/resources/assets/betterend/materials/waving_floor_glow_half.json new file mode 100644 index 00000000..6217c243 --- /dev/null +++ b/src/main/resources/assets/betterend/materials/waving_floor_glow_half.json @@ -0,0 +1,10 @@ +{ + "layers": [ + { + "vertexSource": "betterend:shaders/material/wave_floor.vert", + "fragmentSource": "betterend:shaders/material/glow_all_half.frag", + "disableAo": true, + "disableDiffuse": true + } + ] +} diff --git a/src/main/resources/assets/betterend/textures/entity/silk_moth.png b/src/main/resources/assets/betterend/textures/entity/silk_moth.png index d622f940..4976d1f0 100644 Binary files a/src/main/resources/assets/betterend/textures/entity/silk_moth.png and b/src/main/resources/assets/betterend/textures/entity/silk_moth.png differ