Skip to content

Commit

Permalink
Merge branch 'architectury-1.17.1' into architectury-1.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Feb 21, 2024
2 parents 7ae8bff + 07126c0 commit 62ce5d4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +52,9 @@ public String asString() {

@Override
public Block getBaseBlock() {
if (baseBlock == null)
return PaladinFurnitureModBlocksItems.RAW_CONCRETE;

return baseBlock;
}

Expand All @@ -67,7 +70,7 @@ public boolean isNetherWood() {

@Override
public Material getVanillaMaterial() {
return baseBlock.getDefaultState().getMaterial();
return getBaseBlock().getDefaultState().getMaterial();
}

@Override
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
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;
import net.minecraft.item.ItemStack;
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 62ce5d4

Please sign in to comment.