From 5fd7c80ba1259e49dff02bc4e21b15507935140f Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Wed, 21 Feb 2024 00:41:33 -0600 Subject: [PATCH 1/2] Fix a few mixin related possible crashes --- .../unlikepaladin/pfm/client/PFMItemRenderer.java | 7 ++++++- .../pfm/data/materials/ExtraStoolVariant.java | 13 ++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/unlikepaladin/pfm/client/PFMItemRenderer.java b/common/src/main/java/com/unlikepaladin/pfm/client/PFMItemRenderer.java index 72b810d0c..7c3654680 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/client/PFMItemRenderer.java +++ b/common/src/main/java/com/unlikepaladin/pfm/client/PFMItemRenderer.java @@ -33,11 +33,16 @@ import java.util.*; public class PFMItemRenderer extends BuiltinModelItemRenderer { - private final PFMBedBlockEntity renderBed = new PFMBedBlockEntity(BlockPos.ORIGIN, PaladinFurnitureModBlocksItems.furnitureEntryMap.get(SimpleBedBlock.class).getVariantToBlockMapList().get(WoodVariantRegistry.OAK).iterator().next().getDefaultState()); + private final PFMBedBlockEntity renderBed; private final BlockEntityRenderDispatcher blockEntityRenderDispatcher; public PFMItemRenderer(BlockEntityRenderDispatcher blockEntityRenderDispatcher, EntityModelLoader loader) { super(blockEntityRenderDispatcher, loader); this.blockEntityRenderDispatcher = blockEntityRenderDispatcher; + if (PaladinFurnitureModBlocksItems.furnitureEntryMap.get(SimpleBedBlock.class) != null ) { + renderBed = new PFMBedBlockEntity(BlockPos.ORIGIN, PaladinFurnitureModBlocksItems.furnitureEntryMap.get(SimpleBedBlock.class).getVariantToBlockMapList().get(WoodVariantRegistry.OAK).iterator().next().getDefaultState()); + } else { + renderBed = null; + } } static Map<WoodVariant, Map<String, BakedModel>> bakedModels = new LinkedHashMap<>(); diff --git a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java index 404e02a69..ca35952b9 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java +++ b/common/src/main/java/com/unlikepaladin/pfm/data/materials/ExtraStoolVariant.java @@ -17,7 +17,7 @@ public class ExtraStoolVariant extends VariantBase<ExtraStoolVariant> { public static ExtraStoolVariant GRAY_DARK_OAK = new ExtraStoolVariant(Blocks.GRAY_CONCRETE, Blocks.STRIPPED_DARK_OAK_LOG, "gray_dark_oak"); public static ExtraStoolVariant WHITE = new ExtraStoolVariant(Blocks.WHITE_CONCRETE, Blocks.LIGHT_GRAY_CONCRETE, "white"); - public static ExtraStoolVariant GRAY = new ExtraStoolVariant(PaladinFurnitureModBlocksItems.RAW_CONCRETE, Blocks.LIGHT_GRAY_CONCRETE, "gray"); + public static ExtraStoolVariant GRAY = new ExtraStoolVariant(null, Blocks.LIGHT_GRAY_CONCRETE, "gray"); public static ExtraStoolVariant LIGHT_GRAY_DARK_OAK = new ExtraStoolVariant(Blocks.LIGHT_GRAY_CONCRETE, Blocks.STRIPPED_DARK_OAK_LOG, "light_gray_dark_oak"); private final String name; @@ -52,6 +52,9 @@ public String asString() { @Override public Block getBaseBlock() { + if (baseBlock == null) + return PaladinFurnitureModBlocksItems.RAW_CONCRETE; + return baseBlock; } @@ -67,7 +70,7 @@ public boolean isNetherWood() { @Override public Material getVanillaMaterial() { - return baseBlock.getDefaultState().getMaterial(); + return getBaseBlock().getDefaultState().getMaterial(); } @Override @@ -92,15 +95,15 @@ public void initializeChildrenItems() { @Override public Block mainChild() { - return baseBlock; + return getBaseBlock(); } @Environment(EnvType.CLIENT) @Override public Identifier getTexture(BlockType type) { if (type == BlockType.SECONDARY) - return ModelHelper.getTextureId(secondaryBlock); - return ModelHelper.getTextureId(baseBlock); + return ModelHelper.getTextureId(getSecondaryBlock()); + return ModelHelper.getTextureId(getBaseBlock()); } @Override From 07126c02274c22af38c2aee50868fc0510492516 Mon Sep 17 00:00:00 2001 From: UnlikePaladin <36827970+UnlikePaladin@users.noreply.github.com> Date: Wed, 21 Feb 2024 01:03:48 -0600 Subject: [PATCH 2/2] Cache item quads on forge --- .../forge/PFMBakedModelGetQuadsExtension.java | 14 ++++++++++++++ .../pfm/mixin/forge/ItemRendererMixin.java | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PFMBakedModelGetQuadsExtension.java b/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PFMBakedModelGetQuadsExtension.java index 2a62f8908..7d57f3730 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PFMBakedModelGetQuadsExtension.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/client/forge/PFMBakedModelGetQuadsExtension.java @@ -1,5 +1,6 @@ package com.unlikepaladin.pfm.client.forge; +import com.mojang.datafixers.util.Pair; import net.minecraft.block.BlockState; import net.minecraft.client.render.model.BakedQuad; import net.minecraft.client.texture.Sprite; @@ -7,9 +8,22 @@ import net.minecraft.util.math.Direction; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Random; public interface PFMBakedModelGetQuadsExtension { List<BakedQuad> getQuads(ItemStack stack, @Nullable BlockState state, @Nullable Direction face, Random random); + + Map<Pair<ItemStack, Direction>, List<BakedQuad>> cache = new HashMap<>(); + default List<BakedQuad> getQuadsCached(ItemStack stack, @Nullable BlockState state, @Nullable Direction face, Random random) { + Pair<ItemStack, Direction> directionPair = new Pair<>(stack, face); + if (cache.containsKey(directionPair)) + return cache.get(directionPair); + + List<BakedQuad> quads = getQuads(stack, state, face, random); + cache.put(directionPair, quads); + return quads; + } } diff --git a/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/ItemRendererMixin.java b/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/ItemRendererMixin.java index 9bbc75c25..de3c52270 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/ItemRendererMixin.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/mixin/forge/ItemRendererMixin.java @@ -49,10 +49,10 @@ private void renderPFMItem(ItemStack stack, ModelTransformation.Mode renderMode, long randomSeed = 42L; for (Direction direction : Direction.values()) { random.setSeed(randomSeed); - this.renderBakedItemQuads(matrices, vertexConsumer, ((PFMBakedModelGetQuadsExtension) model).getQuads(stack, state, direction, random), stack, light, overlay); + this.renderBakedItemQuads(matrices, vertexConsumer, ((PFMBakedModelGetQuadsExtension) model).getQuadsCached(stack, state, direction, random), stack, light, overlay); } random.setSeed(randomSeed); - this.renderBakedItemQuads(matrices, vertexConsumer, ((PFMBakedModelGetQuadsExtension)model).getQuads(stack, state, null, random), stack, light, overlay); + this.renderBakedItemQuads(matrices, vertexConsumer, ((PFMBakedModelGetQuadsExtension)model).getQuadsCached(stack, state, null, random), stack, light, overlay); // Conditionally pop because of handlePerspective weirdness if (matrices.peek() != pose) {