Merge pull request #356 from Waterpicker/master
Made sky rendering work with the new fabric api.
This commit is contained in:
commit
360f57feed
5 changed files with 69 additions and 49 deletions
|
@ -14,7 +14,7 @@ archives_base_name=better-end
|
|||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
|
||||
patchouli_version = 55-FABRIC-SNAPSHOT
|
||||
fabric_version = 0.41.3+1.17
|
||||
fabric_version = 0.42.1+1.17
|
||||
bclib_version = 0.5.2
|
||||
rei_version = 6.0.264-alpha
|
||||
canvas_version = 1.0.+
|
||||
|
|
|
@ -2,14 +2,19 @@ package ru.betterend.client;
|
|||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
|
||||
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.util.TranslationHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.client.render.BetterEndSkyRenderer;
|
||||
import ru.betterend.events.ItemTooltipCallback;
|
||||
import ru.betterend.interfaces.MultiModelItem;
|
||||
import ru.betterend.item.CrystaliteArmor;
|
||||
|
@ -52,6 +57,12 @@ public class BetterEndClient implements ClientModInitializer {
|
|||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
BetterEndSkyRenderer skyRenderer = new BetterEndSkyRenderer();
|
||||
|
||||
if(ClientOptions.isCustomSky()) {
|
||||
DimensionRenderingRegistry.registerSkyRenderer(Level.END, skyRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerTooltips() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ru.betterend.mixin.client;
|
||||
package ru.betterend.client.render;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
@ -30,11 +30,14 @@ import ru.bclib.util.BackgroundInfo;
|
|||
import ru.bclib.util.MHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
import ru.betterend.mixin.client.LevelRendererAccessor;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Mixin(LevelRenderer.class)
|
||||
public class LevelRendererMixin {
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
|
||||
|
||||
public class BetterEndSkyRenderer implements DimensionRenderingRegistry.SkyRenderer {
|
||||
private static final ResourceLocation NEBULA_1 = BetterEnd.makeID("textures/sky/nebula_2.png");
|
||||
private static final ResourceLocation NEBULA_2 = BetterEnd.makeID("textures/sky/nebula_3.png");
|
||||
private static final ResourceLocation HORIZON = BetterEnd.makeID("textures/sky/nebula_1.png");
|
||||
|
@ -59,40 +62,36 @@ public class LevelRendererMixin {
|
|||
private static float blind02;
|
||||
private static float blind06;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
private boolean initalized = false;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private TextureManager textureManager;
|
||||
public void initalize() {
|
||||
|
||||
@Shadow
|
||||
private ClientLevel level;
|
||||
if(!initalized) {
|
||||
be_initStars();
|
||||
Random random = new Random(131);
|
||||
axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis2 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis3 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis4 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis1.normalize();
|
||||
axis2.normalize();
|
||||
axis3.normalize();
|
||||
axis4.normalize();
|
||||
|
||||
@Shadow
|
||||
private int ticks;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void be_onInit(Minecraft client, RenderBuffers bufferBuilders, CallbackInfo info) {
|
||||
be_initStars();
|
||||
Random random = new Random(131);
|
||||
axis1 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis2 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis3 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis4 = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
|
||||
axis1.normalize();
|
||||
axis2.normalize();
|
||||
axis3.normalize();
|
||||
axis4.normalize();
|
||||
this.initalized = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
|
||||
private void be_renderBetterEndSky(PoseStack matrices, Matrix4f matrix4f, float tickDelta, Runnable runnable, CallbackInfo info) {
|
||||
if (ClientOptions.isCustomSky() && minecraft.level.effects().skyType() == DimensionSpecialEffects.SkyType.END) {
|
||||
runnable.run();
|
||||
@Override
|
||||
public void render(WorldRenderContext context) {
|
||||
initalize();
|
||||
|
||||
time = (ticks % 360000) * 0.000017453292F;
|
||||
PoseStack matrices = context.matrixStack();
|
||||
|
||||
Matrix4f matrix4f = context.projectionMatrix();
|
||||
float tickDelta = context.tickDelta();
|
||||
|
||||
time = (((LevelRendererAccessor) context.gameRenderer().getMinecraft().levelRenderer).getTick() + context.tickDelta() % 360000) * 0.000017453292F;
|
||||
time2 = time * 2;
|
||||
time3 = time * 3;
|
||||
|
||||
|
@ -213,8 +212,6 @@ public class LevelRendererMixin {
|
|||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void be_renderBuffer(PoseStack matrices, Matrix4f matrix4f, VertexBuffer buffer, VertexFormat format, float r, float g, float b, float a) {
|
|
@ -0,0 +1,12 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
|
||||
@Mixin(LevelRenderer.class)
|
||||
public interface LevelRendererAccessor {
|
||||
@Accessor("ticks")
|
||||
int getTick();
|
||||
}
|
|
@ -5,17 +5,17 @@
|
|||
"compatibilityLevel": "JAVA_16",
|
||||
"client": [
|
||||
"AbstractSoundInstanceAccessor",
|
||||
"HumanoidMobRendererMixin",
|
||||
"ArmorStandRendererMixin",
|
||||
"MinecraftClientMixin",
|
||||
"PlayerRendererMixin",
|
||||
"LevelRendererMixin",
|
||||
"MusicTrackerMixin",
|
||||
"BiomeColorsMixin",
|
||||
"CapeLayerMixin",
|
||||
"HumanoidMobRendererMixin",
|
||||
"ItemStackMixin",
|
||||
"LocalPlayerMixin",
|
||||
"MinecraftClientMixin",
|
||||
"ModelLoaderMixin",
|
||||
"LocalPlayerMixin",
|
||||
"CapeLayerMixin",
|
||||
"ItemStackMixin"
|
||||
"MusicTrackerMixin",
|
||||
"PlayerRendererMixin",
|
||||
"LevelRendererAccessor"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue