Skip to content

Commit

Permalink
some PlayingDeckRenderer stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
awakaxis committed Dec 13, 2024
1 parent a1f1188 commit 83075ec
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
package net.awakaxis.uno.client.renderer.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.awakaxis.uno.UNOItems;
import net.awakaxis.uno.entity.PlayingDeck;
import net.awakaxis.uno.item.UnoCardItem;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import org.joml.Matrix4f;

public class PlayingDeckRenderer extends EntityRenderer<PlayingDeck> {
private final ItemRenderer itemRenderer;

public PlayingDeckRenderer(EntityRendererProvider.Context context) {
super(context);
this.itemRenderer = context.getItemRenderer();
}

@Override
public void render(PlayingDeck playingDeck, float f, float g, PoseStack matrices, MultiBufferSource multiBufferSource, int i) {

ItemStack itemStack = ((UnoCardItem) UNOItems.UNO_CARD).getWithIndex(18);

matrices.pushPose();
Matrix4f affine = matrices.last().pose();

// transform affine matrix with rotation to make the card flat, and scale to make the card look not massive
affine.translate(0f, 0f, 0.05f);
affine.rotate(Axis.XP.rotationDegrees(90f));
affine.scale(0.5f, 0.5f, 0.5f);

this.itemRenderer.renderStatic(itemStack, ItemDisplayContext.FIXED, i, OverlayTexture.NO_OVERLAY, matrices, multiBufferSource, playingDeck.level(), playingDeck.getId());

matrices.popPose();
}

@Override
Expand Down
32 changes: 22 additions & 10 deletions src/main/java/net/awakaxis/uno/entity/PlayingDeck.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class PlayingDeck extends Entity {

Expand All @@ -23,23 +23,26 @@ public class PlayingDeck extends Entity {

public PlayingDeck(EntityType<?> entityType, Level level) {
super(entityType, level);

}

@Environment(EnvType.SERVER)
public void pushCard(int cardIndex) {
if (this.level().isClientSide) return;

UNO.LOGGER.info("pushing card");

CompoundTag deckContents = this.entityData.get(DECK_CONTENTS_ID);
ListTag cardStack = deckContents.getList(DECK_STACK_TAG, Tag.TAG_INT);
cardStack.set(cardStack.size(), IntTag.valueOf(cardIndex));
cardStack.add(IntTag.valueOf(cardIndex));

this.entityData.set(DECK_CONTENTS_ID, deckContents);
this.entityData.set(DECK_CONTENTS_ID, deckContents, true);
}

@Environment(EnvType.SERVER)
public void popCard() {
if (this.level().isClientSide) return;

UNO.LOGGER.info("popping card");

CompoundTag deckContents = this.entityData.get(DECK_CONTENTS_ID);
ListTag cardStack = deckContents.getList(DECK_STACK_TAG, Tag.TAG_INT);
if (cardStack.isEmpty()) return;
Expand All @@ -51,26 +54,35 @@ public void popCard() {

@Override
public @NotNull InteractionResult interact(Player player, InteractionHand interactionHand) {
UNO.LOGGER.info("Testing");
if (this.level().isClientSide) {
player.displayClientMessage(Component.nullToEmpty("CLIENT: tag is: " + this.entityData.get(DECK_CONTENTS_ID)), false);
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
} else {
this.pushCard(18);
player.displayClientMessage(Component.nullToEmpty("SERVER: tag is: " + this.entityData.get(DECK_CONTENTS_ID)), false);
return InteractionResult.SUCCESS;
}
}

@Override
public boolean isPickable() {
return true;
}

@Override
public void defineSynchedData() {
this.entityData.define(DECK_CONTENTS_ID, new CompoundTag());
}

@Override
public void readAdditionalSaveData(CompoundTag compoundTag) {}
public void readAdditionalSaveData(CompoundTag compoundTag) {
CompoundTag compoundTag2 = new CompoundTag();
compoundTag2.put(DECK_STACK_TAG, compoundTag.getList(DECK_STACK_TAG, Tag.TAG_INT));
this.entityData.set(DECK_CONTENTS_ID, compoundTag2);
}

@Override
public void addAdditionalSaveData(CompoundTag compoundTag) {}
public void addAdditionalSaveData(CompoundTag compoundTag) {
compoundTag.put(DECK_STACK_TAG, this.entityData.get(DECK_CONTENTS_ID).getList(DECK_STACK_TAG, Tag.TAG_INT));
}
}

0 comments on commit 83075ec

Please sign in to comment.