Skip to content

Commit

Permalink
Finished Snow Golem head item placement
Browse files Browse the repository at this point in the history
  • Loading branch information
crispytwig committed Nov 30, 2024
1 parent 6036c83 commit f70e2ab
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.starfish_studios.seasons_greetings.client.render.layers;

import com.google.common.collect.Maps;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.starfish_studios.seasons_greetings.client.render.layers;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.starfish_studios.seasons_greetings.SeasonsGreetings;
import com.starfish_studios.seasons_greetings.registry.SGTags;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.Util;
import net.minecraft.client.model.SnowGolemModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.animal.SnowGolem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;

import java.util.HashMap;

@Environment(EnvType.CLIENT)
public class SnowGolemNosesLayer extends RenderLayer<SnowGolem, SnowGolemModel<SnowGolem>> {
public static final HashMap<Item, ResourceLocation> TEXTURE_LOCATION = Util.make(new HashMap<>(), (hashMap) -> {
hashMap.put(Items.CARROT, SeasonsGreetings.id("textures/entity/snow_golem/nose/carrot.png"));
hashMap.put(Items.POTATO, SeasonsGreetings.id("textures/entity/snow_golem/nose/potato.png"));
hashMap.put(Items.BEETROOT, SeasonsGreetings.id("textures/entity/snow_golem/nose/beetroot.png"));
hashMap.put(Items.WHEAT, SeasonsGreetings.id("textures/entity/snow_golem/nose/wheat.png"));
});

public SnowGolemNosesLayer(RenderLayerParent<SnowGolem, SnowGolemModel<SnowGolem>> renderLayerParent) {
super(renderLayerParent);
}

public void render(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, SnowGolem snowGolem, float f, float g, float h, float j, float k, float l) {
ItemStack itemStack = snowGolem.getItemBySlot(EquipmentSlot.HEAD);
if (TEXTURE_LOCATION.containsKey(itemStack.getItem())) {
VertexConsumer vertexConsumer = multiBufferSource.getBuffer(RenderType.entityCutout(TEXTURE_LOCATION.get(itemStack.getItem())));
this.getParentModel().renderToBuffer(poseStack, vertexConsumer, i, OverlayTexture.NO_OVERLAY);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.starfish_studios.seasons_greetings.mixin;

import com.google.common.collect.Maps;
import com.starfish_studios.seasons_greetings.registry.SGTags;
import net.minecraft.Util;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.animal.AbstractGolem;
Expand Down Expand Up @@ -61,26 +65,63 @@ private static DyeColor getDyeColor(ItemStack itemStack) {
return block instanceof WoolCarpetBlock ? ((WoolCarpetBlock)block).getColor() : null;
}

@Unique
public void snowSound(SoundEvent soundEvent) {
float f = 1.0F;
float g = 1.0F;
this.level().playSound(null, this, soundEvent, this.getSoundSource(), f, g);
}

// This makes them drop all of their equipment.
protected void dropCustomDeathLoot(ServerLevel serverLevel, DamageSource damageSource, boolean bl) {
super.dropCustomDeathLoot(serverLevel, damageSource, bl);
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
ItemStack itemStack = this.getItemBySlot(equipmentSlot);
if (!itemStack.isEmpty()) {
this.spawnAtLocation(itemStack);
this.setItemSlot(equipmentSlot, ItemStack.EMPTY);
}
}
}

@Inject(method = "mobInteract", at = @At("HEAD"), cancellable = true)
public void mobInteract(Player player, InteractionHand interactionHand, CallbackInfoReturnable<InteractionResult> cir) {
ItemStack itemStack = player.getItemInHand(interactionHand);
SnowGolem snowGolem = (SnowGolem)(Object)this;
DyeColor dyeColor = getDyeColor(snowGolem.getItemBySlot(EquipmentSlot.BODY));

if (itemStack.is(Items.CARVED_PUMPKIN) && !snowGolem.hasPumpkin()) {
this.level().playSound(null, this, SoundEvents.SNOW_PLACE, this.getSoundSource(), 1.0F, 1.0F);
snowGolem.setPumpkin(true);

// Head Item Placement
if (itemStack.is(SGTags.SeasonsGreetingsItemTags.SNOW_GOLEM_NOSES) && !snowGolem.hasPumpkin() && snowGolem.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
snowSound(SoundEvents.SNOW_PLACE);
snowGolem.setItemSlot(EquipmentSlot.HEAD, new ItemStack(itemStack.getItem()));
cir.setReturnValue(InteractionResult.SUCCESS);
}

if (itemStack.getItem() instanceof ShearsItem && dyeColor != null) {
snowGolem.setItemSlot(EquipmentSlot.BODY, ItemStack.EMPTY);
this.level().playSound(null, this, SoundEvents.SNOW_GOLEM_SHEAR, this.getSoundSource(), 1.0F, 1.0F);
ItemEntity itemEntity = new ItemEntity(this.level(), this.getX(), this.getY() + 1, this.getZ(), new ItemStack(ITEM_BY_DYE.get(dyeColor)));
this.level().addFreshEntity(itemEntity);
// Pumpkin Re-Placement
if (itemStack.is(Items.CARVED_PUMPKIN) && !snowGolem.hasPumpkin() && snowGolem.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
snowSound(SoundEvents.SNOW_PLACE);
snowGolem.setPumpkin(true);
cir.setReturnValue(InteractionResult.SUCCESS);
}

// Shearing
if (itemStack.getItem() instanceof ShearsItem) {
if (dyeColor != null) {
snowGolem.setItemSlot(EquipmentSlot.BODY, ItemStack.EMPTY);
this.level().playSound(null, this, SoundEvents.SNOW_GOLEM_SHEAR, this.getSoundSource(), 1.0F, 1.0F);
ItemEntity itemEntity = new ItemEntity(this.level(), this.getX(), this.getY() + 1, this.getZ(), new ItemStack(ITEM_BY_DYE.get(dyeColor)));
this.level().addFreshEntity(itemEntity);
cir.setReturnValue(InteractionResult.SUCCESS);
} else if (!snowGolem.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
this.level().playSound(null, this, SoundEvents.SNOW_GOLEM_SHEAR, this.getSoundSource(), 1.0F, 1.0F);
ItemEntity itemEntity = new ItemEntity(this.level(), this.getX(), this.getY() + 1.5, this.getZ(), snowGolem.getItemBySlot(EquipmentSlot.HEAD));
this.level().addFreshEntity(itemEntity);
snowGolem.setItemSlot(EquipmentSlot.HEAD, ItemStack.EMPTY);
cir.setReturnValue(InteractionResult.SUCCESS);
}
}

if (itemStack.is(ItemTags.WOOL_CARPETS) && snowGolem.getItemBySlot(EquipmentSlot.BODY).isEmpty()) {
snowGolem.setItemSlot(EquipmentSlot.BODY, new ItemStack(itemStack.getItem()));
cir.setReturnValue(InteractionResult.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.starfish_studios.seasons_greetings.mixin;

import net.minecraft.client.model.AnimationUtils;
import net.minecraft.client.model.HierarchicalModel;
import net.minecraft.client.model.SnowGolemModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.animal.SnowGolem;
import org.spongepowered.asm.mixin.*;
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;

@Mixin(SnowGolemModel.class)
public abstract class SnowGolemModelMixin<T extends Entity> extends HierarchicalModel<T> {
@Unique
private final ModelPart upperBody;
@Unique
private final ModelPart head;
@Unique
private final ModelPart leftArm;
@Unique
private final ModelPart rightArm;
@Unique
private final ModelPart nose;

public SnowGolemModelMixin(ModelPart modelPart) {
this.head = modelPart.getChild("head");
this.leftArm = modelPart.getChild("left_arm");
this.rightArm = modelPart.getChild("right_arm");
this.upperBody = modelPart.getChild("upper_body");
this.nose = modelPart.getChild("carrot_nose");
}


@Inject(method = "createBodyLayer", at = @At(value = "RETURN"), cancellable = true)
private static void sg$createBodyLayer(CallbackInfoReturnable<LayerDefinition> cir) {
MeshDefinition meshDefinition = new MeshDefinition();
PartDefinition partDefinition = meshDefinition.getRoot();
CubeDeformation cubeDeformation = new CubeDeformation(-0.5F);
partDefinition.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, cubeDeformation), PartPose.offset(0.0F, 4.0F, 0.0F));
CubeListBuilder cubeListBuilder = CubeListBuilder.create().texOffs(32, 0).addBox(-1.0F, 0.0F, -1.0F, 12.0F, 2.0F, 2.0F, cubeDeformation);
partDefinition.addOrReplaceChild("left_arm", cubeListBuilder, PartPose.offsetAndRotation(5.0F, 6.0F, 1.0F, 0.0F, 0.0F, 1.0F));
partDefinition.addOrReplaceChild("right_arm", cubeListBuilder, PartPose.offsetAndRotation(-5.0F, 6.0F, -1.0F, 0.0F, 3.1415927F, -1.0F));
partDefinition.addOrReplaceChild("upper_body", CubeListBuilder.create().texOffs(0, 16).addBox(-5.0F, -10.0F, -5.0F, 10.0F, 10.0F, 10.0F, cubeDeformation), PartPose.offset(0.0F, 13.0F, 0.0F));
partDefinition.addOrReplaceChild("lower_body", CubeListBuilder.create().texOffs(0, 36).addBox(-6.0F, -12.0F, -6.0F, 12.0F, 12.0F, 12.0F, cubeDeformation), PartPose.offset(0.0F, 24.0F, 0.0F));

PartDefinition head = partDefinition.getChild("head");

head.addOrReplaceChild("carrot_nose", CubeListBuilder.create().texOffs(33, 16).addBox(0.0F, -24.0F, 0.0F, 1.0F, 1.0F, 4.0F, new CubeDeformation(0.0F)), PartPose.offset(-0.5F, 19.0F, -7.5F));
head.addOrReplaceChild("potato_nose", CubeListBuilder.create().texOffs(44, 12).addBox(-2.0F, -27.0F, 1.0F, 4.0F, 6.0F, 3.0F, new CubeDeformation(-0.5F)), PartPose.offset(0.0F, 20.75F, -7.0F));

head.addOrReplaceChild("wheat_hair", CubeListBuilder.create().texOffs(41, 31).addBox(-4.0F, -4.0F, 0.0F, 8.0F, 8.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -11.0F, 0.0F, 0.0F, 0.7854F, 0.0F));
head.addOrReplaceChild("wheat_hair_2", CubeListBuilder.create().texOffs(41, 31).addBox(-4.0F, -4.0F, 0.0F, 8.0F, 8.0F, 0.0F, new CubeDeformation(0.0F)), PartPose.offsetAndRotation(0.0F, -11.0F, 0.0F, 0.0F, 2.3562F, 0.0F));

head.addOrReplaceChild("beetroot_nose", CubeListBuilder.create().texOffs(41, 22).addBox(-2.0F, -26.0F, 0.0F, 4.0F, 4.0F, 4.0F, new CubeDeformation(-0.5F)), PartPose.offset(0.0F, 19.75F, -6.25F));


cir.setReturnValue(LayerDefinition.create(meshDefinition, 64, 64));
}

@Inject(method = "setupAnim", at = @At(value = "HEAD"))
private void sg$setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, CallbackInfo ci) {
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.starfish_studios.seasons_greetings.mixin;

import com.starfish_studios.seasons_greetings.client.SeasonsGreetingsClient;
import com.starfish_studios.seasons_greetings.client.render.layers.HappyGolemLayer;
import com.starfish_studios.seasons_greetings.client.render.layers.SnowGolemDecorLayer;
import com.starfish_studios.seasons_greetings.client.render.layers.SnowGolemNosesLayer;
import net.minecraft.client.model.SnowGolemModel;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.client.renderer.entity.SnowGolemRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.animal.SnowGolem;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -24,7 +22,7 @@ public SnowGolemRendererMixin(EntityRendererProvider.Context context, SnowGolemM

@Inject(method = "<init>", at = @At("TAIL"))
private void addDecorLayer(EntityRendererProvider.Context context, CallbackInfo ci) {
// this.addLayer(new HappyGolemLayer(this));
this.addLayer((new SnowGolemNosesLayer(this)));
this.addLayer(new SnowGolemDecorLayer(this));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private static TagKey<EntityType<?>> of(String id) {

public static class SeasonsGreetingsItemTags {

public static final TagKey<Item> SNOW_GOLEM_NOSES = of("snow_golem_noses");

// public static final TagKey<Item> PEARLESCENT_FLOWERS = of("pearlescent_flowers");

private static TagKey<Item> of(String id) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"values": [
"minecraft:carrot",
"minecraft:potato",
"minecraft:wheat",
"minecraft:beetroot"
]
}
1 change: 1 addition & 0 deletions src/main/resources/seasonsgreetings.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"defaultRequire": 1
},
"client": [
"SnowGolemModelMixin",
"SnowGolemRendererMixin"
]
}

0 comments on commit f70e2ab

Please sign in to comment.