Skip to content

Commit

Permalink
HAHAHAHAHAHA ADD BIG HAT!!!!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
afamiliarquiet committed Oct 18, 2024
1 parent 8c1ddb5 commit 07bfb26
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package io.github.afamiliarquiet.familiar_magic.item;

import com.google.common.base.Suppliers;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
import java.util.function.Supplier;

import static io.github.afamiliarquiet.familiar_magic.FamiliarMagic.MOD_ID;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class ClothingItem extends Item implements Equipable {
// can't just make an armor item, nooo, because that's an armor and it has trims and is rendered by the armor layer.
// no no, can't have strange creatures on the internet adding their own shapes to armor items. would hate for that.
// WELL TOO BAD AHAHAHA

protected final ArmorItem.Type type;
protected final Holder<ArmorMaterial> material;
private final Supplier<ItemAttributeModifiers> defaultModifiers;

public ClothingItem(Holder<ArmorMaterial> material, ArmorItem.Type type, Item.Properties properties) {
super(properties);
this.material = material;
this.type = type;
DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
this.defaultModifiers = Suppliers.memoize(
() -> new ItemAttributeModifiers(
List.of(new ItemAttributeModifiers.Entry(Attributes.ARMOR,
new AttributeModifier(
ResourceLocation.withDefaultNamespace("armor." + type.getName()),
material.value().getDefense(type),
AttributeModifier.Operation.ADD_VALUE
),
EquipmentSlotGroup.bySlot(type.getSlot())
)),
true
)
);
}

@Override
public int getEnchantmentValue(ItemStack stack) {
return this.material.value().enchantmentValue();
}

@Override
public boolean isValidRepairItem(ItemStack stack, ItemStack repairCandidate) {
return this.material.value().repairIngredient().get().test(repairCandidate);
}

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
return this.swapWithEquipmentSlot(this, level, player, usedHand);
}

@Override
public ItemAttributeModifiers getDefaultAttributeModifiers(ItemStack stack) {
return this.defaultModifiers.get();
}

@Override
public EquipmentSlot getEquipmentSlot() {
return this.type.getSlot();
}

@Override
public Holder<SoundEvent> getEquipSound() {
return this.material.value().equipSound();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,74 @@
package io.github.afamiliarquiet.familiar_magic.item;

import io.github.afamiliarquiet.familiar_magic.block.FamiliarBlocks;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.Util;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.Ingredient;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.SimpleTier;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.registries.DeferredItem;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.EnumMap;
import java.util.List;

import static io.github.afamiliarquiet.familiar_magic.FamiliarMagic.MOD_ID;

public class FamiliarItems {
public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID);
public static final DeferredRegister<ArmorMaterial> ARMOR_MATERIALS = DeferredRegister.create(Registries.ARMOR_MATERIAL, MOD_ID);

public static final Tier SOMEWHAT_FAMILIAR_TIER = new SimpleTier(
BlockTags.INCORRECT_FOR_IRON_TOOL,
1031,
6f,
1f,
31,
() -> Ingredient.of(Items.STRING)
);

public static final Holder<ArmorMaterial> SOMEWHAT_FAMILIAR_MATERIAL = ARMOR_MATERIALS.register(
"somewhat_familiar",
() -> new ArmorMaterial(
Util.make(new EnumMap<>(ArmorItem.Type.class), map -> {
map.put(ArmorItem.Type.HELMET, 1);
map.put(ArmorItem.Type.CHESTPLATE, 3);
map.put(ArmorItem.Type.LEGGINGS, 2);
map.put(ArmorItem.Type.BOOTS, 1);
map.put(ArmorItem.Type.BODY, 3); // for one-piece critters
}),
31,
SoundEvents.ARMOR_EQUIP_LEATHER,
() -> Ingredient.of(Items.STRING),
List.of(

),
0,
0
)
);

public static final DeferredItem<Item> TRUE_NAME_ITEM = ITEMS.registerSimpleItem("true_name");
public static final DeferredItem<Item> BIG_HAT = ITEMS.register(
"big_hat",
() -> new ClothingItem(
SOMEWHAT_FAMILIAR_MATERIAL,
ArmorItem.Type.HELMET,
new Item.Properties().durability(1031)
)
);
public static final ModelResourceLocation BIG_HAT_ON_HEAD_MODEL = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath(MOD_ID, "big_hat_on_head"));

