From 5a703151eb680a80c62691647bbc113edaa9071b Mon Sep 17 00:00:00 2001 From: Meredith Espinosa Date: Fri, 18 Oct 2019 23:40:33 -0700 Subject: [PATCH] clean up renderer, add armor stand support --- build.gradle | 6 +- gradle.properties | 8 +- gradlew | 0 .../lemons/villagerhats/VillagerHats.java | 12 --- .../client/PlayerVillagerHatRenderLayer.java | 6 +- .../villagerhats/client/VillagerHatModel.java | 85 +++++++++++++++++++ .../lemons/villagerhats/init/HatItems.java | 28 +++--- .../villagerhats/item/VillagerHatItem.java | 2 +- .../mixin/ArmorStandRenderMixin.java | 33 +++++++ src/main/resources/fabric.mod.json | 13 +-- src/main/resources/villagerhats.mixins.json | 1 + 11 files changed, 149 insertions(+), 45 deletions(-) mode change 100644 => 100755 gradlew delete mode 100644 src/main/java/party/lemons/villagerhats/VillagerHats.java create mode 100644 src/main/java/party/lemons/villagerhats/client/VillagerHatModel.java create mode 100644 src/main/java/party/lemons/villagerhats/mixin/ArmorStandRenderMixin.java diff --git a/build.gradle b/build.gradle index f7c0c66..ec03e97 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.2-SNAPSHOT' + id 'fabric-loom' version '0.2.5-SNAPSHOT' id 'maven-publish' } @@ -17,10 +17,10 @@ dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}" - modCompile "net.fabricmc:fabric-loader:${project.loader_version}" + modApi "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. - modCompile "net.fabricmc:fabric:${project.fabric_version}" + modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. diff --git a/gradle.properties b/gradle.properties index c218ad1..fb8998d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.14 - yarn_mappings=1.14+build.1 - loader_version=0.4.2+build.132 + minecraft_version=1.14.4 + yarn_mappings=1.14.4+build.14 + loader_version=0.6.3+build.167 # Mod Properties mod_version = fabric-1.14.0-1.0.0 @@ -14,4 +14,4 @@ org.gradle.jvmargs=-Xmx1G # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric - fabric_version=0.2.7+build.127 + fabric_version=0.4.1+build.245-1.14 diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/party/lemons/villagerhats/VillagerHats.java b/src/main/java/party/lemons/villagerhats/VillagerHats.java deleted file mode 100644 index 9cb1a4a..0000000 --- a/src/main/java/party/lemons/villagerhats/VillagerHats.java +++ /dev/null @@ -1,12 +0,0 @@ -package party.lemons.villagerhats; - -import net.fabricmc.api.ModInitializer; - -public class VillagerHats implements ModInitializer -{ - @Override - public void onInitialize() - { - - } -} diff --git a/src/main/java/party/lemons/villagerhats/client/PlayerVillagerHatRenderLayer.java b/src/main/java/party/lemons/villagerhats/client/PlayerVillagerHatRenderLayer.java index 35c271b..be7b8ef 100644 --- a/src/main/java/party/lemons/villagerhats/client/PlayerVillagerHatRenderLayer.java +++ b/src/main/java/party/lemons/villagerhats/client/PlayerVillagerHatRenderLayer.java @@ -35,11 +35,7 @@ public void render(T living, float x, float y, float z, float float_4, float flo GlStateManager.translated(0, 0.250D, 0); } - VillagerResemblingModel hatModel = new VillagerResemblingModel<>(0); - hatModel.cuboidList.forEach(c -> c.visible = false); - - hatModel.setHatVisible(true); - //((class_3884)hatModel).method_17150(true); + VillagerHatModel hatModel = new VillagerHatModel<>(0); this.bindTexture(this.findTexture("profession", Registry.VILLAGER_PROFESSION.getId(hat.getProfession()))); diff --git a/src/main/java/party/lemons/villagerhats/client/VillagerHatModel.java b/src/main/java/party/lemons/villagerhats/client/VillagerHatModel.java new file mode 100644 index 0000000..8b5c969 --- /dev/null +++ b/src/main/java/party/lemons/villagerhats/client/VillagerHatModel.java @@ -0,0 +1,85 @@ +package party.lemons.villagerhats.client; + +import net.minecraft.client.model.Cuboid; +import net.minecraft.client.render.entity.model.EntityModel; +import net.minecraft.client.render.entity.model.ModelWithHat; +import net.minecraft.client.render.entity.model.ModelWithHead; +import net.minecraft.entity.Entity; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.entity.passive.AbstractTraderEntity; +import net.minecraft.util.math.MathHelper; + +public class VillagerHatModel extends EntityModel implements ModelWithHead, ModelWithHat { + private Cuboid head; + private Cuboid headOverlay; + private Cuboid hat; + + public VillagerHatModel(float scale) { + this(scale, 64, 64); + } + + public VillagerHatModel(float scale, int u, int v) { + this.head = (new Cuboid(this)).setTextureSize(u, v); + this.head.setRotationPoint(0.0F, 0.0F, 0.0F); + this.head.setTextureOffset(0, 0).addBox(-4.0F, -10.0F, -4.0F, 8, 10, 8, scale); + this.headOverlay = (new Cuboid(this)).setTextureSize(u, v); + this.headOverlay.setRotationPoint(0.0F, 0.0F, 0.0F); + this.headOverlay.setTextureOffset(32, 0).addBox(-4.0F, -10.0F, -4.0F, 8, 10, 8, scale + 0.5F); + this.head.addChild(this.headOverlay); + this.hat = (new Cuboid(this)).setTextureSize(u, v); + this.hat.setRotationPoint(0.0F, 0.0F, 0.0F); + this.hat.setTextureOffset(30, 47).addBox(-8.0F, -8.0F, -6.0F, 16, 16, 1, scale); + this.hat.pitch = -1.5707964F; + this.headOverlay.addChild(this.hat); + } + + @Override + public void setHatVisible(boolean visible) { + this.head.visible = visible; + this.headOverlay.visible = visible; + this.hat.visible = visible; + } + + @Override + public void render(T entity, float float_1, float float_2, float headRoll, float headYaw, float headPitch, float scale) { + this.setAngles(entity, float_1, float_2, headRoll, headYaw, headPitch, scale); + this.head.render(scale); + } + + @Override + public void setAngles(T entity, float float_1, float float_2, float headRoll, float headYaw, float headPitch, float scale) + { + boolean isRollingHead = false; + if (entity instanceof AbstractTraderEntity) + { + isRollingHead = ((AbstractTraderEntity)entity).getHeadRollingTimeLeft() > 0; + } + + if (entity instanceof ArmorStandEntity) + { + ArmorStandEntity stand = (ArmorStandEntity) entity; + this.head.yaw = stand.getHeadRotation().getYaw() * 0.017453292F; + this.head.pitch = stand.getHeadRotation().getPitch() * 0.017453292F; + this.head.roll = stand.getHeadRotation().getRoll() * 0.017453292F; + } else + { + this.head.yaw = headYaw * 0.017453292F; + this.head.pitch = headPitch * 0.017453292F; + if (isRollingHead) + { + this.head.roll = 0.3F * MathHelper.sin(0.45F * headRoll); + this.head.pitch = 0.4F; + } else + { + this.head.roll = 0.0F; + } + } + + + } + + @Override + public Cuboid getHead() { + return head; + } +} diff --git a/src/main/java/party/lemons/villagerhats/init/HatItems.java b/src/main/java/party/lemons/villagerhats/init/HatItems.java index d9220f8..a1ccf99 100644 --- a/src/main/java/party/lemons/villagerhats/init/HatItems.java +++ b/src/main/java/party/lemons/villagerhats/init/HatItems.java @@ -10,15 +10,15 @@ public class HatItems implements ModInitializer { - public static final Item FARMER_HAT = registerItem(new VillagerHatItem(VillagerProfession.FARMER), "farmer_hat"); - public static final Item ARMORER_HAT = registerItem(new VillagerHatItem(VillagerProfession.ARMORER), "armorer_hat"); - public static final Item BUTCHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.BUTCHER), "butcher_hat"); - public static final Item CARTOGRAPHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.CARTOGRAPHER), "cartographer_hat"); - public static final Item FISHERMAN_HAT = registerItem(new VillagerHatItem(VillagerProfession.FISHERMAN), "fisherman_hat"); - public static final Item FLETCHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.FLETCHER), "fletcher_hat"); - public static final Item LIBRARIAN_HAT = registerItem(new VillagerHatItem(VillagerProfession.LIBRARIAN), "librarian_hat"); - public static final Item SHEPHERD_HAT = registerItem(new VillagerHatItem(VillagerProfession.SHEPHERD), "shepherd_hat"); - public static final Item WEAPONSMITH_HAT = registerItem(new VillagerHatItem(VillagerProfession.WEAPONSMITH), "weaponsmith_hat"); + public static Item FARMER_HAT; + public static Item ARMORER_HAT; + public static Item BUTCHER_HAT; + public static Item CARTOGRAPHER_HAT; + public static Item FISHERMAN_HAT; + public static Item FLETCHER_HAT; + public static Item LIBRARIAN_HAT; + public static Item SHEPHERD_HAT; + public static Item WEAPONSMITH_HAT; public static Item registerItem(Item item, String name) { @@ -29,6 +29,14 @@ public static Item registerItem(Item item, String name) @Override public void onInitialize() { - + FARMER_HAT = registerItem(new VillagerHatItem(VillagerProfession.FARMER), "farmer_hat"); + ARMORER_HAT = registerItem(new VillagerHatItem(VillagerProfession.ARMORER), "armorer_hat"); + BUTCHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.BUTCHER), "butcher_hat"); + CARTOGRAPHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.CARTOGRAPHER), "cartographer_hat"); + FISHERMAN_HAT = registerItem(new VillagerHatItem(VillagerProfession.FISHERMAN), "fisherman_hat"); + FLETCHER_HAT = registerItem(new VillagerHatItem(VillagerProfession.FLETCHER), "fletcher_hat"); + LIBRARIAN_HAT = registerItem(new VillagerHatItem(VillagerProfession.LIBRARIAN), "librarian_hat"); + SHEPHERD_HAT = registerItem(new VillagerHatItem(VillagerProfession.SHEPHERD), "shepherd_hat"); + WEAPONSMITH_HAT = registerItem(new VillagerHatItem(VillagerProfession.WEAPONSMITH), "weaponsmith_hat"); } } diff --git a/src/main/java/party/lemons/villagerhats/item/VillagerHatItem.java b/src/main/java/party/lemons/villagerhats/item/VillagerHatItem.java index 23e422d..05c2de4 100644 --- a/src/main/java/party/lemons/villagerhats/item/VillagerHatItem.java +++ b/src/main/java/party/lemons/villagerhats/item/VillagerHatItem.java @@ -11,7 +11,7 @@ public class VillagerHatItem extends ArmorItem public VillagerHatItem(VillagerProfession profession) { - super(VillagerArmorMaterial.INSTANCE, EquipmentSlot.HEAD, new Settings().itemGroup(ItemGroup.COMBAT)); + super(VillagerArmorMaterial.INSTANCE, EquipmentSlot.HEAD, new Settings().group(ItemGroup.COMBAT)); this.profession = profession; } diff --git a/src/main/java/party/lemons/villagerhats/mixin/ArmorStandRenderMixin.java b/src/main/java/party/lemons/villagerhats/mixin/ArmorStandRenderMixin.java new file mode 100644 index 0000000..57bafa0 --- /dev/null +++ b/src/main/java/party/lemons/villagerhats/mixin/ArmorStandRenderMixin.java @@ -0,0 +1,33 @@ +package party.lemons.villagerhats.mixin; + +import net.minecraft.client.render.entity.ArmorStandEntityRenderer; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.LivingEntityRenderer; +import net.minecraft.client.render.entity.model.ArmorStandEntityModel; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import party.lemons.villagerhats.client.PlayerVillagerHatRenderLayer; + +@Mixin(ArmorStandEntityRenderer.class) +public class ArmorStandRenderMixin extends LivingEntityRenderer { + public ArmorStandRenderMixin(EntityRenderDispatcher entityRenderDispatcher_1, ArmorStandEntityModel entityModel_1, float float_1) + { + super(entityRenderDispatcher_1, entityModel_1, float_1); + } + + @Inject(at = @At("RETURN"), method = "") + public void onConstruct(EntityRenderDispatcher dispatcher, CallbackInfo info) + { + this.addFeature(new PlayerVillagerHatRenderLayer<>(this)); + } + + @Override + protected Identifier getTexture(ArmorStandEntity armorStandEntity) + { + return null; + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 447c3de..9d034e7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,12 +6,9 @@ "name": "Villager Hats", "description": "Adds wearable villager hats! Hot Damn!", "authors": [ - "Me!" + "Lemonszz", + "B0undarybreaker" ], - "contact": { - "homepage": "", - "sources": "" - }, "license": "MIT", "icon": "assets/villagerhats/icon.png", @@ -19,7 +16,6 @@ "environment": "*", "entrypoints": { "main": [ - "party.lemons.villagerhats.VillagerHats", "party.lemons.villagerhats.init.HatItems" ] }, @@ -27,11 +23,8 @@ "villagerhats.mixins.json" ], - "requires": { + "depends": { "fabricloader": ">=0.4.0", "fabric": "*" - }, - "suggests": { - "flamingo": "*" } } diff --git a/src/main/resources/villagerhats.mixins.json b/src/main/resources/villagerhats.mixins.json index bdb06b7..de63df4 100644 --- a/src/main/resources/villagerhats.mixins.json +++ b/src/main/resources/villagerhats.mixins.json @@ -5,6 +5,7 @@ "mixins": [ ], "client": [ + "ArmorStandRenderMixin", "PlayerRenderMixin" ], "injectors": {