Removed Jello AI
This commit is contained in:
parent
ff22f74fdf
commit
7084e294d7
4 changed files with 54 additions and 128 deletions
|
@ -2,60 +2,56 @@ package ru.betterend.entity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import net.minecraft.block.Blocks;
|
|
||||||
|
import net.minecraft.entity.EntityData;
|
||||||
|
import net.minecraft.entity.EntityDimensions;
|
||||||
|
import net.minecraft.entity.EntityPose;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.SpawnReason;
|
import net.minecraft.entity.SpawnReason;
|
||||||
import net.minecraft.entity.ai.control.MoveControl;
|
|
||||||
import net.minecraft.entity.ai.goal.EscapeDangerGoal;
|
|
||||||
import net.minecraft.entity.ai.goal.FleeEntityGoal;
|
|
||||||
import net.minecraft.entity.ai.goal.SwimAroundGoal;
|
|
||||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
import net.minecraft.entity.attribute.EntityAttributes;
|
||||||
import net.minecraft.entity.damage.DamageSource;
|
|
||||||
import net.minecraft.entity.data.DataTracker;
|
import net.minecraft.entity.data.DataTracker;
|
||||||
import net.minecraft.entity.data.TrackedData;
|
import net.minecraft.entity.data.TrackedData;
|
||||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||||
import net.minecraft.entity.passive.SchoolingFishEntity;
|
import net.minecraft.entity.mob.WaterCreatureEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.particle.ParticleTypes;
|
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
|
||||||
import net.minecraft.sound.SoundEvent;
|
|
||||||
import net.minecraft.sound.SoundEvents;
|
|
||||||
import net.minecraft.tag.FluidTags;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Box;
|
import net.minecraft.util.math.Box;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.world.LocalDifficulty;
|
||||||
import net.minecraft.world.ServerWorldAccess;
|
import net.minecraft.world.ServerWorldAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndBiomes;
|
||||||
|
|
||||||
public class EntityJello extends SchoolingFishEntity {
|
public class EntityJello extends WaterCreatureEntity {
|
||||||
public static final int VARIANTS = 5;
|
public static final int VARIANTS = 2;
|
||||||
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EntityJello.class, TrackedDataHandlerRegistry.BYTE);
|
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EntityJello.class, TrackedDataHandlerRegistry.BYTE);
|
||||||
private static final TrackedData<Byte> SCALE = DataTracker.registerData(EntityJello.class, TrackedDataHandlerRegistry.BYTE);
|
private static final TrackedData<Byte> SCALE = DataTracker.registerData(EntityJello.class, TrackedDataHandlerRegistry.BYTE);
|
||||||
|
|
||||||
public EntityJello(EntityType<EntityJello> entityType, World world) {
|
public EntityJello(EntityType<EntityJello> entityType, World world) {
|
||||||
super(entityType, world);
|
super(entityType, world);
|
||||||
this.moveControl = new JelloMoveControl(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initGoals() {
|
protected void initGoals() {}
|
||||||
this.goalSelector.add(0, new EscapeDangerGoal(this, 1.25D));
|
|
||||||
this.goalSelector.add(2, new FleeEntityGoal<PlayerEntity>(this, PlayerEntity.class, 8.0F, 0.4D, 0.6D, EntityPredicates.EXCEPT_SPECTATOR::test));
|
@Override
|
||||||
this.goalSelector.add(4, new SwimToRandomPlaceGoal(this));
|
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CompoundTag entityTag) {
|
||||||
|
EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityTag);
|
||||||
|
if (EndBiomes.getFromBiome(world.getBiome(getBlockPos())) == EndBiomes.SULPHUR_SPRINGS) {
|
||||||
|
this.dataTracker.set(VARIANT, (byte) 1);
|
||||||
|
}
|
||||||
|
this.calculateDimensions();
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initDataTracker() {
|
protected void initDataTracker() {
|
||||||
super.initDataTracker();
|
super.initDataTracker();
|
||||||
this.dataTracker.startTracking(VARIANT, (byte) this.getRandom().nextInt(VARIANTS));
|
this.dataTracker.startTracking(VARIANT, (byte) 0);
|
||||||
this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16));
|
this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeCustomDataToTag(CompoundTag tag) {
|
public void writeCustomDataToTag(CompoundTag tag) {
|
||||||
super.writeCustomDataToTag(tag);
|
super.writeCustomDataToTag(tag);
|
||||||
|
@ -74,110 +70,30 @@ public class EntityJello extends SchoolingFishEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ItemStack getFishBucketItem() {
|
|
||||||
return new ItemStack(EndItems.BUCKET_END_FISH);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SoundEvent getFlopSound() {
|
|
||||||
return SoundEvents.ENTITY_TROPICAL_FISH_FLOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SoundEvent getAmbientSound() {
|
|
||||||
return SoundEvents.ENTITY_SALMON_AMBIENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SoundEvent getDeathSound() {
|
|
||||||
return SoundEvents.ENTITY_SALMON_DEATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SoundEvent getHurtSound(DamageSource source) {
|
|
||||||
return SoundEvents.ENTITY_SALMON_HURT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
super.tick();
|
|
||||||
if (random.nextInt(8) == 0 && getBlockState().isOf(Blocks.WATER)) {
|
|
||||||
double x = getX() + random.nextGaussian() * 0.2;
|
|
||||||
double y = getY() + random.nextGaussian() * 0.2;
|
|
||||||
double z = getZ() + random.nextGaussian() * 0.2;
|
|
||||||
world.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DefaultAttributeContainer.Builder createMobAttributes() {
|
public static DefaultAttributeContainer.Builder createMobAttributes() {
|
||||||
return LivingEntity.createLivingAttributes()
|
return LivingEntity.createLivingAttributes()
|
||||||
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
|
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
|
||||||
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0)
|
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0)
|
||||||
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.05);
|
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getVariant() {
|
public int getVariant() {
|
||||||
return (int) this.dataTracker.get(VARIANT);
|
return (int) this.dataTracker.get(VARIANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScale() {
|
public float getScale() {
|
||||||
return this.dataTracker.get(SCALE) / 32F + 0.75F;
|
return this.dataTracker.get(SCALE) / 32F + 0.75F;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canSpawn(EntityType<EntityJello> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
|
public static boolean canSpawn(EntityType<EntityJello> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
|
||||||
Box box = new Box(pos).expand(16);
|
Box box = new Box(pos).expand(16);
|
||||||
List<EntityJello> list = world.getEntitiesByClass(EntityJello.class, box, (entity) -> { return true; });
|
List<EntityJello> list = world.getEntitiesByClass(EntityJello.class, box, (entity) -> {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
return list.size() < 9;
|
return list.size() < 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class JelloMoveControl extends MoveControl {
|
|
||||||
private final EntityJello jello;
|
|
||||||
|
|
||||||
JelloMoveControl(EntityJello owner) {
|
protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
|
||||||
super(owner);
|
return dimensions.height * 0.5F;
|
||||||
this.jello = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick() {
|
|
||||||
if (this.jello.isSubmergedIn(FluidTags.WATER)) {
|
|
||||||
this.jello.setVelocity(this.jello.getVelocity().add(0.0D, 0.005D, 0.0D));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.state == MoveControl.State.MOVE_TO && !this.jello.getNavigation().isIdle()) {
|
|
||||||
float f = (float) (this.speed * this.jello.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED));
|
|
||||||
this.jello.setMovementSpeed(MathHelper.lerp(0.025F, this.jello.getMovementSpeed(), f));
|
|
||||||
double d = this.targetX - this.jello.getX();
|
|
||||||
double e = this.targetY - this.jello.getY();
|
|
||||||
double g = this.targetZ - this.jello.getZ();
|
|
||||||
if (e != 0.0D) {
|
|
||||||
double h = (double) MathHelper.sqrt(d * d + e * e + g * g);
|
|
||||||
this.jello.setVelocity(this.jello.getVelocity().add(0.0D, (double) this.jello.getMovementSpeed() * (e / h) * 0.1D, 0.0D));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d != 0.0D || g != 0.0D) {
|
|
||||||
float i = (float) (MathHelper.atan2(g, d) * 57.2957763671875D) - 90.0F;
|
|
||||||
this.jello.yaw = this.changeAngle(this.jello.yaw, i, 5.0F);
|
|
||||||
this.jello.bodyYaw = this.jello.yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.jello.setMovementSpeed(0.0F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SwimToRandomPlaceGoal extends SwimAroundGoal {
|
|
||||||
private final EntityJello fish;
|
|
||||||
|
|
||||||
public SwimToRandomPlaceGoal(EntityJello jello) {
|
|
||||||
super(jello, 1.0D, 40);
|
|
||||||
this.fish = jello;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canStart() {
|
|
||||||
return this.fish.hasSelfControl() && super.canStart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,25 +13,35 @@ import ru.betterend.entity.model.ModelEntityJello;
|
||||||
public class RendererEntityJello extends MobEntityRenderer<EntityJello, ModelEntityJello> {
|
public class RendererEntityJello extends MobEntityRenderer<EntityJello, ModelEntityJello> {
|
||||||
private static final Identifier TEXTURE = BetterEnd.makeID("textures/entity/jello.png");
|
private static final Identifier TEXTURE = BetterEnd.makeID("textures/entity/jello.png");
|
||||||
private static final RenderLayer GLOW = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/jello_glow.png"));
|
private static final RenderLayer GLOW = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/jello_glow.png"));
|
||||||
|
|
||||||
public RendererEntityJello(EntityRenderDispatcher entityRenderDispatcher) {
|
public RendererEntityJello(EntityRenderDispatcher entityRenderDispatcher) {
|
||||||
super(entityRenderDispatcher, new ModelEntityJello(), 0.5f);
|
super(entityRenderDispatcher, new ModelEntityJello(), 0.5f);
|
||||||
this.addFeature(new EyesFeatureRenderer<EntityJello, ModelEntityJello>(this) {
|
this.addFeature(new EyesFeatureRenderer<EntityJello, ModelEntityJello>(this) {
|
||||||
@Override
|
@Override
|
||||||
public RenderLayer getEyesTexture() {
|
public RenderLayer getEyesTexture() {
|
||||||
return GLOW;
|
return GLOW;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void scale(EntityJello entity, MatrixStack matrixStack, float f) {
|
protected void scale(EntityJello entity, MatrixStack matrixStack, float f) {
|
||||||
float scale = entity.getScale();
|
float scale = entity.getScale();
|
||||||
matrixStack.scale(scale, scale, scale);
|
matrixStack.scale(scale, scale, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getTexture(EntityJello entity) {
|
public Identifier getTexture(EntityJello entity) {
|
||||||
return TEXTURE;
|
return TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
|
protected void setupTransforms(EntityJello squidEntity, MatrixStack matrixStack, float f, float g, float h) {
|
||||||
|
float i = MathHelper.lerp(h, squidEntity.prevTiltAngle, squidEntity.tiltAngle);
|
||||||
|
float j = MathHelper.lerp(h, squidEntity.prevRollAngle, squidEntity.rollAngle);
|
||||||
|
matrixStack.translate(0, -0.5F, 0);
|
||||||
|
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180.0F - g));
|
||||||
|
matrixStack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(i));
|
||||||
|
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(j));
|
||||||
|
}*/
|
||||||
}
|
}
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Loading…
Add table
Add a link
Reference in a new issue