Code style changes, entities fixes

This commit is contained in:
paulevsGitch 2021-07-08 00:21:47 +03:00
parent 9d604b2d25
commit 44962e18b6
377 changed files with 5038 additions and 4914 deletions

View file

@ -1,8 +1,5 @@
package ru.betterend.entity;
import java.util.List;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
@ -30,25 +27,28 @@ import ru.bclib.api.BiomeAPI;
import ru.betterend.registry.EndBiomes;
import ru.betterend.registry.EndItems;
import java.util.List;
import java.util.Random;
public class EndFishEntity extends AbstractSchoolingFish {
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 EntityDataAccessor<Byte> VARIANT = SynchedEntityData.defineId(EndFishEntity.class, EntityDataSerializers.BYTE);
private static final EntityDataAccessor<Byte> SCALE = SynchedEntityData.defineId(EndFishEntity.class, EntityDataSerializers.BYTE);
public EndFishEntity(EntityType<EndFishEntity> entityType, Level world) {
super(entityType, world);
}
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType spawnReason, SpawnGroupData entityData, CompoundTag entityTag) {
SpawnGroupData data = super.finalizeSpawn(world, difficulty, spawnReason, entityData, entityTag);
if (BiomeAPI.getFromBiome(world.getBiome(blockPosition())) == EndBiomes.SULPHUR_SPRINGS) {
this.entityData.set(VARIANT, (byte) (random.nextInt(VARIANTS_SULPHUR) + VARIANTS_NORMAL));
}
if (entityTag != null) {
if (entityTag.contains("Variant")) {
this.entityData.set(VARIANT, entityTag.getByte("variant"));
@ -57,18 +57,18 @@ public class EndFishEntity extends AbstractSchoolingFish {
this.entityData.set(SCALE, entityTag.getByte("scale"));
}
}
this.refreshDimensions();
return data;
}
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.entityData.define(VARIANT, (byte) this.getRandom().nextInt(VARIANTS_NORMAL));
this.entityData.define(SCALE, (byte) this.getRandom().nextInt(16));
}
@Override
public void addAdditionalSaveData(CompoundTag tag) {
super.addAdditionalSaveData(tag);
@ -115,7 +115,7 @@ public class EndFishEntity extends AbstractSchoolingFish {
protected SoundEvent getHurtSound(DamageSource source) {
return SoundEvents.SALMON_HURT;
}
@Override
public void tick() {
super.tick();
@ -126,32 +126,34 @@ public class EndFishEntity extends AbstractSchoolingFish {
level.addParticle(ParticleTypes.BUBBLE, x, y, z, 0, 0, 0);
}
}
public static AttributeSupplier.Builder createMobAttributes() {
return LivingEntity.createLivingAttributes()
.add(Attributes.MAX_HEALTH, 2.0)
.add(Attributes.FOLLOW_RANGE, 16.0)
.add(Attributes.MOVEMENT_SPEED, 0.75);
}
public int getVariant() {
return (int) this.entityData.get(VARIANT);
}
public byte getByteScale() {
return this.entityData.get(SCALE);
}
public float getScale() {
return getByteScale() / 32F + 0.75F;
}
public static boolean canSpawn(EntityType<EndFishEntity> type, ServerLevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) {
AABB box = new AABB(pos).inflate(16);
List<EndFishEntity> list = world.getEntitiesOfClass(EndFishEntity.class, box, (entity) -> { return true; });
List<EndFishEntity> list = world.getEntitiesOfClass(EndFishEntity.class, box, (entity) -> {
return true;
});
return list.size() < 9;
}
@Override
protected void dropFromLootTable(DamageSource source, boolean causedByPlayer) {
ItemEntity drop = new ItemEntity(level, getX(), getY(), getZ(), new ItemStack(EndItems.END_FISH_RAW));