Skip to content

Commit

Permalink
Merge branch 'architectury-1.18.1' into architectury-1.18.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/com/unlikepaladin/pfm/runtime/assets/PFMBlockstateModelProvider.java
  • Loading branch information
UnlikePaladin committed Jan 2, 2024
2 parents fa8843a + 257aaac commit 3659d87
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.stream.Stream;

public class SimpleBunkLadderBlock extends LadderBlock {
private static final BooleanProperty UP = Properties.UP;
public static final BooleanProperty UP = Properties.UP;
private static final List<FurnitureBlock> SIMPLE_BUNK_LADDER = new ArrayList<>();
public SimpleBunkLadderBlock(Settings settings) {
super(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.TexturedRenderLayers;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.texture.MissingSprite;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
Expand Down Expand Up @@ -178,24 +179,33 @@ public static Identifier getTextureId(Block block, String postfix) {
if (postfix.isEmpty() && !PFMDataGenerator.areAssetsRunning()) {
BakedModel model = MinecraftClient.getInstance().getBakedModelManager().getBlockModels().getModel(block.getDefaultState());
if (model != null) {
id = model.getQuads(block.getDefaultState(), Direction.NORTH, new Random(42L)).get(0).getSprite().getId();
if (id != null) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
List<BakedQuad> quadList = model.getQuads(block.getDefaultState(), Direction.NORTH, new Random(42L));
if (!quadList.isEmpty()) {
id = quadList.get(0).getSprite().getId();
if (id != null && id != MissingSprite.getMissingSpriteId()) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
}
}
}
} else if (postfix.equals("top") && !PFMDataGenerator.areAssetsRunning()) {
BakedModel model = MinecraftClient.getInstance().getBakedModelManager().getBlockModels().getModel(block.getDefaultState());
if (model != null) {
id = model.getQuads(block.getDefaultState(), Direction.UP, new Random(42L)).get(0).getSprite().getId();
if (id != null && id != MissingSprite.getMissingSpriteId()) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
List<BakedQuad> quadList = model.getQuads(block.getDefaultState(), Direction.UP, new Random(42L));
if (!quadList.isEmpty()) {
id = quadList.get(0).getSprite().getId();
if (id != null && id != MissingSprite.getMissingSpriteId()) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
}
}
id = model.getQuads(block.getDefaultState(), Direction.DOWN, new Random(42L)).get(0).getSprite().getId();
if (id != null && id != MissingSprite.getMissingSpriteId()) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
quadList = model.getQuads(block.getDefaultState(), Direction.DOWN, new Random(42L));
if (!quadList.isEmpty()) {
id = quadList.get(0).getSprite().getId();
if (id != null && id != MissingSprite.getMissingSpriteId()) {
blockToTextureMap.put(pair, new Pair<>(id, attemptNum));
return id;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.unlikepaladin.pfm.blocks.models.ladder;

import com.mojang.datafixers.util.Pair;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.data.materials.StoneVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariant;
import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

public class UnbakedLadderModel implements UnbakedModel {
public static final Identifier[] LADDER_PARTS_BASE = new Identifier[] {
new Identifier(PaladinFurnitureMod.MOD_ID, "block/simple_bunk_ladder/simple_ladder"),
new Identifier(PaladinFurnitureMod.MOD_ID, "block/simple_bunk_ladder/simple_ladder_top")
};

public static final Identifier LADDER_MODEL_ID = new Identifier(PaladinFurnitureMod.MOD_ID, "block/simple_bunk_ladder");
public static final List<Identifier> LADDER_MODEL_IDS = new ArrayList<>() {
{
for(WoodVariant variant : WoodVariantRegistry.getVariants()){

add(new Identifier(PaladinFurnitureMod.MOD_ID, "item/" + variant.asString() + "_simple_bunk_ladder"));
if (variant.hasStripped())
add(new Identifier(PaladinFurnitureMod.MOD_ID, "item/stripped_" + variant.asString() + "_simple_bunk_ladder"));
}
for(StoneVariant variant : StoneVariant.values()){

add(new Identifier(PaladinFurnitureMod.MOD_ID, "item/" + variant.asString() + "_simple_bunk_ladder"));
}
add(LADDER_MODEL_ID);
}
};

private static final Identifier PARENT = new Identifier("block/block");
public Collection<Identifier> getModelDependencies() {
return List.of(PARENT);
}

@Override
public Collection<SpriteIdentifier> getTextureDependencies(Function<Identifier, UnbakedModel> unbakedModelGetter, Set<Pair<String, String>> unresolvedTextureReferences) {
return Collections.emptyList();
}

public static final Map<ModelBakeSettings, List<BakedModel>> CACHED_MODELS = new ConcurrentHashMap<>();
@Nullable
@Override
public BakedModel bake(ModelLoader loader, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings rotationContainer, Identifier modelId) {
if (CACHED_MODELS.containsKey(rotationContainer))
return getBakedModel(rotationContainer, CACHED_MODELS.get(rotationContainer));

List<BakedModel> bakedModelList = new ArrayList<>();
for (Identifier modelPart : LADDER_PARTS_BASE) {
bakedModelList.add(loader.bake(modelPart, rotationContainer));
}
CACHED_MODELS.put(rotationContainer, bakedModelList);
return getBakedModel(rotationContainer, bakedModelList);
}

@ExpectPlatform
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
throw new RuntimeException("Method wasn't replaced correctly");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void handledScreenTick() {
super.handledScreenTick();
this.isActive = handler.isActive;
DefaultedList<ItemStack> inventory = DefaultedList.ofSize(1,handler.getInventory().getStack(0));
Recipe<?> recipe = getRecipe(Objects.requireNonNull(handler.microwaveBlockEntity.getWorld()), handler.getInventory());
Recipe<?> recipe = getRecipe(handler.microwaveBlockEntity.getWorld(), handler.getInventory());
if(!MicrowaveBlockEntity.canAcceptRecipeOutput(recipe, inventory ,microwaveBlockEntity.getMaxCountPerStack()) && !this.handler.isActive()) {
this.startButton.active = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void registerBeds() {
}

public void registerLadders() {
generateModelAndBlockStateForVariants(PaladinFurnitureMod.furnitureEntryMap.get(SimpleBunkLadderBlock.class).getVariantToBlockMap(), "simple_bunk_ladder", TEMPLATE_SIMPLE_BUNK_LADDER_ARRAY, PFMBlockStateModelGenerator::createLadderBlockState, PFMBlockStateModelGenerator::createPlankBlockTexture);
generateBlockStateForBlock(PaladinFurnitureMod.furnitureEntryMap.get(SimpleBunkLadderBlock.class).getVariantToBlockMap(), "simple_bunk_ladder", PFMBlockStateModelGenerator::createOrientableTableBlockState);
}

public void registerCounters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"credit": "By UnlikePaladin",
"textures": {
"0": "#texture",
"particle": "#texture"
"0": "minecraft:block/oak_planks",
"particle": "minecraft:block/oak_planks"
},
"elements": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"credit": "By UnlikePaladin",
"textures": {
"0": "#texture",
"particle": "#texture"
"0": "minecraft:block/oak_planks",
"particle": "minecraft:block/oak_planks"
},
"elements": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.unlikepaladin.pfm.blocks.models.ladder.fabric;

import com.unlikepaladin.pfm.blocks.SimpleBunkLadderBlock;
import com.unlikepaladin.pfm.blocks.models.fabric.PFMFabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView;

import java.util.List;
import java.util.Random;
import java.util.function.Supplier;

public class FabricLadderModel extends PFMFabricBakedModel {
public FabricLadderModel(ModelBakeSettings settings, List<BakedModel> bakedModels) {
super(settings, bakedModels);
}

@Override
public Sprite pfm$getParticle(BlockState state) {
return getSpriteList(state).get(0);
}

@Override
public boolean isVanillaAdapter() {
return false;
}

@Override
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
if (state != null && state.getBlock() instanceof SimpleBunkLadderBlock) {
Sprite sprite = getSpriteList(state).get(0);
pushTextureTransform(context, sprite);
int offset = state.get(SimpleBunkLadderBlock.UP) ? 1 : 0;
((FabricBakedModel)getTemplateBakedModels().get(offset)).emitBlockQuads(blockView, state, pos, randomSupplier, context);
context.popTransform();
}
}

@Override
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
Sprite sprite = getSpriteList(stack).get(0);
pushTextureTransform(context, sprite);
((FabricBakedModel)getTemplateBakedModels().get(0)).emitItemQuads(stack, randomSupplier, context);
context.popTransform();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.unlikepaladin.pfm.blocks.models.ladder.fabric;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;

import java.util.List;

public class UnbakedLadderModelImpl {
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
return new FabricLadderModel(settings, modelParts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.unlikepaladin.pfm.blocks.models.kitchenSink.UnbakedKitchenSinkModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallCounter.UnbakedKitchenWallCounterModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawer.UnbakedKitchenWallDrawerModel;
import com.unlikepaladin.pfm.blocks.models.ladder.UnbakedLadderModel;
import com.unlikepaladin.pfm.blocks.models.logStool.UnbakedLogStoolModel;
import com.unlikepaladin.pfm.blocks.models.logTable.UnbakedLogTableModel;
import com.unlikepaladin.pfm.blocks.models.mirror.UnbakedMirrorModel;
Expand Down Expand Up @@ -106,6 +107,9 @@ public void provideExtraModels(ResourceManager manager, Consumer<Identifier> out
for (Identifier id : UnbakedKitchenWallDrawerSmallModel.DRAWER_MODEL_PARTS_BASE) {
out.accept(id);
}
for (Identifier id : UnbakedLadderModel.LADDER_PARTS_BASE) {
out.accept(id);
}
UnbakedMirrorModel.ALL_MODEL_IDS.forEach(out::accept);
UnbakedIronFridgeModel.ALL_MODEL_IDS.forEach(out::accept);
UnbakedFridgeModel.ALL_MODEL_IDS.forEach(out::accept);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.unlikepaladin.pfm.blocks.models.kitchenWallCounter.UnbakedKitchenWallCounterModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawer.UnbakedKitchenWallDrawerModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawerSmall.UnbakedKitchenWallDrawerSmallModel;
import com.unlikepaladin.pfm.blocks.models.ladder.UnbakedLadderModel;
import com.unlikepaladin.pfm.blocks.models.logStool.UnbakedLogStoolModel;
import com.unlikepaladin.pfm.blocks.models.logTable.UnbakedLogTableModel;
import com.unlikepaladin.pfm.blocks.models.mirror.UnbakedMirrorModel;
Expand Down Expand Up @@ -123,6 +124,9 @@ else if (UnbakedFreezerModel.FREEZER_MODEL_IDS.contains(resourceId)){
else if (UnbakedBasicLampModel.LAMP_MODEL_IDS.contains(resourceId)){
return new UnbakedBasicLampModel();
}
else if (UnbakedLadderModel.LADDER_MODEL_IDS.contains(resourceId)){
return new UnbakedLadderModel();
}
else
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.unlikepaladin.pfm.blocks.models.ladder.forge;

import com.unlikepaladin.pfm.blocks.SimpleBunkLadderBlock;
import com.unlikepaladin.pfm.blocks.models.forge.PFMForgeBakedModel;
import net.minecraft.block.BlockState;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedQuad;
import net.minecraft.client.render.model.ModelBakeSettings;
import net.minecraft.client.texture.Sprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockRenderView;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class ForgeLadderModel extends PFMForgeBakedModel {

public ForgeLadderModel(ModelBakeSettings settings, List<BakedModel> templateBakedModels) {
super(settings, templateBakedModels);
}

@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull Random rand, @NotNull IModelData extraData) {
if (state != null && state.getBlock() instanceof SimpleBunkLadderBlock) {
int offset = state.get(SimpleBunkLadderBlock.UP) ? 1 : 0;
Sprite sprite = getSpriteList(state).get(0);
return getQuadsWithTexture(getTemplateBakedModels().get(offset).getQuads(state, side, rand, extraData), sprite);
}
return Collections.emptyList();
}

@Override
public @NotNull IModelData getModelData(@NotNull BlockRenderView world, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData tileData) {
return super.getModelData(world, pos, state, new ModelDataMap.Builder().build());
}

@Override
public List<BakedQuad> getQuads(ItemStack stack, @Nullable BlockState state, @Nullable Direction face, Random random) {
Sprite sprite = getSpriteList(stack).get(0);
return getQuadsWithTexture(getTemplateBakedModels().get(0).getQuads(state, face, random), sprite);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.unlikepaladin.pfm.blocks.models.ladder.forge;

import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.ModelBakeSettings;

import java.util.List;

public class UnbakedLadderModelImpl {
public static BakedModel getBakedModel(ModelBakeSettings settings, List<BakedModel> modelParts) {
return new ForgeLadderModel(settings, modelParts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.unlikepaladin.pfm.blocks.models.kitchenWallCounter.UnbakedKitchenWallCounterModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawer.UnbakedKitchenWallDrawerModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawerSmall.UnbakedKitchenWallDrawerSmallModel;
import com.unlikepaladin.pfm.blocks.models.ladder.UnbakedLadderModel;
import com.unlikepaladin.pfm.blocks.models.logStool.UnbakedLogStoolModel;
import com.unlikepaladin.pfm.blocks.models.logTable.UnbakedLogTableModel;
import com.unlikepaladin.pfm.blocks.models.mirror.UnbakedMirrorModel;
Expand Down Expand Up @@ -147,6 +148,9 @@ public static void registerExtraModels(ModelRegistryEvent event) {
for (Identifier id : UnbakedKitchenWallDrawerSmallModel.DRAWER_MODEL_PARTS_BASE) {
ForgeModelBakery.addSpecialModel(id);
}
for (Identifier id : UnbakedLadderModel.LADDER_PARTS_BASE) {
ForgeModelBakery.addSpecialModel(id);
}
UnbakedMirrorModel.ALL_MODEL_IDS.forEach(ForgeModelBakery::addSpecialModel);
UnbakedIronFridgeModel.ALL_MODEL_IDS.forEach(ForgeModelBakery::addSpecialModel);
UnbakedFridgeModel.ALL_MODEL_IDS.forEach(ForgeModelBakery::addSpecialModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.unlikepaladin.pfm.blocks.models.kitchenWallCounter.UnbakedKitchenWallCounterModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawer.UnbakedKitchenWallDrawerModel;
import com.unlikepaladin.pfm.blocks.models.kitchenWallDrawerSmall.UnbakedKitchenWallDrawerSmallModel;
import com.unlikepaladin.pfm.blocks.models.ladder.UnbakedLadderModel;
import com.unlikepaladin.pfm.blocks.models.logStool.UnbakedLogStoolModel;
import com.unlikepaladin.pfm.blocks.models.logTable.UnbakedLogTableModel;
import com.unlikepaladin.pfm.blocks.models.mirror.UnbakedMirrorModel;
Expand Down Expand Up @@ -226,5 +227,11 @@ else if (UnbakedLogStoolModel.LOG_STOOL_MODEL_IDS.contains(modifiedId)){
this.modelsToBake.put(resourceId, model);
ci.cancel();
}
else if (UnbakedLadderModel.LADDER_MODEL_IDS.contains(modifiedId)){
UnbakedModel model = new UnbakedLadderModel();
this.unbakedModels.put(resourceId, model);
this.modelsToBake.put(resourceId, model);
ci.cancel();
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.18.2
enabled_platforms=fabric,forge

archives_base_name=paladin-furniture-mod
mod_version=1.2.1
mod_version=1.2.1-rc2
maven_group=com.unlikepaladin

architectury_version=4.9.83
Expand Down

0 comments on commit 3659d87

Please sign in to comment.