all hail the minilith
This commit is contained in:
parent
bcf5e45d01
commit
28aff1da1c
3 changed files with 91 additions and 37 deletions
|
@ -54,10 +54,15 @@ public class MonolithRenderer extends MobEntityRenderer<MonolithEntity, Monolith
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MonolithEntity mobEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
|
public void render(MonolithEntity mobEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
|
||||||
super.render(mobEntity, f, g, matrixStack, vertexConsumerProvider, i);
|
super.render(mobEntity, f, g, matrixStack, vertexConsumerProvider, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected void scale(MonolithEntity entity, MatrixStack matrices, float amount) {
|
||||||
|
matrices.scale(entity.getScale(), entity.getScale(), entity.getScale());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected boolean hasLabel(MonolithEntity mobEntity) {
|
protected boolean hasLabel(MonolithEntity mobEntity) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,13 @@ public class ModEntityTypes {
|
||||||
public static final EntityType<MonolithEntity> MONOLITH = register(
|
public static final EntityType<MonolithEntity> MONOLITH = register(
|
||||||
"dimdoors:monolith",
|
"dimdoors:monolith",
|
||||||
MonolithEntity::new,
|
MonolithEntity::new,
|
||||||
3, 3
|
2f, 2.7f, false
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final EntityType<MaskEntity> MASK = register(
|
public static final EntityType<MaskEntity> MASK = register(
|
||||||
"dimdoors:mask",
|
"dimdoors:mask",
|
||||||
MaskEntity::new,
|
MaskEntity::new,
|
||||||
0.9375f, 0.9375f
|
0.9375f, 0.9375f, true
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
@ -39,7 +39,7 @@ public class ModEntityTypes {
|
||||||
EntityRendererRegistry.INSTANCE.register(MASK, MaskRenderer::new);
|
EntityRendererRegistry.INSTANCE.register(MASK, MaskRenderer::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <E extends Entity> EntityType<E> register(String id, EntityType.EntityFactory<E> factory, float width, float height) {
|
private static <E extends Entity> EntityType<E> register(String id, EntityType.EntityFactory<E> factory, float width, float height, boolean fixed) {
|
||||||
return Registry.register(Registry.ENTITY_TYPE, id, FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, factory).dimensions(EntityDimensions.fixed(width, height)).spawnableFarFromPlayer().fireImmune().build());
|
return Registry.register(Registry.ENTITY_TYPE, id, FabricEntityTypeBuilder.create(SpawnGroup.MONSTER, factory).dimensions(new EntityDimensions(width, height, fixed)).spawnableFarFromPlayer().fireImmune().build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package org.dimdev.dimdoors.entity;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.util.NbtType;
|
||||||
|
import net.minecraft.util.math.Box;
|
||||||
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
|
||||||
import org.dimdev.dimdoors.entity.ai.MonolithAggroGoal;
|
import org.dimdev.dimdoors.entity.ai.MonolithAggroGoal;
|
||||||
import org.dimdev.dimdoors.item.ModItems;
|
import org.dimdev.dimdoors.item.ModItems;
|
||||||
|
@ -34,8 +36,6 @@ import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
public class MonolithEntity extends MobEntity {
|
public class MonolithEntity extends MobEntity {
|
||||||
public final EntityDimensions DIMENSIONS = EntityDimensions.fixed(3f, 6f);
|
|
||||||
|
|
||||||
public static final int MAX_AGGRO = 250;
|
public static final int MAX_AGGRO = 250;
|
||||||
private static final int MAX_AGGRO_CAP = 100;
|
private static final int MAX_AGGRO_CAP = 100;
|
||||||
private static final int MIN_AGGRO_CAP = 25;
|
private static final int MIN_AGGRO_CAP = 25;
|
||||||
|
@ -43,11 +43,12 @@ public class MonolithEntity extends MobEntity {
|
||||||
private static final int MAX_SOUND_COOLDOWN = 200;
|
private static final int MAX_SOUND_COOLDOWN = 200;
|
||||||
public static final int MAX_AGGRO_RANGE = 35;
|
public static final int MAX_AGGRO_RANGE = 35;
|
||||||
private static final TrackedData<Integer> AGGRO = DataTracker.registerData(MonolithEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
private static final TrackedData<Integer> AGGRO = DataTracker.registerData(MonolithEntity.class, TrackedDataHandlerRegistry.INTEGER);
|
||||||
private static final float EYE_HEIGHT = 1.5f;
|
private static final TrackedData<Float> SCALE = DataTracker.registerData(MonolithEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
private static Random random;
|
private static final TrackedData<Float> PITCH = DataTracker.registerData(MonolithEntity.class, TrackedDataHandlerRegistry.FLOAT);
|
||||||
|
private static final float EYE_HEIGHT_PERCENTAGE = 0.55f;
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
private static final Random clientRandom = new Random();
|
||||||
|
|
||||||
public float pitchLevel;
|
|
||||||
private int aggro = 0;
|
|
||||||
private int soundTime = 0;
|
private int soundTime = 0;
|
||||||
private final int aggroCap;
|
private final int aggroCap;
|
||||||
|
|
||||||
|
@ -57,7 +58,6 @@ public class MonolithEntity extends MobEntity {
|
||||||
|
|
||||||
public MonolithEntity(EntityType<? extends MonolithEntity> type, World world) {
|
public MonolithEntity(EntityType<? extends MonolithEntity> type, World world) {
|
||||||
super(ModEntityTypes.MONOLITH, world);
|
super(ModEntityTypes.MONOLITH, world);
|
||||||
random = this.getRandom();
|
|
||||||
this.noClip = true;
|
this.noClip = true;
|
||||||
this.aggroCap = MathHelper.nextInt(this.getRandom(), MIN_AGGRO_CAP, MAX_AGGRO_CAP);
|
this.aggroCap = MathHelper.nextInt(this.getRandom(), MIN_AGGRO_CAP, MAX_AGGRO_CAP);
|
||||||
this.setNoGravity(true);
|
this.setNoGravity(true);
|
||||||
|
@ -71,10 +71,6 @@ public class MonolithEntity extends MobEntity {
|
||||||
this.setInvulnerable(true);
|
this.setInvulnerable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityDimensions getDimensions(EntityPose entityPose) {
|
|
||||||
return this.DIMENSIONS;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDangerous() {
|
public boolean isDangerous() {
|
||||||
return DimensionalDoorsInitializer.getConfig().getMonolithsConfig().monolithTeleportation && (ModDimensions.isLimboDimension(this.world) || DimensionalDoorsInitializer.getConfig().getMonolithsConfig().dangerousLimboMonoliths);
|
return DimensionalDoorsInitializer.getConfig().getMonolithsConfig().monolithTeleportation && (ModDimensions.isLimboDimension(this.world) || DimensionalDoorsInitializer.getConfig().getMonolithsConfig().dangerousLimboMonoliths);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +78,7 @@ public class MonolithEntity extends MobEntity {
|
||||||
@Override
|
@Override
|
||||||
public boolean damage(DamageSource source, float amount) {
|
public boolean damage(DamageSource source, float amount) {
|
||||||
if (source != DamageSource.IN_WALL) {
|
if (source != DamageSource.IN_WALL) {
|
||||||
this.aggro = MAX_AGGRO;
|
setAggro(MAX_AGGRO);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +118,9 @@ public class MonolithEntity extends MobEntity {
|
||||||
super.initDataTracker();
|
super.initDataTracker();
|
||||||
// Add a short for the aggro level
|
// Add a short for the aggro level
|
||||||
this.dataTracker.startTracking(AGGRO, 0);
|
this.dataTracker.startTracking(AGGRO, 0);
|
||||||
|
this.dataTracker.startTracking(SCALE, 1f);
|
||||||
|
this.dataTracker.startTracking(PITCH, 1f);
|
||||||
|
this.calculateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -210,8 +209,9 @@ public class MonolithEntity extends MobEntity {
|
||||||
*/
|
*/
|
||||||
public void playSounds(Vec3d pos) {
|
public void playSounds(Vec3d pos) {
|
||||||
float aggroPercent = this.getAggroProgress();
|
float aggroPercent = this.getAggroProgress();
|
||||||
|
float pitch = getPitch();
|
||||||
if (this.soundTime <= 0) {
|
if (this.soundTime <= 0) {
|
||||||
this.playSound(ModSoundEvents.MONK, 1F, 1F);
|
this.playSound(ModSoundEvents.MONK, 1F, pitch);
|
||||||
this.soundTime = 100;
|
this.soundTime = 100;
|
||||||
}
|
}
|
||||||
if (aggroPercent > 0.70 && this.soundTime < 100) {
|
if (aggroPercent > 0.70 && this.soundTime < 100) {
|
||||||
|
@ -219,7 +219,7 @@ public class MonolithEntity extends MobEntity {
|
||||||
this.soundTime = 100 + this.getRandom().nextInt(75);
|
this.soundTime = 100 + this.getRandom().nextInt(75);
|
||||||
}
|
}
|
||||||
if (aggroPercent > 0.80 && this.soundTime < MAX_SOUND_COOLDOWN) {
|
if (aggroPercent > 0.80 && this.soundTime < MAX_SOUND_COOLDOWN) {
|
||||||
this.world.playSound(null, new BlockPos(pos), ModSoundEvents.TEARING, SoundCategory.HOSTILE, 7, 1F);
|
this.world.playSound(null, new BlockPos(pos), ModSoundEvents.TEARING, SoundCategory.HOSTILE, 7, 1);
|
||||||
this.soundTime = 250;
|
this.soundTime = 250;
|
||||||
}
|
}
|
||||||
this.soundTime--;
|
this.soundTime--;
|
||||||
|
@ -227,10 +227,15 @@ public class MonolithEntity extends MobEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getEyeHeight(EntityPose entityPose) {
|
public float getEyeHeight(EntityPose entityPose) {
|
||||||
return EYE_HEIGHT;
|
return getDimensions(entityPose).height * EYE_HEIGHT_PERCENTAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Override
|
||||||
|
protected float getActiveEyeHeight(EntityPose pose, EntityDimensions dimensions) {
|
||||||
|
return getDimensions(pose).height * EYE_HEIGHT_PERCENTAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
public static void spawnParticles(int aggro) {
|
public static void spawnParticles(int aggro) {
|
||||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
if (aggro < 120) {
|
if (aggro < 120) {
|
||||||
|
@ -239,16 +244,16 @@ public class MonolithEntity extends MobEntity {
|
||||||
int count = 10 * aggro / MAX_AGGRO;
|
int count = 10 * aggro / MAX_AGGRO;
|
||||||
for (int i = 1; i < count; ++i) {
|
for (int i = 1; i < count; ++i) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
player.world.addParticle(ParticleTypes.PORTAL, player.getX() + (random.nextDouble() - 0.5D) * 3.0,
|
player.world.addParticle(ParticleTypes.PORTAL, player.getX() + (clientRandom.nextDouble() - 0.5D) * 3.0,
|
||||||
player.getY() + random.nextDouble() * player.getHeight() - 0.75D,
|
player.getY() + clientRandom.nextDouble() * player.getHeight() - 0.75D,
|
||||||
player.getZ() + (random.nextDouble() - 0.5D) * player.getWidth(),
|
player.getZ() + (clientRandom.nextDouble() - 0.5D) * player.getWidth(),
|
||||||
(random.nextDouble() - 0.5D) * 2.0D, -random.nextDouble(),
|
(clientRandom.nextDouble() - 0.5D) * 2.0D, -clientRandom.nextDouble(),
|
||||||
(random.nextDouble() - 0.5D) * 2.0D);
|
(clientRandom.nextDouble() - 0.5D) * 2.0D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getAggroProgress() {
|
public float getAggroProgress() {
|
||||||
return (float) this.aggro / MAX_AGGRO;
|
return ((float) getAggro()) / MAX_AGGRO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -262,19 +267,26 @@ public class MonolithEntity extends MobEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NbtCompound writeNbt(NbtCompound nbt) {
|
public void writeCustomDataToNbt(NbtCompound nbt) {
|
||||||
super.writeNbt(nbt);
|
super.writeCustomDataToNbt(nbt);
|
||||||
nbt.putInt("Aggro", this.aggro);
|
nbt.putInt("Aggro", getAggro());
|
||||||
return nbt;
|
nbt.putFloat("scale", getScale());
|
||||||
|
nbt.putFloat("pitch", getPitch());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readNbt(NbtCompound nbt) {
|
public void readCustomDataFromNbt(NbtCompound nbt) {
|
||||||
super.readNbt(nbt);
|
super.readCustomDataFromNbt(nbt);
|
||||||
this.aggro = nbt.getInt("Aggro");
|
setAggro(nbt.getInt("Aggro"));
|
||||||
|
if (nbt.contains("scale", NbtType.FLOAT)) {
|
||||||
|
setScale(nbt.getFloat("scale"));
|
||||||
|
}
|
||||||
|
if (nbt.contains("pitch", NbtType.FLOAT)) {
|
||||||
|
setPitch(nbt.getFloat("pitch"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAggro() {
|
public int getAggro() {
|
||||||
return this.dataTracker.get(AGGRO);
|
return this.dataTracker.get(AGGRO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +294,44 @@ public class MonolithEntity extends MobEntity {
|
||||||
this.dataTracker.set(AGGRO, aggro);
|
this.dataTracker.set(AGGRO, aggro);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public float getScaleFactor() {
|
||||||
|
return getScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getScale() {
|
||||||
|
return this.dataTracker.get(SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScale(float scale) {
|
||||||
|
this.dataTracker.set(SCALE, scale);
|
||||||
|
calculateDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPitch() {
|
||||||
|
return this.dataTracker.get(PITCH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPitch(float pitch) {
|
||||||
|
this.dataTracker.set(PITCH, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Box getBoundingBox(EntityPose pose) {
|
||||||
|
float scale = getScale();
|
||||||
|
return super.getBoundingBox(pose).stretch(scale, scale, scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackedDataSet(TrackedData<?> data) {
|
||||||
|
if (SCALE.equals(data)) {
|
||||||
|
this.calculateDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onTrackedDataSet(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canSpawn(WorldAccess world, SpawnReason spawnReason) {
|
public boolean canSpawn(WorldAccess world, SpawnReason spawnReason) {
|
||||||
if (spawnReason == SpawnReason.CHUNK_GENERATION) {
|
if (spawnReason == SpawnReason.CHUNK_GENERATION) {
|
||||||
return super.canSpawn(world, spawnReason);
|
return super.canSpawn(world, spawnReason);
|
||||||
|
|
Loading…
Reference in a new issue