diff --git a/common/src/main/java/com/craisinlord/antarchy/content/client/model/ScorpionModel.java b/common/src/main/java/com/craisinlord/antarchy/content/client/model/ScorpionModel.java index 5b23cbc6..c408ff34 100644 --- a/common/src/main/java/com/craisinlord/antarchy/content/client/model/ScorpionModel.java +++ b/common/src/main/java/com/craisinlord/antarchy/content/client/model/ScorpionModel.java @@ -6,19 +6,39 @@ import net.minecraft.resources.ResourceLocation; import software.bernie.geckolib.model.GeoModel; public class ScorpionModel extends GeoModel { + private static final ResourceLocation MODEL = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "geo/scorpion.geo.json"); + private static final ResourceLocation BLUE_TEXTURE = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "textures/entity/scorpion/scorpion_blue.png"); + private static final ResourceLocation GREEN_TEXTURE = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "textures/entity/scorpion/scorpion_green.png"); + private static final ResourceLocation BLUE_EMISSIVE_TEXTURE = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "textures/entity/scorpion/scorpion_blue_emissive.png"); + private static final ResourceLocation GREEN_EMISSIVE_TEXTURE = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "textures/entity/scorpion/scorpion_green_emissive.png"); + private static final ResourceLocation ANIMATION = + ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "animations/scorpion.animation.json"); @Override public ResourceLocation getModelResource(ScorpionEntity animatable) { - return ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "geo/scorpion.geo.json"); + return MODEL; } @Override public ResourceLocation getTextureResource(ScorpionEntity animatable) { - return ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "textures/entity/scorpion.png"); + return textureFor(animatable); } @Override public ResourceLocation getAnimationResource(ScorpionEntity animatable) { - return ResourceLocation.fromNamespaceAndPath(Antarchy.MODID, "animations/scorpion.animation.json"); + return ANIMATION; + } + + public static ResourceLocation textureFor(ScorpionEntity animatable) { + return animatable.getTextureVariant() == ScorpionEntity.GREEN_VARIANT ? GREEN_TEXTURE : BLUE_TEXTURE; + } + + public static ResourceLocation emissiveTextureFor(ScorpionEntity animatable) { + return animatable.getTextureVariant() == ScorpionEntity.GREEN_VARIANT ? GREEN_EMISSIVE_TEXTURE : BLUE_EMISSIVE_TEXTURE; } } diff --git a/common/src/main/java/com/craisinlord/antarchy/content/client/renderer/ScorpionRenderer.java b/common/src/main/java/com/craisinlord/antarchy/content/client/renderer/ScorpionRenderer.java index 892679a9..c37d5202 100644 --- a/common/src/main/java/com/craisinlord/antarchy/content/client/renderer/ScorpionRenderer.java +++ b/common/src/main/java/com/craisinlord/antarchy/content/client/renderer/ScorpionRenderer.java @@ -2,13 +2,53 @@ package com.craisinlord.antarchy.content.client.renderer; import com.craisinlord.antarchy.content.client.model.ScorpionModel; import com.craisinlord.antarchy.content.entity.ScorpionEntity; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.texture.OverlayTexture; +import org.jetbrains.annotations.Nullable; +import software.bernie.geckolib.cache.object.BakedGeoModel; import software.bernie.geckolib.renderer.GeoEntityRenderer; +import software.bernie.geckolib.renderer.layer.GeoRenderLayer; public class ScorpionRenderer extends GeoEntityRenderer { public ScorpionRenderer(EntityRendererProvider.Context context) { super(context, new ScorpionModel()); this.shadowRadius = 0.6F; + this.addRenderLayer(new ScorpionEmissiveLayer(this)); + } + + @Override + public RenderType getRenderType(ScorpionEntity animatable, net.minecraft.resources.ResourceLocation texture, @Nullable MultiBufferSource bufferSource, float partialTick) { + return RenderType.entityCutoutNoCull(texture); + } + + private static final class ScorpionEmissiveLayer extends GeoRenderLayer { + private ScorpionEmissiveLayer(GeoEntityRenderer renderer) { + super(renderer); + } + + @Override + public void render(PoseStack poseStack, ScorpionEntity animatable, BakedGeoModel bakedModel, @Nullable RenderType renderType, + MultiBufferSource bufferSource, @Nullable VertexConsumer buffer, float partialTick, + int packedLight, int packedOverlay) { + RenderType emissiveType = RenderType.eyes(ScorpionModel.emissiveTextureFor(animatable)); + VertexConsumer emissiveBuffer = bufferSource.getBuffer(emissiveType); + this.getRenderer().reRender( + bakedModel, + poseStack, + bufferSource, + animatable, + emissiveType, + emissiveBuffer, + partialTick, + 0xF000F0, + OverlayTexture.NO_OVERLAY, + 0xFFFFFFFF + ); + } } } diff --git a/common/src/main/java/com/craisinlord/antarchy/content/entity/ScorpionEntity.java b/common/src/main/java/com/craisinlord/antarchy/content/entity/ScorpionEntity.java index 16999635..40437f18 100644 --- a/common/src/main/java/com/craisinlord/antarchy/content/entity/ScorpionEntity.java +++ b/common/src/main/java/com/craisinlord/antarchy/content/entity/ScorpionEntity.java @@ -2,8 +2,13 @@ package com.craisinlord.antarchy.content.entity; import com.craisinlord.antarchy.content.AntarchySoundEvents; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.RandomSource; +import net.minecraft.world.DifficultyInstance; import net.minecraft.world.Difficulty; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; @@ -13,6 +18,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.SpawnGroupData; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.goal.FloatGoal; @@ -39,6 +45,11 @@ import org.jetbrains.annotations.Nullable; public class ScorpionEntity extends Monster implements GeoEntity { private static final byte ATTACK_ANIM_EVENT = 4; + private static final EntityDataAccessor TEXTURE_VARIANT = + SynchedEntityData.defineId(ScorpionEntity.class, EntityDataSerializers.INT); + private static final String TEXTURE_VARIANT_KEY = "TextureVariant"; + public static final int BLUE_VARIANT = 0; + public static final int GREEN_VARIANT = 1; private static final int ATTACK_ANIM_TICKS = 12; private static final int ATTACK_HIT_TICK = 6; @@ -82,6 +93,12 @@ public class ScorpionEntity extends Monster implements GeoEntity { && Monster.checkMonsterSpawnRules(entityType, level, spawnReason, pos, random); } + @Override + protected void defineSynchedData(SynchedEntityData.Builder builder) { + super.defineSynchedData(builder); + builder.define(TEXTURE_VARIANT, BLUE_VARIANT); + } + @Override protected void registerGoals() { this.goalSelector.addGoal(0, new FloatGoal(this)); @@ -93,6 +110,13 @@ public class ScorpionEntity extends Monster implements GeoEntity { this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true)); } + @Nullable + @Override + public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) { + this.assignRandomTextureVariant(); + return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData); + } + @Override public void tick() { super.tick(); @@ -208,6 +232,22 @@ public class ScorpionEntity extends Monster implements GeoEntity { return this.geoCache; } + @Override + public void addAdditionalSaveData(CompoundTag tag) { + super.addAdditionalSaveData(tag); + tag.putInt(TEXTURE_VARIANT_KEY, this.getTextureVariant()); + } + + @Override + public void readAdditionalSaveData(CompoundTag tag) { + super.readAdditionalSaveData(tag); + if (tag.contains(TEXTURE_VARIANT_KEY)) { + this.setTextureVariant(tag.getInt(TEXTURE_VARIANT_KEY)); + } else { + this.assignRandomTextureVariant(); + } + } + @Override protected SoundEvent getAmbientSound() { return AntarchySoundEvents.SCORPION_AMBIENT.get(); @@ -228,6 +268,18 @@ public class ScorpionEntity extends Monster implements GeoEntity { return 0.6F; } + public int getTextureVariant() { + return this.entityData.get(TEXTURE_VARIANT); + } + + public void setTextureVariant(int variant) { + this.entityData.set(TEXTURE_VARIANT, variant == GREEN_VARIANT ? GREEN_VARIANT : BLUE_VARIANT); + } + + private void assignRandomTextureVariant() { + this.setTextureVariant(this.random.nextBoolean() ? BLUE_VARIANT : GREEN_VARIANT); + } + private final class ScorpionMeleeAttackGoal extends MeleeAttackGoal { private ScorpionMeleeAttackGoal() { super(ScorpionEntity.this, 1.15D, true); diff --git a/common/src/main/java/com/craisinlord/antarchy/content/entity/nightmare/NightmareEntity.java b/common/src/main/java/com/craisinlord/antarchy/content/entity/nightmare/NightmareEntity.java index 6c296799..93ffbfed 100644 --- a/common/src/main/java/com/craisinlord/antarchy/content/entity/nightmare/NightmareEntity.java +++ b/common/src/main/java/com/craisinlord/antarchy/content/entity/nightmare/NightmareEntity.java @@ -82,6 +82,7 @@ public class NightmareEntity extends Monster implements GeoEntity { private static final int COMBAT_ROAR_TICKS = 30; private static final int DEATH_TICKS = 30; private static final int TARGET_RESET_TICKS = 60; + private static final int MIN_AIRBORNE_TICKS_FOR_FLY_ANIM = 4; private static final int DREAD_TICKS = 160; private static final int WEAKNESS_TICKS = 100; private static final int BLOCK_BREAK_TICKS = 10; @@ -644,23 +645,18 @@ public class NightmareEntity extends Monster implements GeoEntity { return; } if (this.attackAnimationTicks > 0) { - this.setAnimationState(this.onGround() ? ANIM_ATTACK : ANIM_FLY_ATTACK); + this.setAnimationState(this.isNoGravity() || this.airborneTicks >= MIN_AIRBORNE_TICKS_FOR_FLY_ANIM ? ANIM_FLY_ATTACK : ANIM_ATTACK); this.groundMoveTicks = 0; this.tickWingFlapSound(); return; } if (this.flyingToTarget) { this.groundMoveTicks = 0; - if (this.onGround() || this.airborneTicks <= 8) { - this.setAnimationState(ANIM_FLY); - this.wingFlapCooldown = 0; - } else { - this.setAnimationState(ANIM_FLY); - this.tickWingFlapSound(); - } + this.setAnimationState(ANIM_FLY); + this.tickWingFlapSound(); return; } - if (!this.onGround()) { + if (this.isNoGravity() || this.airborneTicks >= MIN_AIRBORNE_TICKS_FOR_FLY_ANIM) { this.groundMoveTicks = 0; this.setAnimationState(ANIM_FLY); this.tickWingFlapSound(); diff --git a/common/src/main/resources/assets/antarchy/geo/scorpion.geo.json b/common/src/main/resources/assets/antarchy/geo/scorpion.geo.json index a52b3951..0e3340b6 100644 --- a/common/src/main/resources/assets/antarchy/geo/scorpion.geo.json +++ b/common/src/main/resources/assets/antarchy/geo/scorpion.geo.json @@ -99,7 +99,7 @@ "pivot": [1, 1, 24], "cubes": [ {"origin": [-5, 1, 24], "size": [10, 7, 8], "inflate": 0.01, "uv": [28, 35]}, - {"origin": [-0.5, 8, 28], "size": [1, 5, 3], "inflate": 0.01, "uv": [28, 35]} + {"origin": [-0.5, 8, 28], "size": [1, 8, 3], "uv": [28, 50]} ] }, { diff --git a/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up1.mp3 b/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up1.mp3 new file mode 100644 index 00000000..3232ca89 Binary files /dev/null and b/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up1.mp3 differ diff --git a/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up2.mp3 b/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up2.mp3 new file mode 100644 index 00000000..f0cca377 Binary files /dev/null and b/common/src/main/resources/assets/antarchy/sounds/mob/toreterror/jump up2.mp3 differ diff --git a/common/src/main/resources/assets/antarchy/textures/entity/scorpion.png b/common/src/main/resources/assets/antarchy/textures/entity/scorpion.png deleted file mode 100644 index 9c93d54c..00000000 Binary files a/common/src/main/resources/assets/antarchy/textures/entity/scorpion.png and /dev/null differ diff --git a/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue.png b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue.png new file mode 100644 index 00000000..658b7180 Binary files /dev/null and b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue.png differ diff --git a/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue_emissive.png b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue_emissive.png new file mode 100644 index 00000000..a7ee1708 Binary files /dev/null and b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_blue_emissive.png differ diff --git a/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green.png b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green.png new file mode 100644 index 00000000..8737db9b Binary files /dev/null and b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green.png differ diff --git a/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green_emissive.png b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green_emissive.png new file mode 100644 index 00000000..03dc179d Binary files /dev/null and b/common/src/main/resources/assets/antarchy/textures/entity/scorpion/scorpion_green_emissive.png differ