Skip to content

Commit

Permalink
Merge pull request #1 from Boundarybreaker/master
Browse files Browse the repository at this point in the history
clean up renderer, add armor stand support
  • Loading branch information
Shnupbups committed Oct 19, 2019
2 parents a50f5ee + 5a70315 commit 475aaa3
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 45 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.2.2-SNAPSHOT'
id 'fabric-loom' version '0.2.5-SNAPSHOT'
id 'maven-publish'
}

Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Empty file modified gradlew
100644 → 100755
Empty file.
12 changes: 0 additions & 12 deletions src/main/java/party/lemons/villagerhats/VillagerHats.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<T> hatModel = new VillagerResemblingModel<>(0);
hatModel.cuboidList.forEach(c -> c.visible = false);

hatModel.setHatVisible(true);
//((class_3884)hatModel).method_17150(true);
VillagerHatModel<T> hatModel = new VillagerHatModel<>(0);

this.bindTexture(this.findTexture("profession", Registry.VILLAGER_PROFESSION.getId(hat.getProfession())));

Expand Down
Original file line number Diff line number Diff line change
@@ -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<T extends Entity> extends EntityModel<T> 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;
}
}
28 changes: 18 additions & 10 deletions src/main/java/party/lemons/villagerhats/init/HatItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArmorStandEntity, ArmorStandEntityModel> {
public ArmorStandRenderMixin(EntityRenderDispatcher entityRenderDispatcher_1, ArmorStandEntityModel entityModel_1, float float_1)
{
super(entityRenderDispatcher_1, entityModel_1, float_1);
}

@Inject(at = @At("RETURN"), method = "<init>")
public void onConstruct(EntityRenderDispatcher dispatcher, CallbackInfo info)
{
this.addFeature(new PlayerVillagerHatRenderLayer<>(this));
}

@Override
protected Identifier getTexture(ArmorStandEntity armorStandEntity)
{
return null;
}
}
13 changes: 3 additions & 10 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,25 @@
"name": "Villager Hats",
"description": "Adds wearable villager hats! Hot Damn!",
"authors": [
"Me!"
"Lemonszz",
"B0undarybreaker"
],
"contact": {
"homepage": "",
"sources": ""
},

"license": "MIT",
"icon": "assets/villagerhats/icon.png",

"environment": "*",
"entrypoints": {
"main": [
"party.lemons.villagerhats.VillagerHats",
"party.lemons.villagerhats.init.HatItems"
]
},
"mixins": [
"villagerhats.mixins.json"
],

"requires": {
"depends": {
"fabricloader": ">=0.4.0",
"fabric": "*"
},
"suggests": {
"flamingo": "*"
}
}
1 change: 1 addition & 0 deletions src/main/resources/villagerhats.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"mixins": [
],
"client": [
"ArmorStandRenderMixin",
"PlayerRenderMixin"
],
"injectors": {
Expand Down

0 comments on commit 475aaa3

Please sign in to comment.