Skip to content

Commit

Permalink
allow protection on wolf armor, add enchantment glint, tweak netherit…
Browse files Browse the repository at this point in the history
…e recipe to require blacksmith station, 1.4.0 v bump
  • Loading branch information
Draylar committed Jul 17, 2020
1 parent 8927a8d commit 2543337
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 23 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = project.mod_version + "-" + project.minecraft_version
group = project.maven_group

minecraft {
accessWidener "src/main/resources/wolveswitharmor.accesswidener"
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.8.8+build.202
fabric_version=0.13.1+build.370-1.16

# Mod Properties
mod_version=1.3.0
mod_version=1.4.0
maven_group=draylar
archives_base_name=wolves-with-armor

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/draylar/wolveswitharmor/client/WolfArmorModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package draylar.wolveswitharmor.client;

import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.entity.model.WolfEntityModel;
import net.minecraft.entity.passive.WolfEntity;

public class WolfArmorModel extends WolfEntityModel<WolfEntity> {

public WolfArmorModel(float extra) {
this.head = new ModelPart(this, 0, 0);
this.head.setPivot(-1.0F, 13.5F, -7.0F);
this.field_20788 = new ModelPart(this, 0, 0);
this.field_20788.addCuboid(-2.0F, -3.0F, -2.0F, 6.0F, 6.0F, 4.0F, extra);
this.head.addChild(this.field_20788);
this.torso = new ModelPart(this, 18, 14);
this.torso.addCuboid(-3.0F, -2.0F, -3.0F, 6.0F, 9.0F, 6.0F, extra);
this.torso.setPivot(0.0F, 14.0F, 2.0F);
this.neck = new ModelPart(this, 21, 0);
this.neck.addCuboid(-3.0F, -3.0F, -3.0F, 8.0F, 6.0F, 7.0F, extra);
this.neck.setPivot(-1.0F, 14.0F, 2.0F);
this.rightBackLeg = new ModelPart(this, 0, 18);
this.rightBackLeg.addCuboid(0.0F, 0.0F, -1.0F, 2.0F, 8.0F, 2.0F, extra);
this.rightBackLeg.setPivot(-2.5F, 16.0F, 7.0F);
this.leftBackLeg = new ModelPart(this, 0, 18);
this.leftBackLeg.addCuboid(0.0F, 0.0F, -1.0F, 2.0F, 8.0F, 2.0F, extra);
this.leftBackLeg.setPivot(0.5F, 16.0F, 7.0F);
this.rightFrontLeg = new ModelPart(this, 0, 18);
this.rightFrontLeg.addCuboid(0.0F, 0.0F, -1.0F, 2.0F, 8.0F, 2.0F, extra);
this.rightFrontLeg.setPivot(-2.5F, 16.0F, -4.0F);
this.leftFrontLeg = new ModelPart(this, 0, 18);
this.leftFrontLeg.addCuboid(0.0F, 0.0F, -1.0F, 2.0F, 8.0F, 2.0F, extra);
this.leftFrontLeg.setPivot(0.5F, 16.0F, -4.0F);
this.tail = new ModelPart(this, 9, 18);
this.tail.setPivot(-1.0F, 12.0F, 8.0F);
this.field_20789 = new ModelPart(this, 9, 18);
this.field_20789.addCuboid(0.0F, 0.0F, -1.0F, 2.0F, 8.0F, 2.0F, extra);
this.tail.addChild(this.field_20789);
this.field_20788.setTextureOffset(16, 14).addCuboid(-2.0F, -5.0F, 0.0F, 2.0F, 2.0F, 1.0F, 0.0F);
this.field_20788.setTextureOffset(16, 14).addCuboid(2.0F, -5.0F, 0.0F, 2.0F, 2.0F, 1.0F, 0.0F);
this.field_20788.setTextureOffset(0, 10).addCuboid(-0.5F, 0.0F, -5.0F, 3.0F, 3.0F, 4.0F, 0.0F);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package draylar.wolveswitharmor.client.feature;

import draylar.wolveswitharmor.WolvesWithArmor;
import draylar.wolveswitharmor.client.WolfArmorModel;
import draylar.wolveswitharmor.item.DyeableWolfArmorItem;
import draylar.wolveswitharmor.item.WolfArmorItem;
import net.fabricmc.api.EnvType;
Expand All @@ -12,14 +13,15 @@
import net.minecraft.client.render.entity.feature.FeatureRenderer;
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
import net.minecraft.client.render.entity.model.WolfEntityModel;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.passive.WolfEntity;
import net.minecraft.item.ItemStack;

@Environment(EnvType.CLIENT)
public class WolfArmorFeatureRenderer extends FeatureRenderer<WolfEntity, WolfEntityModel<WolfEntity>> {

private final WolfEntityModel<WolfEntity> model = new WolfEntityModel<>();
private final WolfArmorModel model = new WolfArmorModel(0.35f);

public WolfArmorFeatureRenderer(FeatureRendererContext<WolfEntity, WolfEntityModel<WolfEntity>> featureRendererContext) {
super(featureRendererContext);
Expand All @@ -30,7 +32,7 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
ItemStack itemStack = WolvesWithArmor.WOLF_ARMOR.get(wolfEntity).getArmor();

if (itemStack.getItem() instanceof WolfArmorItem) {
WolfArmorItem WolfArmorItem = (WolfArmorItem) itemStack.getItem();
WolfArmorItem armorItem = (WolfArmorItem) itemStack.getItem();
this.getContextModel().copyStateTo(this.model);

this.model.animateModel(wolfEntity, f, g, h);
Expand All @@ -40,8 +42,8 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
float r;
float s;

if (WolfArmorItem instanceof DyeableWolfArmorItem) {
int m = ((DyeableWolfArmorItem) WolfArmorItem).getColor(itemStack);
if (armorItem instanceof DyeableWolfArmorItem) {
int m = ((DyeableWolfArmorItem) armorItem).getColor(itemStack);
q = (float)(m >> 16 & 255) / 255.0F;
r = (float)(m >> 8 & 255) / 255.0F;
s = (float)(m & 255) / 255.0F;
Expand All @@ -51,7 +53,7 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
s = 1.0F;
}

VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutoutNoCull(WolfArmorItem.getEntityTexture()));
VertexConsumer vertexConsumer = ItemRenderer.method_27952(vertexConsumerProvider, RenderLayer.getArmorCutoutNoCull(armorItem.getEntityTexture()), false, itemStack.hasEnchantments());
this.model.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, q, r, s, 1.0F);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/draylar/wolveswitharmor/item/WolfArmorItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
Expand Down Expand Up @@ -37,8 +39,9 @@ public Identifier getEntityTexture() {
return this.entityTexture;
}

public int getBonus() {
return this.bonus;
public int getBonus(ItemStack stack) {
int protectionLevel = EnchantmentHelper.getLevel(Enchantments.PROTECTION, stack) * 2;
return this.bonus + protectionLevel;
}

@Override
Expand All @@ -48,6 +51,10 @@ public void appendTooltip(ItemStack stack, World world, List<Text> tooltip, Tool

tooltip.add(new LiteralText(""));
tooltip.add(new TranslatableText("wolveswitharmor.tooltip.when_equipped").formatted(Formatting.GRAY));
tooltip.add(new TranslatableText("wolveswitharmor.tooltip.bonus", bonus).formatted(Formatting.BLUE));
tooltip.add(new TranslatableText("wolveswitharmor.tooltip.bonus", getBonus(stack)).formatted(Formatting.BLUE));

if(stack.hasEnchantments()) {
tooltip.add(new LiteralText(""));
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/draylar/wolveswitharmor/mixin/EnchantmentMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package draylar.wolveswitharmor.mixin;

import draylar.wolveswitharmor.item.WolfArmorItem;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.ProtectionEnchantment;
import net.minecraft.item.ItemStack;
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.CallbackInfoReturnable;

@Mixin(Enchantment.class)
public class EnchantmentMixin {

@Inject(
method = "isAcceptableItem",
at = @At("HEAD"),
cancellable = true
)
private void wolfArmorProtection(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
if((Object) this instanceof ProtectionEnchantment && stack.getItem() instanceof WolfArmorItem) {
cir.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void getArmor(CallbackInfoReturnable<Integer> cir) {
ItemStack stack = WolvesWithArmor.WOLF_ARMOR.get(wolfEntity).getArmor();

if(stack.getItem() instanceof WolfArmorItem) {
cir.setReturnValue(((WolfArmorItem) stack.getItem()).getBonus());
cir.setReturnValue(((WolfArmorItem) stack.getItem()).getBonus(stack));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"dgd"
],
"key": {
"d": {
"item": "minecraft:netherite_ingot"
},
"g": {
"item": "minecraft:gold_ingot"
}
"type": "minecraft:smithing",
"base": {
"item": "wolveswitharmor:diamond_wolf_armor"
},
"addition": {
"item": "minecraft:netherite_ingot"
},
"result": {
"item": "wolveswitharmor:netherite_wolf_armor",
"count": 1
"item": "wolveswitharmor:netherite_wolf_armor"
}
}
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"mixins": [
"wolves-with-armor.mixins.json"
],
"accessWidener": "wolveswitharmor.accesswidener",
"depends": {
"fabricloader": ">=0.8.2+build.194",
"fabric": "*",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/wolves-with-armor.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "draylar.wolveswitharmor.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"EnchantmentMixin",
"LivingEntityMixin",
"WolfEntityMixin"
],
Expand Down
31 changes: 31 additions & 0 deletions src/main/resources/wolveswitharmor.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
accessWidener v1 named

accessible field net/minecraft/client/render/entity/model/WolfEntityModel head Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel head Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel field_20788 Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel field_20788 Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel torso Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel torso Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel rightBackLeg Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel rightBackLeg Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel leftBackLeg Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel leftBackLeg Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel rightFrontLeg Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel rightFrontLeg Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel leftFrontLeg Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel leftFrontLeg Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel tail Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel tail Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel field_20789 Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel field_20789 Lnet/minecraft/client/model/ModelPart;

accessible field net/minecraft/client/render/entity/model/WolfEntityModel neck Lnet/minecraft/client/model/ModelPart;
mutable field net/minecraft/client/render/entity/model/WolfEntityModel neck Lnet/minecraft/client/model/ModelPart;

0 comments on commit 2543337

Please sign in to comment.