public static void register(IEventBus eventBus) {
ITEMS.register(eventBus);
ARMOR_MATERIALS.register(eventBus);
eventBus.addListener(FamiliarItems::mrwBuildCreativeModeTabContents);
}

Expand All @@ -37,5 +87,13 @@ private static void mrwBuildCreativeModeTabContents(BuildCreativeModeTabContents
CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS
);
}

if (event.getTabKey() == CreativeModeTabs.COMBAT) {
event.insertBefore(
Items.LEATHER_HELMET.getDefaultInstance(),
BIG_HAT.toStack(),
CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.afamiliarquiet.familiar_magic.mixin;

import io.github.afamiliarquiet.familiar_magic.item.FamiliarItems;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockStateModelLoader;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.profiling.ProfilerFiller;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;
import java.util.Map;

@Mixin(ModelBakery.class)
public abstract class HatBakeryMixin {
@Shadow
protected abstract void loadSpecialItemModelAndDependencies(ModelResourceLocation modelLocation);

@Inject(at = @At("TAIL"), method = "<init>")
private void mmFreshHotHat(BlockColors blockColors,
ProfilerFiller profilerFiller,
Map<ResourceLocation, BlockModel> modelResources,
Map<ResourceLocation, List<BlockStateModelLoader.LoadedJson>> blockStateResources,
CallbackInfo ci) {
this.loadSpecialItemModelAndDependencies(FamiliarItems.BIG_HAT_ON_HEAD_MODEL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.github.afamiliarquiet.familiar_magic.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import io.github.afamiliarquiet.familiar_magic.item.FamiliarItems;
import net.minecraft.client.renderer.ItemModelShaper;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import static io.github.afamiliarquiet.familiar_magic.FamiliarMagic.MOD_ID;

@Mixin(ItemRenderer.class)
public abstract class HatRendererMixin {
@Unique
private static final ModelResourceLocation familiar_magic$BIG_HAT = ModelResourceLocation.inventory(ResourceLocation.fromNamespaceAndPath(MOD_ID, "big_hat_on_head"));

@Shadow
private ItemModelShaper itemModelShaper;

@Shadow
private static boolean hasAnimatedTexture(ItemStack stack) {
return false;
}

@Shadow
public static VertexConsumer getFoilBufferDirect(MultiBufferSource bufferSource, RenderType renderType, boolean noEntity, boolean withGlint) {
return null;
}

@Shadow
public void renderModelLists(BakedModel model, ItemStack stack, int combinedLight, int combinedOverlay, PoseStack poseStack, VertexConsumer buffer) {

}

@Inject(at = @At("HEAD"), method = "render", cancellable = true)
private void render(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHand, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLight, int combinedOverlay, BakedModel p_model, CallbackInfo ci) {
//LOGGER.debug("rendering item");
if (itemStack.is(FamiliarItems.BIG_HAT) && displayContext == ItemDisplayContext.HEAD) {
//LOGGER.debug("rendering hat on head");
if (!itemStack.isEmpty()) {
poseStack.pushPose();
p_model = this.itemModelShaper.getModelManager().getModel(FamiliarItems.BIG_HAT_ON_HEAD_MODEL);

p_model = net.neoforged.neoforge.client.ClientHooks.handleCameraTransforms(poseStack, p_model, displayContext, leftHand);
poseStack.translate(-0.5F, -0.5F, -0.5F);

for (var model : p_model.getRenderPasses(itemStack, true)) {
for (var rendertype : model.getRenderTypes(itemStack, true)) {
VertexConsumer vertexconsumer;
vertexconsumer = getFoilBufferDirect(bufferSource, rendertype, true, itemStack.hasFoil());

this.renderModelLists(model, itemStack, combinedLight, combinedOverlay, poseStack, vertexconsumer);
}
}


poseStack.popPose();
}

ci.cancel();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/familiar_magic/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"item.familiar_magic.true_name": "True Name",
"item.familiar_magic.big_hat": "Big Hat",
"block.familiar_magic.enchanted_candle": "Enchanted Candle",
"block.familiar_magic.summoning_table": "Summoning Table",
"container.familiar_magic.summon": "Summon"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "familiar_magic:item/big_hat"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"1": "familiar_magic:item/big_hat_on_head"
},
"elements": [
{
"from": [-4, 7, -4],
"to": [20, 8, 20],
"rotation": {"angle": 0, "axis": "x", "origin": [8, 7, 8]},
"faces": {
"north": {"uv": [0, 6.75, 6, 7], "texture": "#1"},
"east": {"uv": [0, 6.5, 6, 6.75], "texture": "#1"},
"south": {"uv": [0, 6.25, 6, 6.5], "texture": "#1"},
"west": {"uv": [0, 6, 6, 6.25], "texture": "#1"},
"up": {"uv": [0, 0, 6, 6], "texture": "#1"},
"down": {"uv": [0, 7, 6, 13], "texture": "#1"}
}
},
{
"from": [3, 8, 3],
"to": [13, 13, 13],
"rotation": {"angle": 0, "axis": "x", "origin": [8, 8, 8]},
"faces": {
"north": {"uv": [6, 6.25, 8.5, 7.5], "texture": "#1"},
"east": {"uv": [6, 5, 8.5, 6.25], "texture": "#1"},
"south": {"uv": [6, 3.75, 8.5, 5], "texture": "#1"},
"west": {"uv": [6, 2.5, 8.5, 3.75], "texture": "#1"},
"up": {"uv": [6, 0, 8.5, 2.5], "texture": "#1"},
"down": {"uv": [13.5, 13.5, 16, 16], "texture": "#1"}
}
},
{
"from": [5, 8, 9],
"to": [11, 14, 16],
"rotation": {"angle": -45, "axis": "x", "origin": [8, 8, 8]},
"faces": {
"north": {"uv": [13.5, 13.5, 15, 15], "rotation": 180, "texture": "#1"},
"east": {"uv": [8.5, 5, 10, 6.75], "rotation": 270, "texture": "#1"},
"south": {"uv": [8.5, 0, 10, 1.5], "texture": "#1"},
"west": {"uv": [8.5, 1.5, 10, 3.25], "rotation": 90, "texture": "#1"},
"up": {"uv": [8.5, 6.75, 10, 8.5], "rotation": 180, "texture": "#1"},
"down": {"uv": [8.5, 3.25, 10, 5], "texture": "#1"}
}
},
{
"from": [6, 12, 13],
"to": [10, 16, 18],
"rotation": {"angle": -22.5, "axis": "x", "origin": [8, 8, 8]},
"faces": {
"north": {"uv": [13.5, 13.5, 14.5, 14.5], "rotation": 180, "texture": "#1"},
"east": {"uv": [10, 3.5, 11, 4.75], "rotation": 270, "texture": "#1"},
"south": {"uv": [10, 0, 11, 1], "texture": "#1"},
"west": {"uv": [10, 1, 11, 2.25], "rotation": 90, "texture": "#1"},
"up": {"uv": [10, 4.75, 11, 6], "rotation": 180, "texture": "#1"},
"down": {"uv": [10, 2.25, 11, 3.5], "texture": "#1"}
}
}
],
"display": {
"thirdperson_righthand": {
"scale": [0.5, 0.5, 0.5]
},
"thirdperson_lefthand": {
"scale": [0.5, 0.5, 0.5]
},
"firstperson_righthand": {
"scale": [0.5, 0.5, 0.5]
},
"firstperson_lefthand": {
"scale": [0.5, 0.5, 0.5]
},
"ground": {
"scale": [0.5, 0.5, 0.5]
},
"gui": {
"scale": [0.5, 0.5, 0.5]
},
"head": {
"rotation": [11.25, 0, 0],
"translation": [0, 3, 0],
"scale": [1.6, 1.6, 1.6]
},
"fixed": {
"scale": [0.5, 0.5, 0.5]
}
}
}
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

0 comments on commit 07bfb26

Please sign in to comment.