Skip to content

Commit

Permalink
fix: villagers using moon villagers' model (#382)
Browse files Browse the repository at this point in the history
* fix: villagers using moon villagers' model

* chore: forgot license headers oops
  • Loading branch information
JustAPotota authored Dec 22, 2024
1 parent 7d1077e commit dff802d
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 111 deletions.
13 changes: 7 additions & 6 deletions src/main/java/dev/galacticraft/mod/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/galacticraft/mod/GalacticraftClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MoonVillagerEntity, MoonVillagerModel> {
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<ResourceLocation> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<MoonVillagerEntity> {
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;
}
}
6 changes: 6 additions & 0 deletions src/main/java/dev/galacticraft/mod/content/GCEntityTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

public class GCEntityTypes {
public static final GCRegistry<EntityType<?>> ENTITIES = new GCRegistry<>(BuiltInRegistries.ENTITY_TYPE);
public static final EntityType<MoonVillagerEntity> 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<EvolvedZombieEntity> EVOLVED_ZOMBIE = ENTITIES.register(Entity.EVOLVED_ZOMBIE, FabricEntityTypeBuilder.create(MobCategory.MONSTER, EvolvedZombieEntity::new)
.dimensions(EntityDimensions.fixed(0.6F, 1.95F))
.build());
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<? extends MoonVillagerEntity> entityType, Level level) {
super(entityType, level);
}
}

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/resources/galacticraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
"client.LivingEntityRendererMixin",
"client.LocalPlayerMixin",
"client.MinecraftMixin",
"client.PauseMenuScreenMixin",
"client.VillagerModelMixin",
"client.VillagerRendererMixin"
"client.PauseMenuScreenMixin"
],
"minVersion": "0.8.0",
"injectors": {
Expand Down

0 comments on commit dff802d

Please sign in to comment.