generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c1ddb5
commit 07bfb26
Showing
10 changed files
with
357 additions
and
5 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/io/github/afamiliarquiet/familiar_magic/item/ClothingItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/io/github/afamiliarquiet/familiar_magic/mixin/HatBakeryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/io/github/afamiliarquiet/familiar_magic/mixin/HatRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/resources/assets/familiar_magic/models/item/big_hat.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/resources/assets/familiar_magic/models/item/big_hat_on_head.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Binary file added
BIN
+336 Bytes
src/main/resources/assets/familiar_magic/textures/item/big_hat_on_head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.