Start migration

This commit is contained in:
Aleksey 2021-04-08 21:55:07 +03:00
parent 6630ce0cab
commit 47ed597358
491 changed files with 12045 additions and 11953 deletions

View file

@ -3,52 +3,55 @@ package ru.betterend.entity;
import java.util.List;
import java.util.Random;
import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.control.MoveControl;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.passive.SchoolingFishEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.entity.EntityData;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityPose;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.damage.DamageSource;
import net.minecraft.world.entity.data.DataTracker;
import net.minecraft.world.entity.data.TrackedData;
import net.minecraft.world.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.world.entity.effect.StatusEffectInstance;
import net.minecraft.world.entity.effect.StatusEffects;
import net.minecraft.world.entity.passive.SchoolingFishEntity;
import net.minecraft.world.entity.player.PlayerEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.FluidTags;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndItems;
public class CubozoaEntity extends SchoolingFishEntity {
public static final int VARIANTS = 2;
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(CubozoaEntity.class, TrackedDataHandlerRegistry.BYTE);
private static final TrackedData<Byte> SCALE = DataTracker.registerData(CubozoaEntity.class, TrackedDataHandlerRegistry.BYTE);
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(CubozoaEntity.class,
TrackedDataHandlerRegistry.BYTE);
private static final TrackedData<Byte> SCALE = DataTracker.registerData(CubozoaEntity.class,
TrackedDataHandlerRegistry.BYTE);
public CubozoaEntity(EntityType<CubozoaEntity> entityType, World world) {
public CubozoaEntity(EntityType<CubozoaEntity> entityType, Level world) {
super(entityType, world);
}
@Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CompoundTag entityTag) {
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);
@ -83,10 +86,8 @@ public class CubozoaEntity extends SchoolingFishEntity {
}
public static DefaultAttributeContainer.Builder createMobAttributes() {
return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5);
return LivingEntity.createLivingAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5);
}
public int getVariant() {
@ -97,7 +98,8 @@ public class CubozoaEntity extends SchoolingFishEntity {
return this.dataTracker.get(SCALE) / 32F + 0.75F;
}
public static boolean canSpawn(EntityType<CubozoaEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
public static boolean canSpawn(EntityType<CubozoaEntity> type, ServerWorldAccess world, SpawnReason spawnReason,
BlockPos pos, Random random) {
Box box = new Box(pos).expand(16);
List<CubozoaEntity> list = world.getEntitiesByClass(CubozoaEntity.class, box, (entity) -> {
return true;
@ -108,7 +110,7 @@ public class CubozoaEntity extends SchoolingFishEntity {
protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
return dimensions.height * 0.5F;
}
@Override
protected void dropLoot(DamageSource source, boolean causedByPlayer) {
int count = random.nextInt(3);
@ -127,12 +129,13 @@ public class CubozoaEntity extends SchoolingFishEntity {
protected SoundEvent getFlopSound() {
return SoundEvents.ENTITY_SALMON_FLOP;
}
@Override
public void onPlayerCollision(PlayerEntity player) {
if (player instanceof ServerPlayerEntity && player.damage(DamageSource.mob(this), 0.5F)) {
if (player instanceof ServerPlayer && player.damage(DamageSource.mob(this), 0.5F)) {
if (!this.isSilent()) {
((ServerPlayerEntity) player).networkHandler.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PUFFERFISH_STING, 0.0F));
((ServerPlayer) player).networkHandler
.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PUFFERFISH_STING, 0.0F));
}
if (random.nextBoolean()) {
player.addStatusEffect(new StatusEffectInstance(StatusEffects.POISON, 20, 0));
@ -152,23 +155,23 @@ public class CubozoaEntity extends SchoolingFishEntity {
if (this.state == MoveControl.State.MOVE_TO && !this.entity.getNavigation().isIdle()) {
float f = (float) (this.speed * this.entity.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED));
this.entity.setMovementSpeed(MathHelper.lerp(0.125F, this.entity.getMovementSpeed(), f));
this.entity.setMovementSpeed(Mth.lerp(0.125F, this.entity.getMovementSpeed(), f));
double d = this.targetX - this.entity.getX();
double e = this.targetY - this.entity.getY();
double g = this.targetZ - this.entity.getZ();
if (e != 0.0D) {
double h = (double) MathHelper.sqrt(d * d + e * e + g * g);
this.entity.setVelocity(this.entity.getVelocity().add(0.0D, (double) this.entity.getMovementSpeed() * (e / h) * 0.1D, 0.0D));
double h = (double) Mth.sqrt(d * d + e * e + g * g);
this.entity.setVelocity(this.entity.getVelocity().add(0.0D,
(double) this.entity.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;
float i = (float) (Mth.atan2(g, d) * 57.2957763671875D) - 90.0F;
this.entity.yaw = this.changeAngle(this.entity.yaw, i, 90.0F);
this.entity.bodyYaw = this.entity.yaw;
}
}
else {
} else {
this.entity.setMovementSpeed(0.0F);
}
}

View file

@ -3,34 +3,34 @@ package ru.betterend.entity;
import java.util.EnumSet;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Flutterer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
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.Path;
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.world.level.block.state.BlockState;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Flutterer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.ai.TargetFinder;
import net.minecraft.world.entity.ai.control.FlightMoveControl;
import net.minecraft.world.entity.ai.control.LookControl;
import net.minecraft.world.entity.ai.goal.AnimalMateGoal;
import net.minecraft.world.entity.ai.goal.FollowParentGoal;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.SwimGoal;
import net.minecraft.world.entity.ai.pathing.BirdNavigation;
import net.minecraft.world.entity.ai.pathing.EntityNavigation;
import net.minecraft.world.entity.ai.pathing.Path;
import net.minecraft.world.entity.ai.pathing.PathNodeType;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.mob.MobEntity;
import net.minecraft.world.entity.passive.AnimalEntity;
import net.minecraft.world.entity.passive.PassiveEntity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import net.minecraft.world.WorldView;
import ru.betterend.registry.EndEntities;
import ru.betterend.registry.EndSounds;
@ -38,7 +38,7 @@ import ru.betterend.util.BlocksHelper;
import ru.betterend.util.MHelper;
public class DragonflyEntity extends AnimalEntity implements Flutterer {
public DragonflyEntity(EntityType<DragonflyEntity> entityType, World world) {
public DragonflyEntity(EntityType<DragonflyEntity> entityType, Level world) {
super(entityType, world);
this.moveControl = new FlightMoveControl(this, 20, true);
this.lookControl = new DragonflyLookControl(this);
@ -48,15 +48,13 @@ public class DragonflyEntity extends AnimalEntity implements Flutterer {
}
public static DefaultAttributeContainer.Builder createMobAttributes() {
return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 8.0D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D)
.add(EntityAttributes.GENERIC_FLYING_SPEED, 1.0D)
return LivingEntity.createLivingAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 8.0D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D).add(EntityAttributes.GENERIC_FLYING_SPEED, 1.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.1D);
}
@Override
protected EntityNavigation createNavigation(World world) {
protected EntityNavigation createNavigation(Level world) {
BirdNavigation birdNavigation = new BirdNavigation(this, world) {
public boolean isValidPosition(BlockPos pos) {
BlockState state = this.world.getBlockState(pos);
@ -153,8 +151,8 @@ public class DragonflyEntity extends AnimalEntity implements Flutterer {
if (path != null) {
DragonflyEntity.this.navigation.startMovingAlong(path, 1.0D);
}
} catch (Exception e) {
}
catch (Exception e) {}
}
super.start();
}
@ -188,11 +186,12 @@ public class DragonflyEntity extends AnimalEntity implements Flutterer {
}
@Override
public PassiveEntity createChild(ServerWorld world, PassiveEntity entity) {
public PassiveEntity createChild(ServerLevel world, PassiveEntity entity) {
return EndEntities.DRAGONFLY.create(world);
}
public static boolean canSpawn(EntityType<DragonflyEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
public static boolean canSpawn(EntityType<DragonflyEntity> type, ServerWorldAccess world, SpawnReason spawnReason,
BlockPos pos, Random random) {
int y = world.getChunk(pos).sampleHeightmap(Type.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15);
return y > 0 && pos.getY() >= y;
}

View file

@ -3,29 +3,29 @@ package ru.betterend.entity;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.passive.SchoolingFishEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.entity.EntityData;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.damage.DamageSource;
import net.minecraft.world.entity.data.DataTracker;
import net.minecraft.world.entity.data.TrackedData;
import net.minecraft.world.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.world.entity.passive.SchoolingFishEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndItems;
@ -33,15 +33,18 @@ public class EndFishEntity extends SchoolingFishEntity {
public static final int VARIANTS_NORMAL = 5;
public static final int VARIANTS_SULPHUR = 3;
public static final int VARIANTS = VARIANTS_NORMAL + VARIANTS_SULPHUR;
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EndFishEntity.class, TrackedDataHandlerRegistry.BYTE);
private static final TrackedData<Byte> SCALE = DataTracker.registerData(EndFishEntity.class, TrackedDataHandlerRegistry.BYTE);
public EndFishEntity(EntityType<EndFishEntity> entityType, World world) {
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EndFishEntity.class,
TrackedDataHandlerRegistry.BYTE);
private static final TrackedData<Byte> SCALE = DataTracker.registerData(EndFishEntity.class,
TrackedDataHandlerRegistry.BYTE);
public EndFishEntity(EntityType<EndFishEntity> entityType, Level world) {
super(entityType, world);
}
@Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CompoundTag entityTag) {
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) (random.nextInt(VARIANTS_SULPHUR) + VARIANTS_NORMAL));
@ -49,14 +52,14 @@ public class EndFishEntity extends SchoolingFishEntity {
this.calculateDimensions();
return data;
}
@Override
protected void initDataTracker() {
super.initDataTracker();
this.dataTracker.startTracking(VARIANT, (byte) this.getRandom().nextInt(VARIANTS_NORMAL));
this.dataTracker.startTracking(SCALE, (byte) this.getRandom().nextInt(16));
}
@Override
public void writeCustomDataToTag(CompoundTag tag) {
super.writeCustomDataToTag(tag);
@ -99,39 +102,40 @@ public class EndFishEntity extends SchoolingFishEntity {
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)) {
if (random.nextInt(8) == 0 && getBlockState().is(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() {
return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75);
return LivingEntity.createLivingAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0).add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75);
}
public int getVariant() {
return (int) this.dataTracker.get(VARIANT);
}
public float getScale() {
return this.dataTracker.get(SCALE) / 32F + 0.75F;
}
public static boolean canSpawn(EntityType<EndFishEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
public static boolean canSpawn(EntityType<EndFishEntity> type, ServerWorldAccess world, SpawnReason spawnReason,
BlockPos pos, Random random) {
Box box = new Box(pos).expand(16);
List<EndFishEntity> list = world.getEntitiesByClass(EndFishEntity.class, box, (entity) -> { return true; });
List<EndFishEntity> list = world.getEntitiesByClass(EndFishEntity.class, box, (entity) -> {
return true;
});
return list.size() < 9;
}
@Override
protected void dropLoot(DamageSource source, boolean causedByPlayer) {
ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(EndItems.END_FISH_RAW));

View file

@ -4,39 +4,39 @@ import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Blocks;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityData;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.control.MoveControl;
import net.minecraft.entity.ai.goal.FollowTargetGoal;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.SlimeEntity;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.entity.EntityData;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.goal.FollowTargetGoal;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.damage.DamageSource;
import net.minecraft.world.entity.data.DataTracker;
import net.minecraft.world.entity.data.TrackedData;
import net.minecraft.world.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.world.entity.effect.StatusEffects;
import net.minecraft.world.entity.mob.SlimeEntity;
import net.minecraft.world.entity.passive.IronGolemEntity;
import net.minecraft.world.entity.player.PlayerEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.Mutable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import net.minecraft.world.biome.Biome;
import ru.betterend.interfaces.ISlime;
import ru.betterend.registry.EndBiomes;
@ -45,44 +45,43 @@ import ru.betterend.util.MHelper;
import ru.betterend.world.biome.EndBiome;
public class EndSlimeEntity extends SlimeEntity {
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EndSlimeEntity.class, TrackedDataHandlerRegistry.BYTE);
private static final Mutable POS = new Mutable();
public EndSlimeEntity(EntityType<EndSlimeEntity> entityType, World world) {
private static final TrackedData<Byte> VARIANT = DataTracker.registerData(EndSlimeEntity.class,
TrackedDataHandlerRegistry.BYTE);
private static final MutableBlockPos POS = new MutableBlockPos();
public EndSlimeEntity(EntityType<EndSlimeEntity> entityType, Level world) {
super(entityType, world);
this.moveControl = new EndSlimeMoveControl(this);
}
protected void initGoals() {
this.goalSelector.add(1, new SwimmingGoal());
this.goalSelector.add(2, new FaceTowardTargetGoal());
this.goalSelector.add(3, new RandomLookGoal());
this.goalSelector.add(5, new MoveGoal());
this.targetSelector.add(1, new FollowTargetGoal<PlayerEntity>(this, PlayerEntity.class, 10, true, false, (livingEntity) -> {
return Math.abs(livingEntity.getY() - this.getY()) <= 4.0D;
}));
this.targetSelector.add(1,
new FollowTargetGoal<PlayerEntity>(this, PlayerEntity.class, 10, true, false, (livingEntity) -> {
return Math.abs(livingEntity.getY() - this.getY()) <= 4.0D;
}));
this.targetSelector.add(3, new FollowTargetGoal<IronGolemEntity>(this, IronGolemEntity.class, true));
}
public static DefaultAttributeContainer.Builder createMobAttributes() {
return LivingEntity.createLivingAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 1.0D)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 1.0D)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D)
return LivingEntity.createLivingAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 1.0D)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 1.0D).add(EntityAttributes.GENERIC_FOLLOW_RANGE, 16.0D)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.15D);
}
@Override
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CompoundTag entityTag) {
public EntityData initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason,
EntityData entityData, CompoundTag entityTag) {
EntityData data = super.initialize(world, difficulty, spawnReason, entityData, entityTag);
EndBiome biome = EndBiomes.getFromBiome(world.getBiome(getBlockPos()));
if (biome == EndBiomes.FOGGY_MUSHROOMLAND) {
this.setMossy();
}
else if (biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) {
} else if (biome == EndBiomes.MEGALAKE || biome == EndBiomes.MEGALAKE_GROVE) {
this.setLake();
}
else if (biome == EndBiomes.AMBER_LAND) {
} else if (biome == EndBiomes.AMBER_LAND) {
this.setAmber(true);
}
this.calculateDimensions();
@ -94,7 +93,7 @@ public class EndSlimeEntity extends SlimeEntity {
super.initDataTracker();
this.dataTracker.startTracking(VARIANT, (byte) 0);
}
@Override
public void writeCustomDataToTag(CompoundTag tag) {
super.writeCustomDataToTag(tag);
@ -110,21 +109,21 @@ public class EndSlimeEntity extends SlimeEntity {
}
@Override
protected ParticleEffect getParticles() {
protected ParticleOptions getParticles() {
return ParticleTypes.PORTAL;
}
@Override
public void remove() {
int i = this.getSize();
if (!this.world.isClient && i > 1 && this.isDead()) {
if (!this.world.isClientSide && i > 1 && this.isDead()) {
Text text = this.getCustomName();
boolean bl = this.isAiDisabled();
float f = (float) i / 4.0F;
int j = i / 2;
int k = 2 + this.random.nextInt(3);
int type = this.getSlimeType();
for (int l = 0; l < k; ++l) {
float g = ((float) (l % 2) - 0.5F) * f;
float h = ((float) (l / 2) - 0.5F) * f;
@ -139,13 +138,14 @@ public class EndSlimeEntity extends SlimeEntity {
slimeEntity.setInvulnerable(this.isInvulnerable());
((ISlime) slimeEntity).beSetSlimeSize(j, true);
slimeEntity.calculateDimensions();
slimeEntity.refreshPositionAndAngles(this.getX() + (double) g, this.getY() + 0.5D, this.getZ() + (double) h, this.random.nextFloat() * 360.0F, 0.0F);
slimeEntity.refreshPositionAndAngles(this.getX() + (double) g, this.getY() + 0.5D,
this.getZ() + (double) h, this.random.nextFloat() * 360.0F, 0.0F);
this.world.spawnEntity(slimeEntity);
}
}
this.removed = true;
}
@Override
protected void dropLoot(DamageSource source, boolean causedByPlayer) {
int maxCount = this.getSize();
@ -161,15 +161,15 @@ public class EndSlimeEntity extends SlimeEntity {
ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(Items.SLIME_BALL, count));
this.world.spawnEntity(drop);
}
public int getSlimeType() {
return this.dataTracker.get(VARIANT).intValue();
}
public void setSlimeType(int value) {
this.dataTracker.set(VARIANT, (byte) value);
}
protected void setMossy() {
setSlimeType(1);
}
@ -177,7 +177,7 @@ public class EndSlimeEntity extends SlimeEntity {
public boolean isMossy() {
return getSlimeType() == 1;
}
protected void setLake() {
setSlimeType(2);
}
@ -185,7 +185,7 @@ public class EndSlimeEntity extends SlimeEntity {
public boolean isLake() {
return getSlimeType() == 2;
}
protected void setAmber(boolean mossy) {
this.dataTracker.set(VARIANT, (byte) 3);
}
@ -193,26 +193,30 @@ public class EndSlimeEntity extends SlimeEntity {
public boolean isAmber() {
return this.dataTracker.get(VARIANT) == 3;
}
public boolean isChorus() {
return this.dataTracker.get(VARIANT) == 0;
}
public static boolean canSpawn(EntityType<EndSlimeEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
return random.nextInt(16) == 0 || isPermanentBiome(world, pos) || (notManyEntities(world, pos, 32, 3) && isWaterNear(world, pos, 32, 8));
public static boolean canSpawn(EntityType<EndSlimeEntity> type, ServerWorldAccess world, SpawnReason spawnReason,
BlockPos pos, Random random) {
return random.nextInt(16) == 0 || isPermanentBiome(world, pos)
|| (notManyEntities(world, pos, 32, 3) && isWaterNear(world, pos, 32, 8));
}
private static boolean isPermanentBiome(ServerWorldAccess world, BlockPos pos) {
Biome biome = world.getBiome(pos);
return EndBiomes.getFromBiome(biome) == EndBiomes.CHORUS_FOREST;
}
private static boolean notManyEntities(ServerWorldAccess world, BlockPos pos, int radius, int maxCount) {
Box box = new Box(pos).expand(radius);
List<EndSlimeEntity> list = world.getEntitiesByClass(EndSlimeEntity.class, box, (entity) -> { return true; });
List<EndSlimeEntity> list = world.getEntitiesByClass(EndSlimeEntity.class, box, (entity) -> {
return true;
});
return list.size() <= maxCount;
}
private static boolean isWaterNear(ServerWorldAccess world, BlockPos pos, int radius, int radius2) {
for (int x = pos.getX() - radius; x <= pos.getX() + radius; x++) {
POS.setX(x);
@ -228,7 +232,7 @@ public class EndSlimeEntity extends SlimeEntity {
}
return false;
}
class MoveGoal extends Goal {
public MoveGoal() {
this.setControls(EnumSet.of(Goal.Control.JUMP, Goal.Control.MOVE));
@ -238,17 +242,17 @@ public class EndSlimeEntity extends SlimeEntity {
if (EndSlimeEntity.this.hasVehicle()) {
return false;
}
float yaw = EndSlimeEntity.this.getHeadYaw();
float speed = EndSlimeEntity.this.getMovementSpeed();
if (speed > 0.1) {
float dx = MathHelper.sin(-yaw * 0.017453292F);
float dz = MathHelper.cos(-yaw * 0.017453292F);
float dx = Mth.sin(-yaw * 0.017453292F);
float dz = Mth.cos(-yaw * 0.017453292F);
BlockPos pos = EndSlimeEntity.this.getBlockPos().add(dx * speed * 4, 0, dz * speed * 4);
int down = BlocksHelper.downRay(EndSlimeEntity.this.world, pos, 16);
return down < 5;
}
return true;
}
@ -264,8 +268,7 @@ public class EndSlimeEntity extends SlimeEntity {
}
public boolean canStart() {
return (EndSlimeEntity.this.isTouchingWater()
|| EndSlimeEntity.this.isInLava())
return (EndSlimeEntity.this.isTouchingWater() || EndSlimeEntity.this.isInLava())
&& EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl;
}
@ -288,8 +291,7 @@ public class EndSlimeEntity extends SlimeEntity {
public boolean canStart() {
return EndSlimeEntity.this.getTarget() == null
&& (EndSlimeEntity.this.onGround
|| EndSlimeEntity.this.isTouchingWater()
&& (EndSlimeEntity.this.onGround || EndSlimeEntity.this.isTouchingWater()
|| EndSlimeEntity.this.isInLava()
|| EndSlimeEntity.this.hasStatusEffect(StatusEffects.LEVITATION))
&& EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl;
@ -316,12 +318,12 @@ public class EndSlimeEntity extends SlimeEntity {
LivingEntity livingEntity = EndSlimeEntity.this.getTarget();
if (livingEntity == null) {
return false;
}
else if (!livingEntity.isAlive()) {
} else if (!livingEntity.isAlive()) {
return false;
}
else {
return livingEntity instanceof PlayerEntity && ((PlayerEntity) livingEntity).abilities.invulnerable ? false : EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl;
} else {
return livingEntity instanceof PlayerEntity && ((PlayerEntity) livingEntity).abilities.invulnerable
? false
: EndSlimeEntity.this.getMoveControl() instanceof EndSlimeMoveControl;
}
}
@ -334,21 +336,19 @@ public class EndSlimeEntity extends SlimeEntity {
LivingEntity livingEntity = EndSlimeEntity.this.getTarget();
if (livingEntity == null) {
return false;
}
else if (!livingEntity.isAlive()) {
} else if (!livingEntity.isAlive()) {
return false;
}
else if (livingEntity instanceof PlayerEntity && ((PlayerEntity) livingEntity).abilities.invulnerable) {
} else if (livingEntity instanceof PlayerEntity && ((PlayerEntity) livingEntity).abilities.invulnerable) {
return false;
}
else {
} else {
return --this.ticksLeft > 0;
}
}
public void tick() {
EndSlimeEntity.this.lookAtEntity(EndSlimeEntity.this.getTarget(), 10.0F, 10.0F);
((EndSlimeMoveControl) EndSlimeEntity.this.getMoveControl()).look(EndSlimeEntity.this.yaw, EndSlimeEntity.this.canAttack());
((EndSlimeMoveControl) EndSlimeEntity.this.getMoveControl()).look(EndSlimeEntity.this.yaw,
EndSlimeEntity.this.canAttack());
}
}
@ -378,11 +378,11 @@ public class EndSlimeEntity extends SlimeEntity {
this.entity.bodyYaw = this.entity.yaw;
if (this.state != MoveControl.State.MOVE_TO) {
this.entity.setForwardSpeed(0.0F);
}
else {
} else {
this.state = MoveControl.State.WAIT;
if (this.entity.isOnGround()) {
this.entity.setMovementSpeed((float) (this.speed * this.entity.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)));
this.entity.setMovementSpeed((float) (this.speed
* this.entity.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)));
if (this.ticksUntilJump-- <= 0) {
this.ticksUntilJump = EndSlimeEntity.this.getTicksUntilNextJump();
if (this.jumpOften) {
@ -391,17 +391,17 @@ public class EndSlimeEntity extends SlimeEntity {
EndSlimeEntity.this.getJumpControl().setActive();
if (EndSlimeEntity.this.makesJumpSound()) {
EndSlimeEntity.this.playSound(EndSlimeEntity.this.getJumpSound(), EndSlimeEntity.this.getSoundVolume(), getJumpSoundPitch());
EndSlimeEntity.this.playSound(EndSlimeEntity.this.getJumpSound(),
EndSlimeEntity.this.getSoundVolume(), getJumpSoundPitch());
}
}
else {
} else {
EndSlimeEntity.this.sidewaysSpeed = 0.0F;
EndSlimeEntity.this.forwardSpeed = 0.0F;
this.entity.setMovementSpeed(0.0F);
}
}
else {
this.entity.setMovementSpeed((float) (this.speed * this.entity.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)));
} else {
this.entity.setMovementSpeed((float) (this.speed
* this.entity.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)));
}
}
@ -409,7 +409,8 @@ public class EndSlimeEntity extends SlimeEntity {
private float getJumpSoundPitch() {
float f = EndSlimeEntity.this.isSmall() ? 1.4F : 0.8F;
return ((EndSlimeEntity.this.random.nextFloat() - EndSlimeEntity.this.random.nextFloat()) * 0.2F + 1.0F) * f;
return ((EndSlimeEntity.this.random.nextFloat() - EndSlimeEntity.this.random.nextFloat()) * 0.2F + 1.0F)
* f;
}
}
}

View file

@ -3,37 +3,37 @@ package ru.betterend.entity;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.ai.goal.FollowTargetGoal;
import net.minecraft.entity.ai.goal.LookAroundGoal;
import net.minecraft.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.ai.goal.FollowTargetGoal;
import net.minecraft.world.entity.ai.goal.LookAroundGoal;
import net.minecraft.world.entity.ai.goal.LookAtEntityGoal;
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.world.entity.ai.goal.WanderAroundFarGoal;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.damage.DamageSource;
import net.minecraft.world.entity.effect.StatusEffectInstance;
import net.minecraft.world.entity.effect.StatusEffects;
import net.minecraft.world.entity.mob.HostileEntity;
import net.minecraft.world.entity.player.PlayerEntity;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import ru.betterend.registry.EndSounds;
import ru.betterend.util.MHelper;
public class ShadowWalkerEntity extends HostileEntity {
public ShadowWalkerEntity(EntityType<ShadowWalkerEntity> entityType, World world) {
public ShadowWalkerEntity(EntityType<ShadowWalkerEntity> entityType, Level world) {
super(entityType, world);
}
@Override
protected void initGoals() {
this.goalSelector.add(2, new AttackGoal(this, 1.0D, false));
@ -44,34 +44,22 @@ public class ShadowWalkerEntity extends HostileEntity {
}
public static DefaultAttributeContainer.Builder createMobAttributes() {
return HostileEntity.createHostileAttributes()
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 35.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.15)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 4.5)
.add(EntityAttributes.GENERIC_ARMOR, 2.0)
.add(EntityAttributes.ZOMBIE_SPAWN_REINFORCEMENTS);
return HostileEntity.createHostileAttributes().add(EntityAttributes.GENERIC_FOLLOW_RANGE, 35.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.15).add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 4.5)
.add(EntityAttributes.GENERIC_ARMOR, 2.0).add(EntityAttributes.ZOMBIE_SPAWN_REINFORCEMENTS);
}
@Override
public void tick() {
super.tick();
world.addParticle(ParticleTypes.ASH,
getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1,
getZ() + random.nextGaussian() * 0.2,
0, 0, 0);
world.addParticle(ParticleTypes.SMOKE,
getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1,
getZ() + random.nextGaussian() * 0.2,
0, 0, 0);
world.addParticle(ParticleTypes.ENTITY_EFFECT,
getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1,
getZ() + random.nextGaussian() * 0.2,
0, 0, 0);
world.addParticle(ParticleTypes.ASH, getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0);
world.addParticle(ParticleTypes.SMOKE, getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0);
world.addParticle(ParticleTypes.ENTITY_EFFECT, getX() + random.nextGaussian() * 0.2,
getY() + random.nextGaussian() * 0.5 + 1, getZ() + random.nextGaussian() * 0.2, 0, 0, 0);
}
@Override
protected SoundEvent getAmbientSound() {
return EndSounds.ENTITY_SHADOW_WALKER;
@ -88,18 +76,19 @@ public class ShadowWalkerEntity extends HostileEntity {
}
@Override
protected void playStepSound(BlockPos pos, BlockState state) {}
protected void playStepSound(BlockPos pos, BlockState state) {
}
@Override
protected float getSoundVolume() {
return MHelper.randRange(0.25F, 0.5F, random);
}
@Override
protected float getSoundPitch() {
return MHelper.randRange(0.75F, 1.25F, random);
}
@Override
public boolean tryAttack(Entity target) {
boolean attack = super.tryAttack(target);
@ -111,24 +100,27 @@ public class ShadowWalkerEntity extends HostileEntity {
}
return attack;
}
public static boolean canSpawn(EntityType<ShadowWalkerEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
public static boolean canSpawn(EntityType<ShadowWalkerEntity> type, ServerWorldAccess world,
SpawnReason spawnReason, BlockPos pos, Random random) {
if (HostileEntity.canSpawnInDark(type, world, spawnReason, pos, random)) {
Box box = new Box(pos).expand(16);
List<ShadowWalkerEntity> entities = world.getEntitiesByClass(ShadowWalkerEntity.class, box, (entity) -> { return true; });
List<ShadowWalkerEntity> entities = world.getEntitiesByClass(ShadowWalkerEntity.class, box, (entity) -> {
return true;
});
return entities.size() < 6;
}
return false;
}
private final class AttackGoal extends MeleeAttackGoal {
private final ShadowWalkerEntity walker;
private int ticks;
public AttackGoal(ShadowWalkerEntity walker, double speed, boolean pauseWhenMobIdle) {
super(walker, speed, pauseWhenMobIdle);
this.walker = walker;
}
super(walker, speed, pauseWhenMobIdle);
this.walker = walker;
}
public void start() {
super.start();
@ -145,8 +137,7 @@ public class ShadowWalkerEntity extends HostileEntity {
++this.ticks;
if (this.ticks >= 5 && this.method_28348() < this.method_28349() / 2) {
this.walker.setAttacking(true);
}
else {
} else {
this.walker.setAttacking(false);
}
}

View file

@ -6,45 +6,45 @@ import java.util.Random;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.Flutterer;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnReason;
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.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.PassiveEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Flutterer;
import net.minecraft.world.entity.ItemEntity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.SpawnReason;
import net.minecraft.world.entity.ai.TargetFinder;
import net.minecraft.world.entity.ai.control.FlightMoveControl;
import net.minecraft.world.entity.ai.control.LookControl;
import net.minecraft.world.entity.ai.goal.AnimalMateGoal;
import net.minecraft.world.entity.ai.goal.FollowParentGoal;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.SwimGoal;
import net.minecraft.world.entity.ai.pathing.BirdNavigation;
import net.minecraft.world.entity.ai.pathing.EntityNavigation;
import net.minecraft.world.entity.ai.pathing.PathNodeType;
import net.minecraft.world.entity.attribute.DefaultAttributeContainer;
import net.minecraft.world.entity.attribute.EntityAttributes;
import net.minecraft.world.entity.damage.DamageSource;
import net.minecraft.world.entity.mob.MobEntity;
import net.minecraft.world.entity.passive.AnimalEntity;
import net.minecraft.world.entity.passive.PassiveEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.core.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Heightmap.Type;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.level.Level;
import ru.betterend.BetterEnd;
import ru.betterend.blocks.BlockProperties;
import ru.betterend.registry.EndBlocks;
@ -56,9 +56,9 @@ import ru.betterend.util.MHelper;
public class SilkMothEntity extends AnimalEntity implements Flutterer {
private BlockPos hivePos;
private BlockPos entrance;
private World hiveWorld;
public SilkMothEntity(EntityType<? extends SilkMothEntity> entityType, World world) {
private Level hiveWorld;
public SilkMothEntity(EntityType<? extends SilkMothEntity> entityType, Level world) {
super(entityType, world);
this.moveControl = new FlightMoveControl(this, 20, true);
this.lookControl = new MothLookControl(this);
@ -66,38 +66,35 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
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)
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);
}
public void setHive(World world, BlockPos hive) {
public void setHive(Level world, BlockPos hive) {
this.hivePos = hive;
this.hiveWorld = world;
}
@Override
public void writeCustomDataToTag(CompoundTag tag) {
if (hivePos != null) {
tag.put("HivePos", NbtHelper.fromBlockPos(hivePos));
tag.putString("HiveWorld", hiveWorld.getRegistryKey().getValue().toString());
tag.putString("HiveWorld", hiveWorld.dimension().location().toString());
}
}
@Override
public void readCustomDataFromTag(CompoundTag tag) {
if (tag.contains("HivePos")) {
hivePos = NbtHelper.toBlockPos(tag.getCompound("HivePos"));
Identifier worldID = new Identifier(tag.getString("HiveWorld"));
ResourceLocation worldID = new ResourceLocation(tag.getString("HiveWorld"));
try {
hiveWorld = world.getServer().getWorld(RegistryKey.of(Registry.DIMENSION, worldID));
}
catch (Exception e) {
BetterEnd.LOGGER.warning("Silk Moth Hive World {} is missing!", worldID);
hiveWorld = world.getServer().getLevel(RegistryKey.of(Registry.DIMENSION, worldID));
} catch (Exception e) {
BetterEnd.LOGGER.warning("Silk Moth Hive Level {} is missing!", worldID);
hivePos = null;
}
}
@ -111,9 +108,9 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
this.goalSelector.add(8, new WanderAroundGoal());
this.goalSelector.add(9, new SwimGoal(this));
}
@Override
protected EntityNavigation createNavigation(World world) {
protected EntityNavigation createNavigation(Level world) {
BirdNavigation birdNavigation = new BirdNavigation(this, world) {
public boolean isValidPosition(BlockPos pos) {
BlockState state = this.world.getBlockState(pos);
@ -156,10 +153,10 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
}
@Override
public PassiveEntity createChild(ServerWorld world, PassiveEntity entity) {
public PassiveEntity createChild(ServerLevel world, PassiveEntity entity) {
return EndEntities.SILK_MOTH.create(world);
}
@Override
protected void dropLoot(DamageSource source, boolean causedByPlayer) {
int minCount = 0;
@ -176,18 +173,19 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
ItemEntity drop = new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(EndItems.SILK_FIBER, count));
this.world.spawnEntity(drop);
}
public static boolean canSpawn(EntityType<SilkMothEntity> type, ServerWorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) {
public static boolean canSpawn(EntityType<SilkMothEntity> type, ServerWorldAccess world, SpawnReason spawnReason,
BlockPos pos, Random random) {
int y = world.getChunk(pos).sampleHeightmap(Type.WORLD_SURFACE, pos.getX() & 15, pos.getY() & 15);
return y > 0 && pos.getY() >= y && notManyEntities(world, pos, 32, 1);
}
private static boolean notManyEntities(ServerWorldAccess world, BlockPos pos, int radius, int maxCount) {
Box box = new Box(pos).expand(radius);
List<SilkMothEntity> list = world.getEntitiesByClass(SilkMothEntity.class, box, (entity) -> true);
return list.size() <= maxCount;
}
class MothLookControl extends LookControl {
MothLookControl(MobEntity entity) {
super(entity);
@ -217,16 +215,18 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
public void start() {
Vec3d vec3d = null;
if (SilkMothEntity.this.hivePos != null && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.world) {
if (SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(), SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) > 16) {
if (SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(),
SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) > 16) {
vec3d = SilkMothEntity.this.getPos().add(random.nextGaussian() * 2, 0, random.nextGaussian() * 2);
}
}
vec3d = vec3d == null ? this.getRandomLocation() : vec3d;
if (vec3d != null) {
try {
SilkMothEntity.this.navigation.startMovingAlong(SilkMothEntity.this.navigation.findPathTo(new BlockPos(vec3d), 1), 1.0D);
SilkMothEntity.this.navigation
.startMovingAlong(SilkMothEntity.this.navigation.findPathTo(new BlockPos(vec3d), 1), 1.0D);
} catch (Exception e) {
}
catch (Exception e) {}
}
}
@ -234,43 +234,47 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
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);
return vec3d4 != null ? vec3d4
: TargetFinder.findGroundTarget(SilkMothEntity.this, 8, 4, -2, vec3d3, 1.5707963705062866D);
}
}
class ReturnToHiveGoal extends Goal {
ReturnToHiveGoal() {
this.setControls(EnumSet.of(Goal.Control.MOVE));
}
@Override
public boolean canStart() {
return SilkMothEntity.this.hivePos != null
&& SilkMothEntity.this.hiveWorld == SilkMothEntity.this.world
&& SilkMothEntity.this.navigation.isIdle()
&& SilkMothEntity.this.random.nextInt(16) == 0
&& SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(), SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) < 64;
return SilkMothEntity.this.hivePos != null && SilkMothEntity.this.hiveWorld == SilkMothEntity.this.world
&& SilkMothEntity.this.navigation.isIdle() && SilkMothEntity.this.random.nextInt(16) == 0
&& SilkMothEntity.this.getPos().squaredDistanceTo(SilkMothEntity.this.hivePos.getX(),
SilkMothEntity.this.hivePos.getY(), SilkMothEntity.this.hivePos.getZ()) < 64;
}
@Override
public boolean shouldContinue() {
return SilkMothEntity.this.navigation.isFollowingPath() && world.getBlockState(entrance).isAir() && (world.getBlockState(hivePos).isOf(EndBlocks.SILK_MOTH_NEST) || world.getBlockState(hivePos).isOf(EndBlocks.SILK_MOTH_HIVE));
return SilkMothEntity.this.navigation.isFollowingPath() && world.getBlockState(entrance).isAir()
&& (world.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_NEST)
|| world.getBlockState(hivePos).is(EndBlocks.SILK_MOTH_HIVE));
}
@Override
public void start() {
BlockState state = SilkMothEntity.this.world.getBlockState(SilkMothEntity.this.hivePos);
if (!state.isOf(EndBlocks.SILK_MOTH_NEST) && !state.isOf(EndBlocks.SILK_MOTH_HIVE)) {
if (!state.is(EndBlocks.SILK_MOTH_NEST) && !state.is(EndBlocks.SILK_MOTH_HIVE)) {
SilkMothEntity.this.hivePos = null;
return;
}
try {
SilkMothEntity.this.entrance = SilkMothEntity.this.hivePos.offset(state.get(Properties.HORIZONTAL_FACING));
SilkMothEntity.this.navigation.startMovingAlong(SilkMothEntity.this.navigation.findPathTo(entrance, 1), 1.0D);
SilkMothEntity.this.entrance = SilkMothEntity.this.hivePos
.offset(state.getValue(Properties.HORIZONTAL_FACING));
SilkMothEntity.this.navigation.startMovingAlong(SilkMothEntity.this.navigation.findPathTo(entrance, 1),
1.0D);
} catch (Exception e) {
}
catch (Exception e) {}
}
@Override
public void tick() {
super.tick();
@ -282,20 +286,21 @@ public class SilkMothEntity extends AnimalEntity implements Flutterer {
double dz = Math.abs(SilkMothEntity.this.entrance.getZ() - SilkMothEntity.this.getZ());
if (dx + dy + dz < 1) {
BlockState state = SilkMothEntity.this.world.getBlockState(hivePos);
if (state.isOf(EndBlocks.SILK_MOTH_NEST) || state.isOf(EndBlocks.SILK_MOTH_HIVE)) {
int fullness = state.get(BlockProperties.FULLNESS);
boolean isHive = state.isOf(EndBlocks.SILK_MOTH_HIVE);
if (state.is(EndBlocks.SILK_MOTH_NEST) || state.is(EndBlocks.SILK_MOTH_HIVE)) {
int fullness = state.getValue(BlockProperties.FULLNESS);
boolean isHive = state.is(EndBlocks.SILK_MOTH_HIVE);
if (fullness < 3 && (isHive || SilkMothEntity.this.random.nextBoolean())) {
fullness += isHive ? MHelper.randRange(1, 2, random) : 1;
if (fullness > 3) {
fullness = 3;
}
BlocksHelper.setWithUpdate(SilkMothEntity.this.hiveWorld, SilkMothEntity.this.hivePos, state.with(BlockProperties.FULLNESS, fullness));
BlocksHelper.setWithUpdate(SilkMothEntity.this.hiveWorld, SilkMothEntity.this.hivePos,
state.with(BlockProperties.FULLNESS, fullness));
}
SilkMothEntity.this.world.playSound(null, SilkMothEntity.this.entrance, SoundEvents.BLOCK_BEEHIVE_ENTER, SoundCategory.BLOCKS, 1, 1);
SilkMothEntity.this.world.playLocalSound(null, SilkMothEntity.this.entrance,
SoundEvents.BLOCK_BEEHIVE_ENTER, SoundSource.BLOCKS, 1, 1);
SilkMothEntity.this.remove();
}
else {
} else {
SilkMothEntity.this.hivePos = null;
}
}

View file

@ -5,18 +5,18 @@ import java.util.function.Function;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.entity.model.EntityModel;
import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier;
import net.minecraft.world.entity.Entity;
import net.minecraft.resources.ResourceLocation;
public abstract class BlockBenchModel<T extends Entity> extends EntityModel<T> {
public BlockBenchModel() {
super();
}
public BlockBenchModel(Function<Identifier, RenderLayer> function) {
public BlockBenchModel(Function<ResourceLocation, RenderLayer> function) {
super(function);
}
protected void setRotationAngle(ModelPart modelRenderer, float x, float y, float z) {
modelRenderer.pitch = x;
modelRenderer.yaw = y;

View file

@ -4,7 +4,7 @@ import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;
import ru.betterend.entity.CubozoaEntity;
public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
@ -23,10 +23,10 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
public CubozoaEntityModel() {
super(RenderLayer::getEntityTranslucent);
textureWidth = 48;
textureHeight = 48;
model = new ModelPart(this);
model.setPivot(0.0F, 24.0F, 0.0F);
model.setTextureOffset(0, 17).addCuboid(-2.0F, -12.5F, -2.0F, 4.0F, 4.0F, 4.0F, 0.0F);
@ -40,7 +40,6 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
tentacle_center_1 = new ModelPart(this);
tentacle_center_1.setPivot(0.0F, 0.0F, 0.0F);
model.addChild(tentacle_center_1);
tentacle_1 = new ModelPart(this);
tentacle_1.setPivot(0.0F, -7.0F, 4.5F);
@ -51,7 +50,6 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
tentacle_center_2.setPivot(0.0F, 0.0F, 0.0F);
model.addChild(tentacle_center_2);
setRotationAngle(tentacle_center_2, 0.0F, -1.5708F, 0.0F);
tentacle_2 = new ModelPart(this);
tentacle_2.setPivot(0.0F, -7.0F, 4.5F);
@ -62,7 +60,6 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
tentacle_center_3.setPivot(0.0F, 0.0F, 0.0F);
model.addChild(tentacle_center_3);
setRotationAngle(tentacle_center_3, 0.0F, 3.1416F, 0.0F);
tentacle_3 = new ModelPart(this);
tentacle_3.setPivot(0.0F, -7.0F, 4.5F);
@ -73,20 +70,20 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
tentacle_center_4.setPivot(0.0F, 0.0F, 0.0F);
model.addChild(tentacle_center_4);
setRotationAngle(tentacle_center_4, 0.0F, 1.5708F, 0.0F);
tentacle_4 = new ModelPart(this);
tentacle_4.setPivot(0.0F, -7.0F, 4.5F);
tentacle_center_4.addChild(tentacle_4);
tentacle_4.setTextureOffset(16, 17).addCuboid(-4.0F, 0.0F, 0.0F, 8.0F, 7.0F, 0.0F, 0.0F);
}
@Override
public void setAngles(CubozoaEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
float sin = MathHelper.sin(animationProgress * 0.13F);
public void setAngles(CubozoaEntity entity, float limbAngle, float limbDistance, float animationProgress,
float headYaw, float headPitch) {
float sin = Mth.sin(animationProgress * 0.13F);
scaleY = sin * 0.1F + 0.9F;
scaleXZ = MathHelper.sin(animationProgress * 0.13F + 3.14F) * 0.1F + 0.9F;
scaleXZ = Mth.sin(animationProgress * 0.13F + 3.14F) * 0.1F + 0.9F;
tentacle_1.pitch = sin * 0.15F;
tentacle_2.pitch = sin * 0.15F;
tentacle_3.pitch = sin * 0.15F;
@ -94,7 +91,8 @@ public class CubozoaEntityModel extends BlockBenchModel<CubozoaEntity> {
}
@Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green,
float blue, float alpha) {
matrices.push();
matrices.scale(scaleXZ, scaleY, scaleXZ);
model.render(matrices, vertices, light, overlay);

View file

@ -4,7 +4,7 @@ import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.Mth;
import ru.betterend.entity.SilkMothEntity;
public class SilkMothEntityModel extends BlockBenchModel<SilkMothEntity> {
@ -26,7 +26,7 @@ public class SilkMothEntityModel extends BlockBenchModel<SilkMothEntity> {
public SilkMothEntityModel() {
super(RenderLayer::getEntityCutout);
textureWidth = 64;
textureHeight = 64;
@ -113,22 +113,22 @@ public class SilkMothEntityModel extends BlockBenchModel<SilkMothEntity> {
abdomen_r1.setTextureOffset(0, 10).addCuboid(-3.0F, -4.0F, -1.0F, 4.0F, 4.0F, 7.0F, 0.0F);
}
@Override
public void setAngles(SilkMothEntity entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
wingR_r1.roll = MathHelper.sin(animationProgress * 2F) * 0.4F + 0.3927F;
public void setAngles(SilkMothEntity entity, float limbAngle, float limbDistance, float animationProgress,
float headYaw, float headPitch) {
wingR_r1.roll = Mth.sin(animationProgress * 2F) * 0.4F + 0.3927F;
wingL_r1.roll = -wingR_r1.roll;
head_pivot.pitch = MathHelper.sin(animationProgress * 0.03F) * 0.1F;
tendril_r_r1.roll = MathHelper.sin(animationProgress * 0.07F) * 0.2F + 0.3927F;
head_pivot.pitch = Mth.sin(animationProgress * 0.03F) * 0.1F;
tendril_r_r1.roll = Mth.sin(animationProgress * 0.07F) * 0.2F + 0.3927F;
tendril_r_r2.roll = -tendril_r_r1.roll;
abdomen_r1.pitch = MathHelper.sin(animationProgress * 0.05F) * 0.1F - 0.3927F;
legsR.roll = MathHelper.sin(animationProgress * 0.07F) * 0.1F - 0.6545F;
abdomen_r1.pitch = Mth.sin(animationProgress * 0.05F) * 0.1F - 0.3927F;
legsR.roll = Mth.sin(animationProgress * 0.07F) * 0.1F - 0.6545F;
legsL.roll = -legsR.roll;
}
@Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green,
float blue, float alpha) {
bb_main.render(matrices, vertices, light, overlay);
head_pivot.render(matrices, vertices, light, overlay);
legsL.render(matrices, vertices, light, overlay);

View file

@ -8,13 +8,13 @@ import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.render.entity.feature.EyesFeatureRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd;
import ru.betterend.entity.CubozoaEntity;
import ru.betterend.entity.model.CubozoaEntityModel;
public class RendererEntityCubozoa extends MobEntityRenderer<CubozoaEntity, CubozoaEntityModel> {
private static final Identifier[] TEXTURE = new Identifier[2];
private static final ResourceLocation[] TEXTURE = new ResourceLocation[2];
private static final RenderLayer[] GLOW = new RenderLayer[2];
public RendererEntityCubozoa(EntityRenderDispatcher entityRenderDispatcher) {
@ -26,11 +26,14 @@ public class RendererEntityCubozoa extends MobEntityRenderer<CubozoaEntity, Cubo
}
@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CubozoaEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light,
CubozoaEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress,
float headYaw, float headPitch) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getVariant()]);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F,
1.0F, 1.0F);
}
});
});
}
@Override
@ -40,14 +43,14 @@ public class RendererEntityCubozoa extends MobEntityRenderer<CubozoaEntity, Cubo
}
@Override
public Identifier getTexture(CubozoaEntity entity) {
public ResourceLocation getTexture(CubozoaEntity entity) {
return TEXTURE[entity.getVariant()];
}
static {
TEXTURE[0] = BetterEnd.makeID("textures/entity/cubozoa/cubozoa.png");
TEXTURE[1] = BetterEnd.makeID("textures/entity/cubozoa/cubozoa_sulphur.png");
GLOW[0] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_glow.png"));
GLOW[1] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/cubozoa/cubozoa_sulphur_glow.png"));
}

View file

@ -4,27 +4,27 @@ import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.render.entity.feature.EyesFeatureRenderer;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd;
import ru.betterend.entity.DragonflyEntity;
import ru.betterend.entity.model.DragonflyEntityModel;
public class RendererEntityDragonfly extends MobEntityRenderer<DragonflyEntity, DragonflyEntityModel> {
private static final Identifier TEXTURE = BetterEnd.makeID("textures/entity/dragonfly.png");
private static final RenderLayer GLOW = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/dragonfly_glow.png"));
private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/dragonfly.png");
private static final RenderLayer GLOW = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/dragonfly_glow.png"));
public RendererEntityDragonfly(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new DragonflyEntityModel(), 0.5f);
this.addFeature(new EyesFeatureRenderer<DragonflyEntity, DragonflyEntityModel>(this) {
@Override
public RenderLayer getEyesTexture() {
return GLOW;
}
@Override
public RenderLayer getEyesTexture() {
return GLOW;
}
});
}
@Override
public Identifier getTexture(DragonflyEntity entity) {
public ResourceLocation getTexture(DragonflyEntity entity) {
return TEXTURE;
}
}

View file

@ -8,46 +8,49 @@ import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.client.render.entity.feature.EyesFeatureRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd;
import ru.betterend.entity.EndFishEntity;
import ru.betterend.entity.model.EndFishEntityModel;
public class RendererEntityEndFish extends MobEntityRenderer<EndFishEntity, EndFishEntityModel> {
private static final Identifier[] TEXTURE = new Identifier[EndFishEntity.VARIANTS];
private static final ResourceLocation[] TEXTURE = new ResourceLocation[EndFishEntity.VARIANTS];
private static final RenderLayer[] GLOW = new RenderLayer[EndFishEntity.VARIANTS];
public RendererEntityEndFish(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new EndFishEntityModel(), 0.5f);
this.addFeature(new EyesFeatureRenderer<EndFishEntity, EndFishEntityModel>(this) {
public RendererEntityEndFish(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new EndFishEntityModel(), 0.5f);
this.addFeature(new EyesFeatureRenderer<EndFishEntity, EndFishEntityModel>(this) {
@Override
public RenderLayer getEyesTexture() {
return GLOW[0];
}
@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, EndFishEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light,
EndFishEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress,
float headYaw, float headPitch) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getVariant()]);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F,
1.0F, 1.0F);
}
});
}
@Override
});
}
@Override
protected void scale(EndFishEntity entity, MatrixStack matrixStack, float f) {
float scale = entity.getScale();
matrixStack.scale(scale, scale, scale);
}
@Override
public Identifier getTexture(EndFishEntity entity) {
return TEXTURE[entity.getVariant()];
}
static {
for (int i = 0; i < EndFishEntity.VARIANTS; i++) {
TEXTURE[i] = BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + ".png");
GLOW[i] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + "_glow.png"));
}
}
@Override
public ResourceLocation getTexture(EndFishEntity entity) {
return TEXTURE[entity.getVariant()];
}
static {
for (int i = 0; i < EndFishEntity.VARIANTS; i++) {
TEXTURE[i] = BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + ".png");
GLOW[i] = RenderLayer.getEyes(BetterEnd.makeID("textures/entity/end_fish/end_fish_" + i + "_glow.png"));
}
}
}

View file

@ -11,43 +11,47 @@ import net.minecraft.client.render.entity.feature.EyesFeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import ru.betterend.BetterEnd;
import ru.betterend.entity.EndSlimeEntity;
import ru.betterend.entity.model.EndSlimeEntityModel;
public class RendererEntityEndSlime extends MobEntityRenderer<EndSlimeEntity, EndSlimeEntityModel<EndSlimeEntity>> {
private static final Identifier TEXTURE[] = new Identifier[4];
private static final ResourceLocation TEXTURE[] = new ResourceLocation[4];
private static final RenderLayer GLOW[] = new RenderLayer[4];
public RendererEntityEndSlime(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new EndSlimeEntityModel<EndSlimeEntity>(false), 0.25F);
this.addFeature(new OverlayFeatureRenderer<EndSlimeEntity>(this));
this.addFeature(new EyesFeatureRenderer<EndSlimeEntity, EndSlimeEntityModel<EndSlimeEntity>>(this) {
public RendererEntityEndSlime(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new EndSlimeEntityModel<EndSlimeEntity>(false), 0.25F);
this.addFeature(new OverlayFeatureRenderer<EndSlimeEntity>(this));
this.addFeature(new EyesFeatureRenderer<EndSlimeEntity, EndSlimeEntityModel<EndSlimeEntity>>(this) {
@Override
public RenderLayer getEyesTexture() {
return GLOW[0];
}
@Override
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, EndSlimeEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light,
EndSlimeEntity entity, float limbAngle, float limbDistance, float tickDelta,
float animationProgress, float headYaw, float headPitch) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(GLOW[entity.getSlimeType()]);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
this.getContextModel().render(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F,
1.0F, 1.0F);
if (entity.isLake()) {
this.getContextModel().renderFlower(matrices, vertexConsumer, 15728640, OverlayTexture.DEFAULT_UV);
}
}
});
}
});
}
@Override
public Identifier getTexture(EndSlimeEntity entity) {
public ResourceLocation getTexture(EndSlimeEntity entity) {
return TEXTURE[entity.getSlimeType()];
}
@Override
public void render(EndSlimeEntity slimeEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
public void render(EndSlimeEntity slimeEntity, float f, float g, MatrixStack matrixStack,
VertexConsumerProvider vertexConsumerProvider, int i) {
this.shadowRadius = 0.25F * (float) slimeEntity.getSize();
super.render(slimeEntity, f, g, matrixStack, vertexConsumerProvider, i);
}
@ -57,12 +61,13 @@ public class RendererEntityEndSlime extends MobEntityRenderer<EndSlimeEntity, En
matrixStack.scale(0.999F, 0.999F, 0.999F);
matrixStack.translate(0.0D, 0.0010000000474974513D, 0.0D);
float h = (float) slimeEntity.getSize();
float i = MathHelper.lerp(f, slimeEntity.lastStretch, slimeEntity.stretch) / (h * 0.5F + 1.0F);
float i = Mth.lerp(f, slimeEntity.lastStretch, slimeEntity.stretch) / (h * 0.5F + 1.0F);
float j = 1.0F / (i + 1.0F);
matrixStack.scale(j * h, 1.0F / j * h, j * h);
}
private final class OverlayFeatureRenderer<T extends EndSlimeEntity> extends FeatureRenderer<T, EndSlimeEntityModel<T>> {
private final class OverlayFeatureRenderer<T extends EndSlimeEntity>
extends FeatureRenderer<T, EndSlimeEntityModel<T>> {
private final EndSlimeEntityModel<T> modelOrdinal = new EndSlimeEntityModel<T>(true);
private final EndSlimeEntityModel<T> modelLake = new EndSlimeEntityModel<T>(true);
@ -70,27 +75,33 @@ public class RendererEntityEndSlime extends MobEntityRenderer<EndSlimeEntity, En
super(featureRendererContext);
}
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i,
T livingEntity, float f, float g, float h, float j, float k, float l) {
if (!livingEntity.isInvisible()) {
if (livingEntity.isLake()) {
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity)));
this.getContextModel().renderFlower(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0F));
VertexConsumer vertexConsumer = vertexConsumerProvider
.getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity)));
this.getContextModel().renderFlower(matrixStack, vertexConsumer, i,
LivingEntityRenderer.getOverlay(livingEntity, 0.0F));
} else if (livingEntity.isAmber() || livingEntity.isChorus()) {
VertexConsumer vertexConsumer = vertexConsumerProvider
.getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity)));
this.getContextModel().renderCrop(matrixStack, vertexConsumer, i,
LivingEntityRenderer.getOverlay(livingEntity, 0.0F));
}
else if (livingEntity.isAmber() || livingEntity.isChorus()) {
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(this.getTexture(livingEntity)));
this.getContextModel().renderCrop(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0F));
}
EndSlimeEntityModel<T> model = livingEntity.getSlimeType() == 1 ? modelLake : modelOrdinal;
this.getContextModel().copyStateTo(model);
model.animateModel(livingEntity, f, g, h);
model.setAngles(livingEntity, f, g, j, k, l);
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityTranslucent(this.getTexture(livingEntity)));
model.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0F), 1.0F, 1.0F, 1.0F, 1.0F);
VertexConsumer vertexConsumer = vertexConsumerProvider
.getBuffer(RenderLayer.getEntityTranslucent(this.getTexture(livingEntity)));
model.render(matrixStack, vertexConsumer, i, LivingEntityRenderer.getOverlay(livingEntity, 0.0F), 1.0F,
1.0F, 1.0F, 1.0F);
}
}
}
static {
TEXTURE[0] = BetterEnd.makeID("textures/entity/end_slime/end_slime.png");
TEXTURE[1] = BetterEnd.makeID("textures/entity/end_slime/end_slime_mossy.png");

View file

@ -3,19 +3,20 @@ package ru.betterend.entity.render;
import net.minecraft.client.render.entity.BipedEntityRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd;
import ru.betterend.entity.ShadowWalkerEntity;
public class RendererEntityShadowWalker extends BipedEntityRenderer<ShadowWalkerEntity, PlayerEntityModel<ShadowWalkerEntity>> {
private static final Identifier TEXTURE = BetterEnd.makeID("textures/entity/shadow_walker.png");
public class RendererEntityShadowWalker
extends BipedEntityRenderer<ShadowWalkerEntity, PlayerEntityModel<ShadowWalkerEntity>> {
private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/shadow_walker.png");
public RendererEntityShadowWalker(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new PlayerEntityModel<ShadowWalkerEntity>(0.0F, false), 0.5F);
}
@Override
public Identifier getTexture(ShadowWalkerEntity zombieEntity) {
public ResourceLocation getTexture(ShadowWalkerEntity zombieEntity) {
return TEXTURE;
}
}

View file

@ -2,20 +2,20 @@ package ru.betterend.entity.render;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.util.Identifier;
import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd;
import ru.betterend.entity.SilkMothEntity;
import ru.betterend.entity.model.SilkMothEntityModel;
public class SilkMothEntityRenderer extends MobEntityRenderer<SilkMothEntity, SilkMothEntityModel> {
private static final Identifier TEXTURE = BetterEnd.makeID("textures/entity/silk_moth.png");
private static final ResourceLocation TEXTURE = BetterEnd.makeID("textures/entity/silk_moth.png");
public SilkMothEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher, new SilkMothEntityModel(), 0.5f);
}
@Override
public Identifier getTexture(SilkMothEntity entity) {
public ResourceLocation getTexture(SilkMothEntity entity) {
return TEXTURE;
}
}