Skip to content

Commit

Permalink
hats on pets
Browse files Browse the repository at this point in the history
  • Loading branch information
afamiliarquiet committed Oct 27, 2024
1 parent 6f39b71 commit aa5cc18
Show file tree
Hide file tree
Showing 29 changed files with 725 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
import com.mojang.logging.LogUtils;
import io.github.afamiliarquiet.familiar_magic.block.FamiliarBlocks;
import io.github.afamiliarquiet.familiar_magic.data.FamiliarAttachments;
import io.github.afamiliarquiet.familiar_magic.data.HatWearer;
import io.github.afamiliarquiet.familiar_magic.gooey.FamiliarGUIStuffs;
import io.github.afamiliarquiet.familiar_magic.item.FamiliarItems;
import io.github.afamiliarquiet.familiar_magic.network.FamiliarPacketeering;
import io.github.afamiliarquiet.familiar_magic.network.HattedPayload;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.event.entity.living.LivingDropsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import org.slf4j.Logger;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;

// The value here should match an entry in the META-INF/neoforge.mods.toml file
@Mod(FamiliarMagic.MOD_ID)
public class FamiliarMagic {
Expand Down Expand Up @@ -48,4 +60,32 @@ private void commonSetup(final FMLCommonSetupEvent event) {

Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
}

@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, modid = MOD_ID)
public static class ImReallyGonnaDoItImGonnaExplode {
// i should probably. clean up all these events n stuff instead of having all this crap around
// but .. i also don't really care right now that's a later problem for post-fest me

@SubscribeEvent
private static void mrwPlayerEventStartTracking(PlayerEvent.StartTracking event) {
Entity theEntity = event.getTarget();
ItemStack hat = getHat(theEntity);
if (theEntity instanceof HatWearer && !hat.isEmpty()) {
if (event.getEntity() instanceof ServerPlayer player) {
// idk why this ever wouldn't be the case.. whatever
PacketDistributor.sendToPlayer(player, new HattedPayload(hat, theEntity.getId()));
}
}
}

@SubscribeEvent
private static void mrwLivingDropsEvent(LivingDropsEvent event) {
Entity theEntity = event.getEntity();
ItemStack hat = getHat(theEntity);
if (theEntity instanceof HatWearer && !hat.isEmpty()) {
theEntity.spawnAtLocation(hat);
hat.shrink(1);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.afamiliarquiet.familiar_magic;

import com.mojang.blaze3d.platform.InputConstants;
import io.github.afamiliarquiet.familiar_magic.network.FamiliarPacketeering;
import io.github.afamiliarquiet.familiar_magic.network.FocusPayload;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -89,7 +89,7 @@ private static void mrwClientTickEventPost(ClientTickEvent.Pre event) {

if (shouldUpdate) {
FOCUSED_LAST_TICK.set(focusedNow);
PacketDistributor.sendToServer(new FamiliarPacketeering.FocusPayload(focusedNow));
PacketDistributor.sendToServer(new FocusPayload(focusedNow));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.github.afamiliarquiet.familiar_magic;

import io.github.afamiliarquiet.familiar_magic.data.FamiliarAttachments;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.UUIDUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -82,4 +85,12 @@ public static String uuidToTrueName(UUID uuid) {

return nybbles;
}

public static boolean hasHat(Entity entity) {
return !getHat(entity).isEmpty();
}

public static ItemStack getHat(Entity entity) {
return entity.getData(FamiliarAttachments.HAT).getStackInSlot(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.afamiliarquiet.familiar_magic.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.model.CatModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Quaternionf;

import javax.annotation.ParametersAreNonnullByDefault;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;

@ParametersAreNonnullByDefault
public class CatHatLayer extends RenderLayer<Cat, CatModel<Cat>> {
private final ItemInHandRenderer actuallyItsAHatRenderer;
public CatHatLayer(RenderLayerParent<Cat, CatModel<Cat>> renderer, ItemInHandRenderer itemInHandRenderer) {
super(renderer);
this.actuallyItsAHatRenderer = itemInHandRenderer;
}

@Override
public void render(
PoseStack poseStack,
MultiBufferSource buffer,
int packedLight,
Cat cat,
float limbSwing,
float limbSwingAmount,
float partialTick,
float ageInTicks,
float netHeadYaw,
float headPitch
) {
ItemStack hat = getHat(cat);
if (hat.isEmpty()) {
return;
}

poseStack.pushPose();

ModelPart littleFishyHead = this.getParentModel().head;
poseStack.translate(littleFishyHead.x / 16.0f, littleFishyHead.y / 16.0f, littleFishyHead.z / 16.0f);
poseStack.mulPose(new Quaternionf().rotationZYX(littleFishyHead.zRot, littleFishyHead.yRot, littleFishyHead.xRot));
poseStack.scale(littleFishyHead.xScale, littleFishyHead.yScale, littleFishyHead.zScale);

poseStack.mulPose(Axis.ZP.rotationDegrees(180));
poseStack.translate(0f, 0f, -0.0625f);

poseStack.scale(0.375f, 0.375f, 0.375f);

this.actuallyItsAHatRenderer.renderItem(cat, hat, ItemDisplayContext.HEAD, false, poseStack, buffer, packedLight);
poseStack.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package io.github.afamiliarquiet.familiar_magic.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.model.FoxModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.joml.Quaternionf;

import javax.annotation.ParametersAreNonnullByDefault;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;

@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
public class FoxHatLayer extends RenderLayer<Fox, FoxModel<Fox>> {
private final ItemInHandRenderer actuallyItsAHatRenderer;

public FoxHatLayer(RenderLayerParent<Fox, FoxModel<Fox>> renderer, ItemInHandRenderer itemInHandRenderer) {
super(renderer);
this.actuallyItsAHatRenderer = itemInHandRenderer;
}

// do NOT copy from the fox held item layer i dont know WHAT they were cooking with all that translation and rotation
// just copy the head part's translation/rotation/scale(baby)
@Override
public void render(
PoseStack poseStack,
MultiBufferSource buffer,
int packedLight,
Fox fox,
float limbSwing,
float limbSwingAmount,
float partialTicks,
float ageInTicks,
float netHeadYaw,
float headPitch
) {
ItemStack hat = getHat(fox);
if (hat.isEmpty()) {
return;
}

poseStack.pushPose();

ModelPart littleFishyHead = this.getParentModel().head;
poseStack.translate(littleFishyHead.x / 16.0f, littleFishyHead.y / 16.0f, littleFishyHead.z / 16.0f);
poseStack.mulPose(new Quaternionf().rotationZYX(littleFishyHead.zRot, littleFishyHead.yRot, littleFishyHead.xRot));
poseStack.scale(littleFishyHead.xScale, littleFishyHead.yScale, littleFishyHead.zScale);

poseStack.mulPose(Axis.ZP.rotationDegrees(180));
poseStack.translate(-0.0625f, 0f, -0.125f);

poseStack.scale(0.5625f, 0.5625f, 0.5625f);

this.actuallyItsAHatRenderer.renderItem(fox, hat, ItemDisplayContext.HEAD, false, poseStack, buffer, packedLight);
poseStack.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.github.afamiliarquiet.familiar_magic.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.model.ParrotModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.world.entity.animal.Parrot;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Quaternionf;

import javax.annotation.ParametersAreNonnullByDefault;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;

@ParametersAreNonnullByDefault
public class ParrotHatLayer extends RenderLayer<Parrot, ParrotModel> {
private final ItemInHandRenderer actuallyItsAHatRenderer;
public ParrotHatLayer(RenderLayerParent<Parrot, ParrotModel> renderer, ItemInHandRenderer itemInHandRenderer) {
super(renderer);
this.actuallyItsAHatRenderer = itemInHandRenderer;
}

@Override
public void render(
PoseStack poseStack,
MultiBufferSource buffer,
int packedLight,
Parrot parrot,
float limbSwing,
float limbSwingAmount,
float partialTick,
float ageInTicks,
float netHeadYaw,
float headPitch
) {
ItemStack hat = getHat(parrot);
if (hat.isEmpty()) {
return;
}

poseStack.pushPose();

ModelPart littleFishyHead = this.getParentModel().head;
poseStack.translate(littleFishyHead.x / 16.0f, littleFishyHead.y / 16.0f, littleFishyHead.z / 16.0f);
poseStack.mulPose(new Quaternionf().rotationZYX(littleFishyHead.zRot, littleFishyHead.yRot, littleFishyHead.xRot));
poseStack.scale(littleFishyHead.xScale, littleFishyHead.yScale, littleFishyHead.zScale);

poseStack.mulPose(Axis.ZP.rotationDegrees(180));
poseStack.translate(0f, 0.0625f, -0.0625f);

poseStack.scale(0.3125f, 0.3125f, 0.3125f);

this.actuallyItsAHatRenderer.renderItem(parrot, hat, ItemDisplayContext.HEAD, false, poseStack, buffer, packedLight);
poseStack.popPose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.github.afamiliarquiet.familiar_magic.client;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.model.SilverfishModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.world.entity.monster.Silverfish;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import org.joml.Quaternionf;

import javax.annotation.ParametersAreNonnullByDefault;

import static io.github.afamiliarquiet.familiar_magic.FamiliarTricks.getHat;

@OnlyIn(Dist.CLIENT)
@ParametersAreNonnullByDefault
public class SilverfishHatLayer extends RenderLayer<Silverfish, SilverfishModel<Silverfish>> {
private final ItemInHandRenderer actuallyItsAHatRenderer;

public SilverfishHatLayer(RenderLayerParent<Silverfish, SilverfishModel<Silverfish>> renderer, ItemInHandRenderer itemInHandRenderer) {
super(renderer);
this.actuallyItsAHatRenderer = itemInHandRenderer;
}

@Override
public void render(
PoseStack poseStack,
MultiBufferSource buffer,
int packedLight,
Silverfish silverfish,
float limbSwing,
float limbSwingAmount,
float partialTick,
float ageInTicks,
float netHeadYaw,
float headPitch
) {
ItemStack hat = getHat(silverfish);
if (hat.isEmpty()) {
return;
}

poseStack.pushPose();

if (!this.getParentModel().root().hasChild("segment0")) {
return;
}
ModelPart littleFishyHead = this.getParentModel().root().getChild("segment0");
poseStack.translate(littleFishyHead.x / 16.0f, littleFishyHead.y / 16.0f, littleFishyHead.z / 16.0f);
poseStack.mulPose(new Quaternionf().rotationZYX(littleFishyHead.zRot, littleFishyHead.yRot, littleFishyHead.xRot));

poseStack.mulPose(Axis.ZP.rotationDegrees(180));

poseStack.translate(0f, -0.05f, 0f);

poseStack.scale(0.25f, 0.25f, 0.25f);

this.actuallyItsAHatRenderer.renderItem(silverfish, hat, ItemDisplayContext.HEAD, false, poseStack, buffer, packedLight);
poseStack.popPose();
}
}
Loading

0 comments on commit aa5cc18

Please sign in to comment.