Skip to content

Commit

Permalink
Working render layers (#27)
Browse files Browse the repository at this point in the history
* Working render layers

* Falk's review
  • Loading branch information
maximumpower55 authored Apr 15, 2023
1 parent 0568e3f commit 9e23341
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,37 @@ public enum BlockType {
private final BiFunction<Block, QuiltBlockSettings, Block> creator;
private final float strength;
private final String[] variants;
private final SafeRenderLayer renderLayer;

BlockType(BiFunction<Block, QuiltBlockSettings, Block> creator, float strength, String[] variants, SafeRenderLayer renderLayer) {
this.creator = creator;
this.strength = strength;
this.variants = variants;
this.renderLayer = renderLayer;
}


public String[] variants() {
return variants;
}

public SafeRenderLayer renderLayer() {
return renderLayer;
}

@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}

public TypedGroupedBlock register(BlockGroup group, BlockGroup.GroupedBlock groupedBlock, BlockCreationCallback callback) {
return register(group, groupedBlock, callback, ArchitectureExtensions.MOD_CONTAINER.metadata().id()); // If no id is specified, use our own id
}

public TypedGroupedBlock register(BlockGroup group, BlockGroup.GroupedBlock groupedBlock, BlockCreationCallback callback, String modid) {
public TypedGroupedBlock register(BlockGroup group, BlockGroup.GroupedBlock groupedBlock, BlockCreationCallback callback, String modId) {
// Note: the mod id parameter isn't used here by purpose, that parameter is there so we can easily debug where registration is coming from.
Identifier id = new Identifier(ArchitectureExtensions.MOD_CONTAINER.metadata().id(), groupedBlock.id().getPath() + "_" + this);
var baseBlock = groupedBlock.baseBlock().get();
var block = Registry.register(Registries.BLOCK, id, creator.apply(baseBlock, QuiltBlockSettings.copyOf(baseBlock).mapColorProvider(state -> groupedBlock.mapColor()).strength(strength)));

Registry.register(Registries.ITEM, id, new BlockItem(block, new QuiltItemSettings()));

if (callback != null) callback.onBlockCreated(group, this, baseBlock, block);

return new TypedGroupedBlock(this, groupedBlock, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,21 @@

import io.github.debuggyteam.architecture_extensions.ArchitectureExtensions;
import io.github.debuggyteam.architecture_extensions.resource.DataGeneration;
import net.minecraft.registry.Registries;
import net.minecraft.resource.ResourceType;
import org.jetbrains.annotations.NotNull;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer;
import org.quiltmc.qsl.block.extensions.api.client.BlockRenderLayerMap;
import org.quiltmc.qsl.resource.loader.api.ResourceLoader;
import org.quiltmc.qsl.resource.loader.api.ResourcePackRegistrationContext;

import java.util.ArrayList;
import java.util.List;

public class ArchitectureExtensionsClient implements ClientModInitializer, ResourcePackRegistrationContext.Callback {
@Override
public void onInitializeClient(ModContainer mod) {
ResourceLoader.get(ResourceType.CLIENT_RESOURCES).getRegisterDefaultResourcePackEvent().register(this);

// This will be a pain in the ass
//BlockRenderLayerMap.put(RenderLayer.getCutout(), TransomBlock);
DataGeneration.BLOCKS.forEach(block -> BlockRenderLayerMap.put(block.type().renderLayer().get(), Registries.BLOCK.get(block.id())));

ResourceLoader.get(ResourceType.CLIENT_RESOURCES).getRegisterDefaultResourcePackEvent().register(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import net.minecraft.util.Identifier;

public final class DataGeneration {
static final Set<BlockType.TypedGroupedBlock> BLOCKS = Sets.newHashSet();
public static final Set<BlockType.TypedGroupedBlock> BLOCKS = Sets.newHashSet();

private static final String GROUP_PLACEHOLDER = "group";
private static final String BASE_PLACEHOLDER = "base";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package io.github.debuggyteam.architecture_extensions.util;

public enum SafeRenderLayer {
SOLID,
TRANSLUCENT,
CUTOUT;

public static SafeRenderLayer combine(SafeRenderLayer first, SafeRenderLayer second) {
if (first == TRANSLUCENT || second == TRANSLUCENT) return TRANSLUCENT;
if (first == CUTOUT || second == CUTOUT) return CUTOUT;
return SOLID;
import java.util.function.Supplier;

import org.quiltmc.loader.api.minecraft.ClientOnly;

import net.minecraft.client.render.RenderLayer;

public enum SafeRenderLayer implements @ClientOnly Supplier<RenderLayer> {
SOLID(0),
TRANSLUCENT(2),
CUTOUT(1);

private final int priority;

SafeRenderLayer(int priority) {
this.priority = priority;
}

@ClientOnly
@Override
public RenderLayer get() {
return switch (this) {
case SOLID -> RenderLayer.getSolid();
case TRANSLUCENT -> RenderLayer.getTranslucent();
case CUTOUT -> RenderLayer.getCutout();
};
}

public static SafeRenderLayer choose(SafeRenderLayer first, SafeRenderLayer second) {
if (second.priority > first.priority) return second;
return first;
}
}

0 comments on commit 9e23341

Please sign in to comment.