mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
add ProtoChunkMixin and WorldChunkMixin
This commit is contained in:
@@ -54,6 +54,6 @@ public abstract class ChunkRegionMixin {
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return (ChunkRegion) (Object) this;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.fabric.mixin.world;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.ProtoChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(ProtoChunk.class)
|
||||
@Implements(@Interface(iface = ChunkData.class, prefix = "vw$"))
|
||||
public abstract class ProtoChunkMixin {
|
||||
@Shadow
|
||||
public abstract BlockState getBlockState(BlockPos pos);
|
||||
|
||||
public @NotNull BlockData vw$getBlockData(int x, int y, int z) {
|
||||
return new FabricBlockData(getBlockState(new BlockPos(x, y, z)));
|
||||
}
|
||||
|
||||
public void vw$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public int vw$getMaxHeight() {
|
||||
return 255; // TODO: 1.17 - Implement dynamic height.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.dfsek.terra.fabric.mixin.world;
|
||||
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorld;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(WorldChunk.class)
|
||||
@Implements(@Interface(iface = Chunk.class, prefix = "vw$"))
|
||||
public abstract class WorldChunkMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private net.minecraft.world.World world;
|
||||
|
||||
public int vw$getX() {
|
||||
return ((net.minecraft.world.chunk.Chunk) this).getPos().x;
|
||||
}
|
||||
|
||||
public int vw$getZ() {
|
||||
return ((net.minecraft.world.chunk.Chunk) this).getPos().z;
|
||||
}
|
||||
|
||||
public World vw$getWorld() {
|
||||
return new FabricWorld((ServerWorld) world, new FabricChunkGenerator(((ServerWorld) world).getChunkManager().getChunkGenerator()));
|
||||
}
|
||||
|
||||
public Block vw$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (vw$getX() << 4), y, z + (vw$getZ() << 4));
|
||||
return new FabricBlock(pos, world);
|
||||
}
|
||||
|
||||
public @NotNull BlockData vw$getBlockData(int x, int y, int z) {
|
||||
return vw$getBlock(x, y, z).getBlockData();
|
||||
}
|
||||
|
||||
public void vw$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
((net.minecraft.world.chunk.Chunk) this).setBlockState(new BlockPos(x, y, z), ((FabricBlockData) blockData).getHandle(), false);
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.fabric.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkData;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.util.FastRandom;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
@@ -88,7 +89,7 @@ public class FabricChunkGeneratorWrapper extends ChunkGenerator implements Gener
|
||||
@Override
|
||||
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
|
||||
FabricSeededWorldAccess worldAccess = new FabricSeededWorldAccess(world, seed, this);
|
||||
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, new FabricChunkData(chunk));
|
||||
delegate.generateChunkData(worldAccess, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinGeneratorOptions",
|
||||
"world.ChunkRegionMixin"
|
||||
"world.ChunkRegionMixin",
|
||||
"world.ProtoChunkMixin",
|
||||
"world.WorldChunkMixin"
|
||||
],
|
||||
"client": [
|
||||
"GeneratorTypeAccessor"
|
||||
|
||||
Reference in New Issue
Block a user