Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RenderLayers.getBlockLayer returning solid for everything #69

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.impl.blockrenderlayer;

import net.minecraft.client.render.RenderLayer;

public interface ExtendedChunkRenderTypeSet {
RenderLayer sinytra$firstLayer();
Su5eD marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.blockrenderlayer;

import net.fabricmc.fabric.impl.blockrenderlayer.ExtendedChunkRenderTypeSet;

import net.minecraft.client.render.RenderLayer;

import net.minecraftforge.client.ChunkRenderTypeSet;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import java.util.BitSet;

@Mixin(ChunkRenderTypeSet.class)
public abstract class ChunkRenderTypeSetMixin implements ExtendedChunkRenderTypeSet {

@Shadow
public abstract boolean isEmpty();

@Shadow
@Final
private BitSet bits;

@Shadow
@Final
private static RenderLayer[] CHUNK_RENDER_TYPES;

@Override
public RenderLayer sinytra$firstLayer() {
if(isEmpty())
return RenderLayer.getSolid();
return CHUNK_RENDER_TYPES[bits.nextSetBit(0)];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.blockrenderlayer;

import net.fabricmc.fabric.impl.blockrenderlayer.ExtendedChunkRenderTypeSet;

import net.minecraft.block.Block;
import net.minecraft.client.render.RenderLayers;

import net.minecraft.registry.entry.RegistryEntry;

import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.registries.ForgeRegistries;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Map;

@Mixin(RenderLayers.class)
public class RenderLayersMixin {
@Shadow
@Final
private static Map<RegistryEntry.Reference<Block>, ChunkRenderTypeSet> BLOCK_RENDER_TYPES;

/**
* @author embeddedt
* @reason Make getBlockLayer behave correctly (so that it can be used by Fabric mods) as long as the block has
* only a single render type
*/
@Redirect(method = {"getBlockLayer", "getMovingBlockLayer" }, at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 0))
private static Object getRenderLayerViaForge(Map instance, Object block) {
ChunkRenderTypeSet renderTypeSet = BLOCK_RENDER_TYPES.get(ForgeRegistries.BLOCKS.getDelegateOrThrow((Block)block));
return ((ExtendedChunkRenderTypeSet)(Object)renderTypeSet).sinytra$firstLayer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "net.fabricmc.fabric.mixin.blockrenderlayer",
"compatibilityLevel": "JAVA_17",
"client": [
"ChunkRenderTypeSetMixin",
"RenderLayersMixin"
],
"injectors": {
"defaultRequire": 1,
"maxShiftBy": 3
},
"minVersion": "0.8.5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"fabric-api-base": "*"
},
"description": "Registration utility for block and fluid render layers.",
"mixins": [
"fabric-blockrenderlayer-v1.mixins.json"
],
"custom": {
"fabric-api:module-lifecycle": "stable"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public BlockRenderLayerTest() {
if (RenderLayers.getFluidLayer(EXAMPLE_FLUID.get().getDefaultState()) != RenderLayer.getTranslucent()) {
throw new AssertionError("Expected render type of EXAMPLE_FLUID to be RenderType.translucent");
}
if (RenderLayers.getBlockLayer(EXAMPLE_BLOCK.get().getDefaultState()) != RenderLayer.getCutout()) {
throw new AssertionError("Expected EXAMPLE_BLOCK to be RenderType.cutout");
}

// Success!
LOGGER.info("The tests for block render type layers passed!");
Expand Down
Loading