From cb7e12ecb055d0e926d3bd756bb5281c590ae765 Mon Sep 17 00:00:00 2001 From: Waterpicker Date: Mon, 14 Jun 2021 05:31:35 -0500 Subject: [PATCH 1/3] Attempt at sky rendering showing Addon. --- .../mixin/client/WorldRendererMixin.java | 31 +++- .../world/pocket/type/addon/PocketAddon.java | 1 + .../world/pocket/type/addon/SkyAddon.java | 132 ++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java diff --git a/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java b/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java index 483b4785..a584bb5a 100644 --- a/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java +++ b/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java @@ -2,6 +2,9 @@ package org.dimdev.dimdoors.mixin.client; import com.mojang.blaze3d.systems.RenderSystem; import org.dimdev.dimdoors.world.ModDimensions; +import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry; +import org.dimdev.dimdoors.world.pocket.type.Pocket; +import org.dimdev.dimdoors.world.pocket.type.addon.SkyAddon; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -10,6 +13,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.GameRenderer; @@ -22,13 +26,16 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.util.Identifier; import net.minecraft.util.math.Matrix4f; import net.minecraft.util.math.Vec3f; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @Mixin(WorldRenderer.class) @Environment(EnvType.CLIENT) -public class WorldRendererMixin { +public abstract class WorldRendererMixin { @Unique private static final Identifier MOON_RENDER_PATH = new Identifier("dimdoors:textures/other/limbo_moon.png"); @Unique @@ -37,10 +44,15 @@ public class WorldRendererMixin { @Shadow private ClientWorld world; + @Shadow + private MinecraftClient client; + @Shadow @Final private static Identifier END_SKY; + @Shadow protected abstract void renderEndSky(MatrixStack matrices); + @Inject(method = "renderSky", at = @At("HEAD"), cancellable = true) public void beforeRenderSky(MatrixStack matrices, Matrix4f matrix4f, float f, Runnable runnable, CallbackInfo ci) { if (ModDimensions.isLimboDimension(this.world)) { @@ -50,6 +62,23 @@ public class WorldRendererMixin { this.renderPocketSky(matrices, 255, 255, 255); ci.cancel(); } else if (ModDimensions.isPocketDimension(this.world)) { + Pocket pocket = DimensionalRegistry.getPocketDirectory(this.world.getRegistryKey()).getPocketAt(client.player.getBlockPos()); + + if(pocket != null && pocket.hasAddon(SkyAddon.ID)) { + RegistryKey world = pocket.getAddon(SkyAddon.ID).getWorld(); + + if(world.equals(World.END)) { + this.renderEndSky(matrices); + ci.cancel(); + } else if(world.equals(ModDimensions.LIMBO)) { + this.renderLimboSky(matrices); + ci.cancel(); + } else if(ModDimensions.isPocketDimension(world)) { + this.renderPocketSky(matrices, 255, 255, 255); + ci.cancel(); + } + } + this.renderPocketSky(matrices, 0, 0, 0); ci.cancel(); } diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/PocketAddon.java b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/PocketAddon.java index 1e8cd3ac..5b2cd886 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/PocketAddon.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/PocketAddon.java @@ -84,6 +84,7 @@ public interface PocketAddon { PocketAddonType DYEABLE_ADDON = register(DyeableAddon.ID, DyeableAddon::new, DyeableAddon.DyeableBuilderAddon::new); PocketAddonType PREVENT_BLOCK_MODIFICATION_ADDON = register(PreventBlockModificationAddon.ID, PreventBlockModificationAddon::new, PreventBlockModificationAddon.PreventBlockModificationBuilderAddon::new); PocketAddonType BLOCK_BREAK_CONTAINER = register(BlockBreakContainer.ID, BlockBreakContainer::new, null); + PocketAddonType SKY_ADDON = register(SkyAddon.ID, SkyAddon::new, SkyAddon.SkyBuilderAddon::new); T fromNbt(NbtCompound nbt); diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java new file mode 100644 index 00000000..01e05781 --- /dev/null +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java @@ -0,0 +1,132 @@ +package org.dimdev.dimdoors.world.pocket.type.addon; + +import java.io.IOException; + +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; + +import org.dimdev.dimdoors.world.pocket.type.Pocket; +import org.dimdev.dimdoors.world.pocket.type.PrivatePocket; + +public class SkyAddon implements AutoSyncedAddon { + public static Identifier ID = new Identifier("dimdoors", "sky"); + + private RegistryKey world; + + @Override + public boolean applicable(Pocket pocket) { + return pocket instanceof PrivatePocket; + } + + public boolean setWorld(RegistryKey world) { + this.world = world; + return true; + } + + @Override + public PocketAddon fromNbt(NbtCompound nbt) { + this.world = RegistryKey.of(Registry.WORLD_KEY, Identifier.tryParse(nbt.getString("world"))); + + return this; + } + + @Override + public NbtCompound toNbt(NbtCompound nbt) { + AutoSyncedAddon.super.toNbt(nbt); + + nbt.putString("world", this.world.getValue().toString()); + + return nbt; + } + + @Override + public PocketAddonType getType() { + return PocketAddonType.SKY_ADDON; + } + + @Override + public Identifier getId() { + return ID; + } + + public RegistryKey getWorld() { + return world; + } + + @Override + public AutoSyncedAddon read(PacketByteBuf buf) throws IOException { + this.world = RegistryKey.of(Registry.WORLD_KEY, buf.readIdentifier()); + return this; + } + + @Override + public PacketByteBuf write(PacketByteBuf buf) throws IOException { + buf.writeIdentifier(world.getValue()); + return buf; + } + + public interface SkyPocketBuilder> extends PocketBuilderExtension { + default T world(RegistryKey world) { + + this.getAddon(ID).world = world; + + return getSelf(); + } + } + + public static class SkyBuilderAddon implements PocketBuilderAddon { + + private RegistryKey world = World.OVERWORLD; + // TODO: add some Pocket#init so that we can have boolean shouldRepaintOnInit + + @Override + public void apply(Pocket pocket) { + SkyAddon addon = new SkyAddon(); + addon.world = world; + pocket.addAddon(addon); + } + + @Override + public Identifier getId() { + return ID; + } + + @Override + public PocketBuilderAddon fromNbt(NbtCompound nbt) { + this.world = RegistryKey.of(Registry.WORLD_KEY, Identifier.tryParse(nbt.getString("world"))); + + return this; + } + + @Override + public NbtCompound toNbt(NbtCompound nbt) { + PocketBuilderAddon.super.toNbt(nbt); + + nbt.putString("world", world.getValue().toString()); + + return nbt; + } + + @Override + public PocketAddonType getType() { + return PocketAddonType.SKY_ADDON; + } + } + + public interface SkyPocket extends AddonProvider { + default boolean sky(RegistryKey world) { + ensureIsPocket(); + if (!this.hasAddon(ID)) { + SkyAddon addon = new SkyAddon(); + this.addAddon(addon); + return addon.setWorld(world); + } + return this.getAddon(ID).setWorld(world); + } + } +} From c761b968307328a9e5cee27008e7ba949c0293d3 Mon Sep 17 00:00:00 2001 From: CreepyCre Date: Mon, 14 Jun 2021 16:21:08 +0200 Subject: [PATCH 2/3] fix math bug in GridUtil --- src/main/java/org/dimdev/dimdoors/api/util/math/GridUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dimdev/dimdoors/api/util/math/GridUtil.java b/src/main/java/org/dimdev/dimdoors/api/util/math/GridUtil.java index d3417a02..f62a4719 100644 --- a/src/main/java/org/dimdev/dimdoors/api/util/math/GridUtil.java +++ b/src/main/java/org/dimdev/dimdoors/api/util/math/GridUtil.java @@ -16,8 +16,8 @@ public final class GridUtil { } public GridPos(BlockPos pos, int gridSize) { - this.x = pos.getX() / gridSize / 16; - this.z = pos.getZ() / gridSize / 16; + this.x = Math.floorDiv(Math.floorDiv(pos.getX(), gridSize), 16); + this.z = Math.floorDiv(Math.floorDiv(pos.getZ(), gridSize), 16); } @Override From c5a082f2fd8982193b625933bf9a9155904b3b05 Mon Sep 17 00:00:00 2001 From: CreepyCre Date: Mon, 14 Jun 2021 16:29:08 +0200 Subject: [PATCH 3/3] fix SkyAddon & end lantredom now has end sky --- .../mixin/client/WorldRendererMixin.java | 50 +++++++++++-------- .../world/pocket/type/addon/SkyAddon.java | 8 --- .../generators/dungeon/lantredom_end.json | 8 ++- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java b/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java index a584bb5a..1c982a06 100644 --- a/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java +++ b/src/main/java/org/dimdev/dimdoors/mixin/client/WorldRendererMixin.java @@ -1,9 +1,8 @@ package org.dimdev.dimdoors.mixin.client; import com.mojang.blaze3d.systems.RenderSystem; +import org.dimdev.dimdoors.listener.pocket.PocketListenerUtil; import org.dimdev.dimdoors.world.ModDimensions; -import org.dimdev.dimdoors.world.level.registry.DimensionalRegistry; -import org.dimdev.dimdoors.world.pocket.type.Pocket; import org.dimdev.dimdoors.world.pocket.type.addon.SkyAddon; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -33,6 +32,8 @@ import net.minecraft.world.World; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import java.util.List; + @Mixin(WorldRenderer.class) @Environment(EnvType.CLIENT) public abstract class WorldRendererMixin { @@ -51,10 +52,32 @@ public abstract class WorldRendererMixin { @Final private static Identifier END_SKY; - @Shadow protected abstract void renderEndSky(MatrixStack matrices); + @Shadow + protected abstract void renderEndSky(MatrixStack matrices); @Inject(method = "renderSky", at = @At("HEAD"), cancellable = true) public void beforeRenderSky(MatrixStack matrices, Matrix4f matrix4f, float f, Runnable runnable, CallbackInfo ci) { + List skyAddons = PocketListenerUtil.applicableAddonsClient(SkyAddon.class, this.world, this.client.gameRenderer.getCamera().getBlockPos()); + SkyAddon skyAddon = null; + if (skyAddons.size() > 0) { + // There should really only be one of these. + // If anyone needs to use multiple SkyAddons then go ahead and change this. + skyAddon = skyAddons.get(0); + } + + if (skyAddon != null) { + RegistryKey world = skyAddon.getWorld(); + + if (world.equals(World.END)) { + this.renderEndSky(matrices); + ci.cancel(); + return; + } else if (world.equals(ModDimensions.LIMBO)) { + this.renderLimboSky(matrices); + ci.cancel(); + return; + } + } if (ModDimensions.isLimboDimension(this.world)) { renderLimboSky(matrices); ci.cancel(); @@ -62,23 +85,6 @@ public abstract class WorldRendererMixin { this.renderPocketSky(matrices, 255, 255, 255); ci.cancel(); } else if (ModDimensions.isPocketDimension(this.world)) { - Pocket pocket = DimensionalRegistry.getPocketDirectory(this.world.getRegistryKey()).getPocketAt(client.player.getBlockPos()); - - if(pocket != null && pocket.hasAddon(SkyAddon.ID)) { - RegistryKey world = pocket.getAddon(SkyAddon.ID).getWorld(); - - if(world.equals(World.END)) { - this.renderEndSky(matrices); - ci.cancel(); - } else if(world.equals(ModDimensions.LIMBO)) { - this.renderLimboSky(matrices); - ci.cancel(); - } else if(ModDimensions.isPocketDimension(world)) { - this.renderPocketSky(matrices, 255, 255, 255); - ci.cancel(); - } - } - this.renderPocketSky(matrices, 0, 0, 0); ci.cancel(); } @@ -102,7 +108,7 @@ public abstract class WorldRendererMixin { RenderSystem.setShader(GameRenderer::getPositionTexColorShader); RenderSystem.setShaderColor(1, 1, 1, 1); - for(int i = 0; i < 6; ++i) { + for (int i = 0; i < 6; ++i) { matrices.push(); if (i == 1) { matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F)); @@ -165,7 +171,7 @@ public abstract class WorldRendererMixin { Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - for(int i = 0; i < 6; ++i) { + for (int i = 0; i < 6; ++i) { matrices.push(); if (i == 1) { matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F)); diff --git a/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java index 01e05781..2511cd0b 100644 --- a/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java +++ b/src/main/java/org/dimdev/dimdoors/world/pocket/type/addon/SkyAddon.java @@ -2,7 +2,6 @@ package org.dimdev.dimdoors.world.pocket.type.addon; import java.io.IOException; -import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; @@ -11,18 +10,12 @@ import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import org.dimdev.dimdoors.world.pocket.type.Pocket; -import org.dimdev.dimdoors.world.pocket.type.PrivatePocket; public class SkyAddon implements AutoSyncedAddon { public static Identifier ID = new Identifier("dimdoors", "sky"); private RegistryKey world; - @Override - public boolean applicable(Pocket pocket) { - return pocket instanceof PrivatePocket; - } - public boolean setWorld(RegistryKey world) { this.world = world; return true; @@ -82,7 +75,6 @@ public class SkyAddon implements AutoSyncedAddon { public static class SkyBuilderAddon implements PocketBuilderAddon { private RegistryKey world = World.OVERWORLD; - // TODO: add some Pocket#init so that we can have boolean shouldRepaintOnInit @Override public void apply(Pocket pocket) { diff --git a/src/main/resources/resourcepacks/default/data/dimdoors/pockets/generators/dungeon/lantredom_end.json b/src/main/resources/resourcepacks/default/data/dimdoors/pockets/generators/dungeon/lantredom_end.json index e4231fb6..e2588e98 100644 --- a/src/main/resources/resourcepacks/default/data/dimdoors/pockets/generators/dungeon/lantredom_end.json +++ b/src/main/resources/resourcepacks/default/data/dimdoors/pockets/generators/dungeon/lantredom_end.json @@ -2,7 +2,13 @@ "type": "dimdoors:schematic", "id": "dungeon/lantredom_end", "builder": { - "type": "dimdoors:lazy_gen_pocket" + "type": "dimdoors:lazy_gen_pocket", + "addons": [ + { + "type": "dimdoors:sky", + "world": "minecraft:the_end" + } + ] }, "modifiers": [ {