mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-07 16:26:13 +00:00
implement ChunkRegionMixin
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
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(ChunkRegion.class)
|
||||
@Implements(@Interface(iface = Chunk.class, prefix = "vw$"))
|
||||
public abstract class ChunkRegionMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private int centerChunkX;
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private int centerChunkZ;
|
||||
|
||||
public int vw$getX() {
|
||||
return centerChunkX;
|
||||
}
|
||||
|
||||
public int vw$getZ() {
|
||||
return centerChunkZ;
|
||||
}
|
||||
|
||||
public World vw$getWorld() {
|
||||
return new FabricWorldAccess((ChunkRegion) (Object) this);
|
||||
}
|
||||
|
||||
public Block vw$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4));
|
||||
return new FabricBlock(pos, (ChunkRegion) (Object) this);
|
||||
}
|
||||
|
||||
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) {
|
||||
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerChunkX << 4), y, z + (centerChunkZ << 4)), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return (ChunkRegion) (Object) this;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.dfsek.terra.fabric.world.features;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorld;
|
||||
import com.dfsek.terra.fabric.world.handles.chunk.FabricChunkWorldAccess;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -25,9 +24,8 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
|
||||
FabricChunkWorldAccess chunk = new FabricChunkWorldAccess(world, pos.getX() >> 4, pos.getZ() >> 4);
|
||||
FabricWorld world1 = new FabricWorld(world.toServerWorld(), new FabricChunkGenerator(chunkGenerator));
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate(world1, chunk));
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate(world1, (Chunk) world));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.handles.chunk;
|
||||
|
||||
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.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FabricChunkWorldAccess implements Chunk {
|
||||
private final WorldAccess chunkRegion;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
public FabricChunkWorldAccess(WorldAccess chunkRegion, int x, int z) {
|
||||
this.chunkRegion = chunkRegion;
|
||||
this.x = x << 4;
|
||||
this.z = z << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return x >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return z >> 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return new FabricWorldAccess(chunkRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + this.x, y, z + this.z);
|
||||
return new FabricBlock(pos, chunkRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldAccess getHandle() {
|
||||
return chunkRegion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
chunkRegion.setBlockState(new BlockPos(x + this.x, y, z + this.z), ((FabricBlockData) blockData).getHandle(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockData getBlockData(int x, int y, int z) {
|
||||
return getBlock(x, y, z).getBlockData();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
"package": "com.dfsek.terra.fabric.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinGeneratorOptions"
|
||||
"MixinGeneratorOptions",
|
||||
"world.ChunkRegionMixin"
|
||||
],
|
||||
"client": [
|
||||
"GeneratorTypeAccessor"
|
||||
|
||||
Reference in New Issue
Block a user