Attempt at sky rendering showing Addon.

This commit is contained in:
Waterpicker 2021-06-14 05:31:35 -05:00
parent 68586452bd
commit cb7e12ecb0
3 changed files with 163 additions and 1 deletions

View file

@ -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> world = pocket.<SkyAddon>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();
}

View file

@ -84,6 +84,7 @@ public interface PocketAddon {
PocketAddonType<DyeableAddon> DYEABLE_ADDON = register(DyeableAddon.ID, DyeableAddon::new, DyeableAddon.DyeableBuilderAddon::new);
PocketAddonType<PreventBlockModificationAddon> PREVENT_BLOCK_MODIFICATION_ADDON = register(PreventBlockModificationAddon.ID, PreventBlockModificationAddon::new, PreventBlockModificationAddon.PreventBlockModificationBuilderAddon::new);
PocketAddonType<BlockBreakContainer> BLOCK_BREAK_CONTAINER = register(BlockBreakContainer.ID, BlockBreakContainer::new, null);
PocketAddonType<SkyAddon> SKY_ADDON = register(SkyAddon.ID, SkyAddon::new, SkyAddon.SkyBuilderAddon::new);
T fromNbt(NbtCompound nbt);

View file

@ -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> world;
@Override
public boolean applicable(Pocket pocket) {
return pocket instanceof PrivatePocket;
}
public boolean setWorld(RegistryKey<World> 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<? extends PocketAddon> getType() {
return PocketAddonType.SKY_ADDON;
}
@Override
public Identifier getId() {
return ID;
}
public RegistryKey<World> 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<T extends Pocket.PocketBuilder<T, ?>> extends PocketBuilderExtension<T> {
default T world(RegistryKey<World> world) {
this.<SkyBuilderAddon>getAddon(ID).world = world;
return getSelf();
}
}
public static class SkyBuilderAddon implements PocketBuilderAddon<SkyAddon> {
private RegistryKey<World> 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<SkyAddon> 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<SkyAddon> getType() {
return PocketAddonType.SKY_ADDON;
}
}
public interface SkyPocket extends AddonProvider {
default boolean sky(RegistryKey<World> world) {
ensureIsPocket();
if (!this.hasAddon(ID)) {
SkyAddon addon = new SkyAddon();
this.addAddon(addon);
return addon.setWorld(world);
}
return this.<SkyAddon>getAddon(ID).setWorld(world);
}
}
}