Skip to content

Commit

Permalink
What the hell mc
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudje committed Mar 4, 2024
1 parent 6f7705a commit 97e4b3e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
2 changes: 1 addition & 1 deletion minecraft/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
implementation "org.jgrapht:jgrapht-ext:1.5.1"
implementation 'com.github.vlsi.mxgraph:jgraphx:4.2.2'
implementation 'org.jacop:jacop:4.9.0'
implementation 'com.ewoudje:eggui-jvm:0.1.0+14628d66f1'
implementation 'com.ewoudje:eggui-jvm:0.1.0+d003f1794a'
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.ewoudje.lasagna.mixin.scaleblocks.client;

import com.ewoudje.lasagna.scaleblocks.ScaledSectionStorage;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.ChunkBufferBuilderPack;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.client.renderer.chunk.RenderChunkRegion;
import net.minecraft.client.renderer.chunk.VisGraph;
Expand All @@ -12,6 +14,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -26,13 +29,23 @@ public class MixinRenderChunk {
// The 'this' of the outer class
@Shadow @Final ChunkRenderDispatcher.RenderChunk field_20839;

@Inject(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getBlockRenderer()Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;"), locals = LocalCapture.CAPTURE_FAILHARD)
private void compile(float x, float y, float z, ChunkRenderDispatcher.CompiledChunk compiledChunk, ChunkBufferBuilderPack buffers, CallbackInfoReturnable<Set<BlockEntity>> cir, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph visGraph, Set set, RenderChunkRegion region, PoseStack poseStack, Random random) {
var sections = ((ScaledSectionsProvider) region).getScaledSectionsAt(this.field_20839.getOrigin());
@Unique private Set<ScaledSectionStorage> lasagna_lib$storage = null;

for (var section : sections) {
@Inject(method = "compile", at =
@At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;getBlockRenderer()Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;"), locals = LocalCapture.CAPTURE_FAILHARD)
private void getSections(float x, float y, float z, ChunkRenderDispatcher.CompiledChunk compiledChunk, ChunkBufferBuilderPack buffers, CallbackInfoReturnable<Set<BlockEntity>> cir, int i, BlockPos blockPos, BlockPos blockPos2, VisGraph visGraph, Set set, RenderChunkRegion region, PoseStack poseStack, Random random) {
lasagna_lib$storage = ((ScaledSectionsProvider) region).getScaledSectionsAt(this.field_20839.getOrigin());
}

@Inject(method = "compile", at = @At(value = "INVOKE", target = "Ljava/util/Set;stream()Ljava/util/stream/Stream;"))
private void renderSections(float x, float y, float z, ChunkRenderDispatcher.CompiledChunk compiledChunk, ChunkBufferBuilderPack buffers, CallbackInfoReturnable<Set<BlockEntity>> cir) {
if (compiledChunk.isEmpty(RenderType.solid())) return; // TODO make the layer if it not exists instead of just not rendering it

for (var section : lasagna_lib$storage) {
ScaledSectionRenderer.compile(section, x, y, z, compiledChunk, buffers);
}

lasagna_lib$storage = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,3 @@ class Serialization<T>(
// val size: Int,
val packetClass: Class<T>
): RegistryItem<Serialization<*>>


private fun<T> getSizeOfDecode(decode: (FriendlyByteBuf) -> T): Int {
val buf = FriendlyByteBuf(LengthByteBuf())
decode(buf)
return buf.writerIndex()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.ewoudje.lasagna.scaleblocks
import com.ewoudje.lasagna.api.Identifiable
import com.ewoudje.lasagna.chunkstorage.ExtraSectionStorage
import com.ewoudje.lasagna.kodec.codec
import com.mojang.serialization.Codec
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.nbt.NbtOps
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.level.block.Block
Expand Down Expand Up @@ -50,7 +52,14 @@ class ScaledSectionStorage(val view: ScaleBlocksView, override val id: ResourceL
.getOrThrow(false, ::RuntimeException)
)

// TODO write states
val list = ListTag()
states.forEach {
BLOCK_STATE_CODEC.encode(it, NbtOps.INSTANCE, CompoundTag())
.getOrThrow(false, ::RuntimeException)
.let(list::add)
}

storage.put("states", list)

return storage
}
Expand All @@ -63,8 +72,19 @@ class ScaledSectionStorage(val view: ScaleBlocksView, override val id: ResourceL
.getOrThrow(false, ::RuntimeException).first,
ResourceLocation(storage.getString("id"))
).apply {
// TODO read states
val list = storage.getList("states", 10)
for (i in 0 until list.size) {
states[i] = BLOCK_STATE_CODEC.decode(NbtOps.INSTANCE, list.getCompound(i))
.getOrThrow(false, ::RuntimeException).first
}
}


private val BLOCK_STATE_CODEC: Codec<PalettedContainer<BlockState>> = PalettedContainer.codec(
Block.BLOCK_STATE_REGISTRY,
BlockState.CODEC,
PalettedContainer.Strategy.SECTION_STATES,
Blocks.AIR.defaultBlockState()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void writeExtraChunkData(ServerLevel level, ChunkAccess chunk, Ca
method = "read",
at = @At(value = "RETURN", ordinal = 0)
)
private static void readExtraChunkData(ServerLevel lvel,
private static void readExtraChunkData(ServerLevel level,
PoiManager poiManager,
ChunkPos pos, CompoundTag tag,
CallbackInfoReturnable<ProtoChunk> cir) {
Expand All @@ -57,9 +57,10 @@ private static void readExtraChunkData(ServerLevel lvel,
ImposterProtoChunk chunk = (ImposterProtoChunk) cir.getReturnValue();
ListTag listTag = tag.getList("sections", 10);

for (int index = 0; index < chunk.getSectionsCount(); index++) {
for (int index = 0; index < chunk.getSections().length; index++) {
CompoundTag sectionNbt = listTag.getCompound(index);
ChunkSerializerHelper.INSTANCE.read(chunk.getWrapped(), sectionNbt, index);
ChunkSerializerHelper.INSTANCE.read(chunk.getWrapped(), sectionNbt,
level.getSectionIndexFromSectionY(sectionNbt.getByte("Y")));
}
}
}

0 comments on commit 97e4b3e

Please sign in to comment.