Skip to content

Commit

Permalink
added ItemProperty for uno card item
Browse files Browse the repository at this point in the history
itemgroup is now automatically populated with cards with indexes up to
64 (for all the uno cards)
todo: make the rest of the textures
  • Loading branch information
awakaxis committed Nov 21, 2024
1 parent a0ee2f5 commit 8df317c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/main/java/net/awakaxis/uno/UNO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.awakaxis.uno;

import net.awakaxis.uno.item.UnoCardItem;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
Expand All @@ -23,7 +24,11 @@ public void onInitialize() {

ItemGroupEvents.modifyEntriesEvent(UNOItems.UNO_ITEM_GROUP_KEY).register(itemGroup -> {
itemGroup.accept(UNOBlocks.CARD_DECK.asItem());
itemGroup.accept(UNOItems.UNO_CARD);
if (UNOItems.UNO_CARD instanceof UnoCardItem unoCardItem) {
for (int i = 0; i <= 64; i++) {
itemGroup.accept(unoCardItem.getWithIndex(i));
}
}
});

LOGGER.info("Hello Queers!");
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/net/awakaxis/uno/client/UNOClient.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
package net.awakaxis.uno.client;

import net.awakaxis.uno.UNO;
import net.awakaxis.uno.UNOBlockEntities;
import net.awakaxis.uno.UNOItems;
import net.awakaxis.uno.client.renderer.blockentity.CardDeckRenderer;
import net.awakaxis.uno.item.UnoCardItem;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public class UNOClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
BlockEntityRenderers.register(UNOBlockEntities.CARD_DECK_BLOCK_ENTITY_TYPE, CardDeckRenderer::new);

// fuck you, *unclamps your ClampedItemPropertyFunction*
ClampedItemPropertyFunction function = new ClampedItemPropertyFunction() {
@Override
public float call(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
return itemStack.getOrCreateTag().getInt(UnoCardItem.CARD_INDEX_TAG);
}

@Override
public float unclampedCall(ItemStack itemStack, @Nullable ClientLevel clientLevel, @Nullable LivingEntity livingEntity, int i) {
return 0;
}
};

ItemProperties.register(UNOItems.UNO_CARD, new ResourceLocation("card_index"), function);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.joml.Matrix4f;

public class CardDeckRenderer implements BlockEntityRenderer<CardDeckBlockEntity> {
public static final ResourceLocation CARD_DECK_TEXTURE = UNO.id("textures/entity/card_deck.png");
public static final ResourceLocation CARD_DECK_TEXTURE = UNO.id("textures/item/card_back.png");
public static final ResourceLocation CARD_DECK_TEXTURE_SIDE = UNO.id("textures/entity/card_deck_side.png");
public static int CARD_COUNT = 112;
private static final float CARD_THICKNESS = 0.007f;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/awakaxis/uno/item/UnoCardItem.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
package net.awakaxis.uno.item;

import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

public class UnoCardItem extends Item {

public static final String CARD_INDEX_TAG = "cardIndex";

@Override
public ItemStack getDefaultInstance() {
ItemStack itemStack = super.getDefaultInstance();
itemStack.getOrCreateTag().putInt(CARD_INDEX_TAG, 0);
return itemStack;
}

public ItemStack getWithIndex(int index) {
ItemStack itemStack = getDefaultInstance();
itemStack.getOrCreateTag().putInt(CARD_INDEX_TAG, index);
return itemStack;
}

public UnoCardItem(Item.Properties properties) {
super(properties);
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/assets/uno/models/item/card.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"parent": "item/generated",
"textures": {
"layer0": "uno:item/card_back"
},
"overrides": [
{
"predicate": {
"card_index": 0
},
"model": "uno:item/card_0"
},
{
"predicate": {
"card_index": 1
},
"model": "uno:item/card_1"
}
]
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/uno/models/item/card_0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "uno:item/card_back"
}
}
6 changes: 6 additions & 0 deletions src/main/resources/assets/uno/models/item/card_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "uno:item/card_wild"
}
}
Binary file not shown.

0 comments on commit 8df317c

Please sign in to comment.