gas my own light, gate my own keep, and girl my own boss

This commit is contained in:
petrak@ 2023-02-16 13:53:37 -06:00
parent 9e9413e340
commit ac9e00f675
6 changed files with 77 additions and 5 deletions

View file

@ -3,12 +3,14 @@ package at.petrak.hexcasting.client.be;
import at.petrak.hexcasting.client.RegisterClientStuff; import at.petrak.hexcasting.client.RegisterClientStuff;
import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay; import at.petrak.hexcasting.common.blocks.BlockQuenchedAllay;
import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay; import at.petrak.hexcasting.common.blocks.entity.BlockEntityQuenchedAllay;
import at.petrak.hexcasting.xplat.IClientXplatAbstractions;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.BlockRenderDispatcher; import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.phys.AABB;
public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer<BlockEntityQuenchedAllay> { public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer<BlockEntityQuenchedAllay> {
private static int GASLIGHTING_AMOUNT = 0; private static int GASLIGHTING_AMOUNT = 0;
@ -36,7 +38,19 @@ public class BlockEntityQuenchedAllayRenderer implements BlockEntityRenderer<Blo
@Override @Override
public void render(BlockEntityQuenchedAllay blockEntity, float partialTick, PoseStack poseStack, public void render(BlockEntityQuenchedAllay blockEntity, float partialTick, PoseStack poseStack,
MultiBufferSource bufferSource, int packedLight, int packedOverlay) { MultiBufferSource bufferSource, int packedLight, int packedOverlay) {
doRender(this.ctx.getBlockRenderDispatcher(), poseStack, bufferSource, packedLight, packedOverlay); // https://github.com/MinecraftForge/MinecraftForge/blob/79dfdb0ace9694f9dd0f1d9e8c5c24a0ae2d77f8/patches/minecraft/net/minecraft/client/renderer/LevelRenderer.java.patch#L68
// Forge fixes BEs rendering offscreen; Fabric doesn't!
// So we do a special check on Fabric only
var pos = blockEntity.getBlockPos();
var aabb = new AABB(pos.offset(-1, 0, -1), pos.offset(1, 1, 1));
if (IClientXplatAbstractions.INSTANCE.fabricAdditionalQuenchFrustumCheck(aabb)) {
doRender(this.ctx.getBlockRenderDispatcher(), poseStack, bufferSource, packedLight, packedOverlay);
}
}
@Override
public boolean shouldRenderOffScreen(BlockEntityQuenchedAllay blockEntity) {
return false;
} }
public static int getGaslightingAmount() { public static int getGaslightingAmount() {

View file

@ -11,6 +11,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.AABB;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -31,6 +32,8 @@ public interface IClientXplatAbstractions {
void restoreLastFilter(AbstractTexture texture); void restoreLastFilter(AbstractTexture texture);
boolean fabricAdditionalQuenchFrustumCheck(AABB aabb);
IClientXplatAbstractions INSTANCE = find(); IClientXplatAbstractions INSTANCE = find();
private static IClientXplatAbstractions find() { private static IClientXplatAbstractions find() {
@ -38,7 +41,7 @@ public interface IClientXplatAbstractions {
if (providers.size() != 1) { if (providers.size() != 1) {
var names = providers.stream().map(p -> p.type().getName()).collect(Collectors.joining(",", "[", "]")); var names = providers.stream().map(p -> p.type().getName()).collect(Collectors.joining(",", "[", "]"));
throw new IllegalStateException( throw new IllegalStateException(
"There should be exactly one IClientXplatAbstractions implementation on the classpath. Found: " + names); "There should be exactly one IClientXplatAbstractions implementation on the classpath. Found: " + names);
} else { } else {
var provider = providers.get(0); var provider = providers.get(0);
HexAPI.LOGGER.debug("Instantiating client xplat impl: " + provider.type().getName()); HexAPI.LOGGER.debug("Instantiating client xplat impl: " + provider.type().getName());

View file

@ -0,0 +1,34 @@
package at.petrak.hexcasting.fabric.mixin.client;
import at.petrak.hexcasting.fabric.xplat.FabricClientXplatImpl;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(LevelRenderer.class)
public class FabricLevelRendererMixin {
@SuppressWarnings("InvalidInjectorMethodSignature")
@Inject(
method = "renderLevel",
at = @At(
value = "INVOKE", target = "Lnet/minecraft/client/renderer/FogRenderer;levelFogColor()V",
ordinal = 0),
locals = LocalCapture.CAPTURE_FAILSOFT)
private void snagFrustumFromLevelRenderer(PoseStack poseStack, float f, long arg2, boolean bl, Camera camera,
GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f matrix4f, CallbackInfo ci,
ProfilerFiller profilerFiller, boolean bl2, Vec3 vec3, double d, double e, double g, Matrix4f matrix4f2,
boolean bl3, Frustum frustum) {
FabricClientXplatImpl.LEVEL_RENDERER_FRUSTUM = frustum;
}
}

View file

@ -11,6 +11,7 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; import net.minecraft.client.renderer.item.ClampedItemPropertyFunction;
import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.client.renderer.item.ItemProperties;
@ -23,6 +24,7 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class FabricClientXplatImpl implements IClientXplatAbstractions { public class FabricClientXplatImpl implements IClientXplatAbstractions {
@ -45,7 +47,7 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions {
@Override @Override
public <T extends Entity> void registerEntityRenderer(EntityType<? extends T> type, public <T extends Entity> void registerEntityRenderer(EntityType<? extends T> type,
EntityRendererProvider<T> renderer) { EntityRendererProvider<T> renderer) {
EntityRendererRegistry.register(type, renderer); EntityRendererRegistry.register(type, renderer);
} }
@ -53,7 +55,7 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions {
private record UnclampedClampedItemPropFunc(ItemPropertyFunction inner) implements ClampedItemPropertyFunction { private record UnclampedClampedItemPropFunc(ItemPropertyFunction inner) implements ClampedItemPropertyFunction {
@Override @Override
public float unclampedCall(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, public float unclampedCall(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity,
int seed) { int seed) {
return inner.call(stack, level, entity, seed); return inner.call(stack, level, entity, seed);
} }
@ -77,4 +79,15 @@ public class FabricClientXplatImpl implements IClientXplatAbstractions {
public void restoreLastFilter(AbstractTexture texture) { public void restoreLastFilter(AbstractTexture texture) {
((ExtendedTexture) texture).restoreLastFilter(); ((ExtendedTexture) texture).restoreLastFilter();
} }
// Set by FabricLevelRendererMixin
public static Frustum LEVEL_RENDERER_FRUSTUM = null;
@Override
public boolean fabricAdditionalQuenchFrustumCheck(AABB aabb) {
if (LEVEL_RENDERER_FRUSTUM == null) {
return true; // fail safe
}
return LEVEL_RENDERER_FRUSTUM.isVisible(aabb);
}
} }

View file

@ -16,7 +16,9 @@
], ],
"client": [ "client": [
"client.FabricAbstractTextureMixin", "client.FabricAbstractTextureMixin",
"client.FabricLevelRendererMixin",
"client.FabricMixinGameRenderer", "client.FabricMixinGameRenderer",
"client.FabricModelManagerMixin",
"client.FabricMouseHandlerMixin", "client.FabricMouseHandlerMixin",
"client.FabricParticleEngineMixin" "client.FabricParticleEngineMixin"
] ]

View file

@ -14,6 +14,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.AABB;
public class ForgeClientXplatImpl implements IClientXplatAbstractions { public class ForgeClientXplatImpl implements IClientXplatAbstractions {
@Override @Override
@ -34,7 +35,7 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions {
@Override @Override
public <T extends Entity> void registerEntityRenderer(EntityType<? extends T> type, public <T extends Entity> void registerEntityRenderer(EntityType<? extends T> type,
EntityRendererProvider<T> renderer) { EntityRendererProvider<T> renderer) {
EntityRenderers.register(type, renderer); EntityRenderers.register(type, renderer);
} }
@ -52,4 +53,9 @@ public class ForgeClientXplatImpl implements IClientXplatAbstractions {
public void restoreLastFilter(AbstractTexture texture) { public void restoreLastFilter(AbstractTexture texture) {
texture.restoreLastBlurMipmap(); texture.restoreLastBlurMipmap();
} }
@Override
public boolean fabricAdditionalQuenchFrustumCheck(AABB aabb) {
return true; // forge fixes this with a patch so we just say "yep"
}
} }