From dff802d81e05e4933a66fc79efa4b1fa21d33eda Mon Sep 17 00:00:00 2001 From: JustAPotota <43710172+JustAPotota@users.noreply.github.com> Date: Sun, 22 Dec 2024 13:53:18 -0600 Subject: [PATCH] fix: villagers using moon villagers' model (#382) * fix: villagers using moon villagers' model * chore: forgot license headers oops --- .../java/dev/galacticraft/mod/Constant.java | 13 +-- .../galacticraft/mod/GalacticraftClient.java | 1 + .../render/entity/MoonVillagerRenderer.java} | 32 ++++--- .../entity/model/GCEntityModelLayer.java | 2 + .../entity/model/MoonVillagerModel.java | 68 +++++++++++++++ .../mod/content/GCEntityTypes.java | 6 ++ .../content/entity/MoonVillagerEntity.java | 33 +++++++ .../mod/mixin/client/VillagerModelMixin.java | 85 ------------------- src/main/resources/galacticraft.mixins.json | 4 +- 9 files changed, 133 insertions(+), 111 deletions(-) rename src/main/java/dev/galacticraft/mod/{mixin/client/VillagerRendererMixin.java => client/render/entity/MoonVillagerRenderer.java} (54%) create mode 100644 src/main/java/dev/galacticraft/mod/client/render/entity/model/MoonVillagerModel.java create mode 100644 src/main/java/dev/galacticraft/mod/content/entity/MoonVillagerEntity.java delete mode 100644 src/main/java/dev/galacticraft/mod/mixin/client/VillagerModelMixin.java diff --git a/src/main/java/dev/galacticraft/mod/Constant.java b/src/main/java/dev/galacticraft/mod/Constant.java index 532ebcd68..3625aff85 100644 --- a/src/main/java/dev/galacticraft/mod/Constant.java +++ b/src/main/java/dev/galacticraft/mod/Constant.java @@ -573,26 +573,27 @@ interface SlotSprite { } interface Entity { + String MOON_VILLAGER = "moon_villager"; String EVOLVED_ZOMBIE = "evolved_zombie"; String EVOLVED_CREEPER = "evolved_creeper"; + String EVOLVED_SKELETON = "evolved_skeleton"; + String EVOLVED_SPIDER = "evolved_spider"; + String EVOLVED_PILLAGER = "evolved_pillager"; + String EVOLVED_EVOKER = "evolved_evoker"; + String EVOLVED_VINDICATOR = "evolved_vindicator"; String T1_ROCKET = "t1_rocket"; String ROCKET = "rocket"; String LANDER = "lander"; String BUGGY = "buggy"; String PARACHEST = "parachest"; String BUBBLE = "bubble"; - String EVOLVED_SKELETON = "evolved_skeleton"; - String EVOLVED_SPIDER = "evolved_spider"; - String EVOLVED_PILLAGER = "evolved_pillager"; - String EVOLVED_EVOKER = "evolved_evoker"; - String EVOLVED_VINDICATOR = "evolved_vindicator"; - String EVOLVED_SKELETON_BOSS = "evolved_skeleton_boss"; String GREY = "grey"; String ARCH_GREY = "arch_grey"; String RUMBLER = "rumbler"; String OLI_GRUB = "oli_grub"; String COMET_CUBE = "comet_cube"; String GAZER = "gazer"; + String EVOLVED_SKELETON_BOSS = "evolved_skeleton_boss"; } interface EntityTexture { diff --git a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java index 95f068685..9f0e02bfa 100644 --- a/src/main/java/dev/galacticraft/mod/GalacticraftClient.java +++ b/src/main/java/dev/galacticraft/mod/GalacticraftClient.java @@ -107,6 +107,7 @@ public void onInitializeClient() { MenuScreens.register(GCMenuTypes.ROCKET, RocketInventoryScreen::new); MenuScreens.register(GCMenuTypes.PARACHEST, ParachestScreen::new); + EntityRendererRegistry.register(GCEntityTypes.MOON_VILLAGER, MoonVillagerRenderer::new); EntityRendererRegistry.register(GCEntityTypes.EVOLVED_ZOMBIE, EvolvedZombieRenderer::new); EntityRendererRegistry.register(GCEntityTypes.EVOLVED_CREEPER, EvolvedCreeperEntityRenderer::new); EntityRendererRegistry.register(GCEntityTypes.EVOLVED_SKELETON, EvolvedSkeletonEntityRenderer::new); diff --git a/src/main/java/dev/galacticraft/mod/mixin/client/VillagerRendererMixin.java b/src/main/java/dev/galacticraft/mod/client/render/entity/MoonVillagerRenderer.java similarity index 54% rename from src/main/java/dev/galacticraft/mod/mixin/client/VillagerRendererMixin.java rename to src/main/java/dev/galacticraft/mod/client/render/entity/MoonVillagerRenderer.java index 93d339e10..2c853c304 100644 --- a/src/main/java/dev/galacticraft/mod/mixin/client/VillagerRendererMixin.java +++ b/src/main/java/dev/galacticraft/mod/client/render/entity/MoonVillagerRenderer.java @@ -20,30 +20,28 @@ * SOFTWARE. */ -package dev.galacticraft.mod.mixin.client; +package dev.galacticraft.mod.client.render.entity; import dev.galacticraft.mod.Constant; -import dev.galacticraft.mod.village.MoonVillagerTypes; +import dev.galacticraft.mod.client.render.entity.model.GCEntityModelLayer; +import dev.galacticraft.mod.client.render.entity.model.MoonVillagerModel; +import dev.galacticraft.mod.content.entity.MoonVillagerEntity; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.renderer.entity.VillagerRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.npc.Villager; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(VillagerRenderer.class) @Environment(EnvType.CLIENT) -public abstract class VillagerRendererMixin { - private static final @Unique ResourceLocation MOON_TEXTURE = Constant.id("textures/entity/villager/moon_villager.png"); +public class MoonVillagerRenderer extends MobRenderer { + private static final ResourceLocation BASE_TEXTURE = Constant.id("textures/entity/villager/moon_villager.png"); - @Inject(method = "getTextureLocation(Lnet/minecraft/world/entity/npc/Villager;)Lnet/minecraft/resources/ResourceLocation;", at = @At("HEAD"), cancellable = true) - private void getMoonTexture_gc(Villager villagerEntity, CallbackInfoReturnable cir) { - if (MoonVillagerTypes.MOON_VILLAGER_TYPE_REGISTRY.contains(villagerEntity.getVillagerData().getType())) { - cir.setReturnValue(MOON_TEXTURE); - } + public MoonVillagerRenderer(EntityRendererProvider.Context context) { + super(context, new MoonVillagerModel(context.bakeLayer(GCEntityModelLayer.MOON_VILLAGER)), 0.5f); + } + + @Override + public ResourceLocation getTextureLocation(MoonVillagerEntity entityGoalInfo) { + return BASE_TEXTURE; } } diff --git a/src/main/java/dev/galacticraft/mod/client/render/entity/model/GCEntityModelLayer.java b/src/main/java/dev/galacticraft/mod/client/render/entity/model/GCEntityModelLayer.java index a39074b94..f45787924 100644 --- a/src/main/java/dev/galacticraft/mod/client/render/entity/model/GCEntityModelLayer.java +++ b/src/main/java/dev/galacticraft/mod/client/render/entity/model/GCEntityModelLayer.java @@ -38,6 +38,7 @@ public class GCEntityModelLayer { public static final ModelLayerLocation SOLAR_PANEL = new ModelLayerLocation(Constant.id("solar_panel"), "main"); public static final ModelLayerLocation LANDER = new ModelLayerLocation(Constant.id("lander"), "main"); public static final ModelLayerLocation PARACHEST = new ModelLayerLocation(Constant.id("parachest"), "main"); + public static final ModelLayerLocation MOON_VILLAGER = new ModelLayerLocation(Constant.id("moon_villager"), "main"); // Bosses public static final ModelLayerLocation SKELETON_BOSS = new ModelLayerLocation(Constant.id("skeleton_boss"), "main"); @@ -50,6 +51,7 @@ public static void register() { EntityModelLayerRegistry.registerModelLayer(ARCH_GREY, ArchGreyEntityModel::createBodyLayer); EntityModelLayerRegistry.registerModelLayer(LANDER, LanderModel::createBodyLayer); EntityModelLayerRegistry.registerModelLayer(PARACHEST, ParachestModel::createParachuteLayer); + EntityModelLayerRegistry.registerModelLayer(MOON_VILLAGER, MoonVillagerModel::createBodyLayer); EntityModelLayerRegistry.registerModelLayer(SKELETON_BOSS, EvolvedSkeletonBossModel::createBodyLayer); diff --git a/src/main/java/dev/galacticraft/mod/client/render/entity/model/MoonVillagerModel.java b/src/main/java/dev/galacticraft/mod/client/render/entity/model/MoonVillagerModel.java new file mode 100644 index 000000000..da92f9dc0 --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/client/render/entity/model/MoonVillagerModel.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.client.render.entity.model; + +import dev.galacticraft.mod.Constant; +import dev.galacticraft.mod.content.entity.MoonVillagerEntity; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.model.VillagerModel; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.model.geom.PartNames; +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.model.geom.builders.CubeListBuilder; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraft.client.model.geom.builders.MeshDefinition; + +@Environment(EnvType.CLIENT) +public class MoonVillagerModel extends VillagerModel { + private final ModelPart hat; + private final ModelPart hatRim; + private final ModelPart jacket; + + public MoonVillagerModel(ModelPart modelPart) { + super(modelPart); + this.hat = modelPart.getChild("head").getChild("hat"); + this.hatRim = this.hat.getChild("hat_rim"); + this.jacket = modelPart.getChild("body").getChild("jacket"); + } + + public static LayerDefinition createBodyLayer() { + MeshDefinition mesh = VillagerModel.createBodyModel(); + mesh.getRoot().getChild(PartNames.HEAD).addOrReplaceChild( + Constant.ModelPartName.MOON_VILLAGER_BRAIN, + CubeListBuilder.create().texOffs(0, 38).addBox(-5.0F, -16.0F, -5.0F, 10.0F, 8.0F, 10.0F), + PartPose.ZERO + ); + + return LayerDefinition.create(mesh, 64, 64); + } + + @Override + public void setupAnim(MoonVillagerEntity entityGoalInfo, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) { + super.setupAnim(entityGoalInfo, limbAngle, limbDistance, animationProgress, headYaw, headPitch); + this.hat.visible = false; + this.hatRim.visible = false; + this.jacket.visible = false; + } +} diff --git a/src/main/java/dev/galacticraft/mod/content/GCEntityTypes.java b/src/main/java/dev/galacticraft/mod/content/GCEntityTypes.java index 7ac263272..d4149be7c 100644 --- a/src/main/java/dev/galacticraft/mod/content/GCEntityTypes.java +++ b/src/main/java/dev/galacticraft/mod/content/GCEntityTypes.java @@ -39,6 +39,11 @@ public class GCEntityTypes { public static final GCRegistry> ENTITIES = new GCRegistry<>(BuiltInRegistries.ENTITY_TYPE); + public static final EntityType MOON_VILLAGER = ENTITIES.register(Entity.MOON_VILLAGER, EntityType.Builder.of(MoonVillagerEntity::new, MobCategory.MISC) + .sized(0.6F, 1.95F) + .eyeHeight(1.62F) + .clientTrackingRange(10) + .build()); public static final EntityType EVOLVED_ZOMBIE = ENTITIES.register(Entity.EVOLVED_ZOMBIE, FabricEntityTypeBuilder.create(MobCategory.MONSTER, EvolvedZombieEntity::new) .dimensions(EntityDimensions.fixed(0.6F, 1.95F)) .build()); @@ -123,6 +128,7 @@ public class GCEntityTypes { .build()); public static void register() { + FabricDefaultAttributeRegistry.register(MOON_VILLAGER, MoonVillagerEntity.createMobAttributes().add(GcApiEntityAttributes.CAN_BREATHE_IN_SPACE, 1.0D)); FabricDefaultAttributeRegistry.register(EVOLVED_ZOMBIE, EvolvedZombieEntity.createAttributes().add(GcApiEntityAttributes.CAN_BREATHE_IN_SPACE, 1.0D).add(Attributes.MOVEMENT_SPEED, 0.35D).add(Attributes.MAX_HEALTH, 30.0D)); FabricDefaultAttributeRegistry.register(EVOLVED_CREEPER, EvolvedCreeperEntity.createAttributes().add(GcApiEntityAttributes.CAN_BREATHE_IN_SPACE, 1.0D)); FabricDefaultAttributeRegistry.register(EVOLVED_SKELETON, EvolvedSkeletonEntity.createAttributes().add(GcApiEntityAttributes.CAN_BREATHE_IN_SPACE, 1.0D).add(Attributes.MAX_HEALTH, 25.0D)); diff --git a/src/main/java/dev/galacticraft/mod/content/entity/MoonVillagerEntity.java b/src/main/java/dev/galacticraft/mod/content/entity/MoonVillagerEntity.java new file mode 100644 index 000000000..73d5b89cb --- /dev/null +++ b/src/main/java/dev/galacticraft/mod/content/entity/MoonVillagerEntity.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019-2024 Team Galacticraft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.galacticraft.mod.content.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.npc.Villager; +import net.minecraft.world.level.Level; + +public class MoonVillagerEntity extends Villager { + public MoonVillagerEntity(EntityType entityType, Level level) { + super(entityType, level); + } +} diff --git a/src/main/java/dev/galacticraft/mod/mixin/client/VillagerModelMixin.java b/src/main/java/dev/galacticraft/mod/mixin/client/VillagerModelMixin.java deleted file mode 100644 index d8464c38c..000000000 --- a/src/main/java/dev/galacticraft/mod/mixin/client/VillagerModelMixin.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019-2024 Team Galacticraft - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package dev.galacticraft.mod.mixin.client; - -import dev.galacticraft.mod.Constant; -import dev.galacticraft.mod.village.MoonVillagerTypes; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.model.VillagerModel; -import net.minecraft.client.model.geom.ModelPart; -import net.minecraft.client.model.geom.PartNames; -import net.minecraft.client.model.geom.PartPose; -import net.minecraft.client.model.geom.builders.CubeListBuilder; -import net.minecraft.client.model.geom.builders.MeshDefinition; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.npc.Villager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.NoSuchElementException; - -@Mixin(VillagerModel.class) -@Environment(EnvType.CLIENT) -public abstract class VillagerModelMixin { - @Shadow public abstract void hatVisible(boolean visible); - @Shadow @Final private ModelPart head; - - private @Unique ModelPart brain = null; - - @Inject(method = "", at = @At(value = "RETURN")) - private void getModelData_gc(ModelPart root, CallbackInfo ci) { - try { - this.brain = root.getChild(PartNames.HEAD).getChild(Constant.ModelPartName.MOON_VILLAGER_BRAIN); - } catch (NoSuchElementException ignore) {} - } - - @Inject(method = "createBodyModel", at = @At(value = "RETURN")) - private static void getModelData_gc(CallbackInfoReturnable cir) { - cir.getReturnValue().getRoot().getChild(PartNames.HEAD).addOrReplaceChild(Constant.ModelPartName.MOON_VILLAGER_BRAIN, CubeListBuilder.create().texOffs(0, 38).addBox(-5.0F, -16.0F, -5.0F, 10.0F, 8.0F, 10.0F), PartPose.ZERO); - } - - @Inject(method = "setupAnim", at = @At(value = "RETURN")) - private void getModelData_gc(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch, CallbackInfo ci) { - if (entity instanceof Villager villager) { - if (MoonVillagerTypes.MOON_VILLAGER_TYPE_REGISTRY.contains(villager.getVillagerData().getType())) { - assert brain != null; - - this.hatVisible(false); - this.brain.visible = this.head.visible; - this.brain.yRot = this.head.yRot; - this.brain.xRot = this.head.xRot; - this.brain.x = this.head.x; - this.brain.y = this.head.y; - this.brain.z = this.head.z; - this.brain.zRot = this.head.zRot; - } - } - } -} diff --git a/src/main/resources/galacticraft.mixins.json b/src/main/resources/galacticraft.mixins.json index 8cdbcf18c..7532bf2f6 100644 --- a/src/main/resources/galacticraft.mixins.json +++ b/src/main/resources/galacticraft.mixins.json @@ -40,9 +40,7 @@ "client.LivingEntityRendererMixin", "client.LocalPlayerMixin", "client.MinecraftMixin", - "client.PauseMenuScreenMixin", - "client.VillagerModelMixin", - "client.VillagerRendererMixin" + "client.PauseMenuScreenMixin" ], "minVersion": "0.8.0", "injectors": {