mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
finish World mixins
This commit is contained in:
@@ -3,14 +3,11 @@ package com.dfsek.terra.fabric.mixin.entity;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@@ -43,16 +40,16 @@ public abstract class EntityMixin {
|
||||
}
|
||||
|
||||
public Location vw$getLocation() {
|
||||
return new Location(new FabricWorldAccess(world), FabricAdapter.adapt(blockPos));
|
||||
return new Location((World) world, FabricAdapter.adapt(blockPos));
|
||||
}
|
||||
|
||||
public void vw$setLocation(Location location) {
|
||||
teleport(location.getX(), location.getY(), location.getZ());
|
||||
moveToWorld((ServerWorld) ((FabricWorldHandle) location).getWorld());
|
||||
moveToWorld((ServerWorld) location.getWorld());
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return new FabricWorldAccess(world);
|
||||
return (World) world;
|
||||
}
|
||||
|
||||
public void vw$sendMessage(String message) {
|
||||
|
||||
@@ -6,8 +6,6 @@ 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;
|
||||
@@ -37,7 +35,7 @@ public abstract class ChunkRegionMixin {
|
||||
}
|
||||
|
||||
public World vw$getWorld() {
|
||||
return new FabricWorldAccess((ChunkRegion) (Object) this);
|
||||
return (World) this;
|
||||
}
|
||||
|
||||
public Block vw$getBlock(int x, int y, int z) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.dfsek.terra.fabric.mixin.world;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ChunkRegion.class)
|
||||
@Implements(@Interface(iface = World.class, prefix = "vw$"))
|
||||
public abstract class ChunkRegionWorldMixin {
|
||||
public int vw$getMaxHeight() {
|
||||
return ((ChunkRegion) (Object) this).getDimensionHeight();
|
||||
}
|
||||
|
||||
public ChunkGenerator vw$getGenerator() {
|
||||
return (ChunkGenerator) ((ChunkRegion) (Object) this).toServerWorld().getChunkManager().getChunkGenerator();
|
||||
}
|
||||
|
||||
public Chunk vw$getChunkAt(int x, int z) {
|
||||
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public Block vw$getBlockAt(int x, int y, int z) {
|
||||
return new FabricBlock(new BlockPos(x, y, z), ((ChunkRegion) (Object) this));
|
||||
}
|
||||
|
||||
public Entity vw$spawnEntity(Location location, EntityType entityType) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int vw$getMinHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean vw$isTerraWorld() {
|
||||
return vw$getGenerator() instanceof GeneratorWrapper;
|
||||
}
|
||||
|
||||
public TerraChunkGenerator vw$getTerraGenerator() {
|
||||
return ((FabricChunkGeneratorWrapper) vw$getGenerator()).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.dfsek.terra.fabric.mixin.world;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ServerWorld.class)
|
||||
@Implements(@Interface(iface = World.class, prefix = "vw$"))
|
||||
public abstract class ServerWorldMixin {
|
||||
public int vw$getMaxHeight() {
|
||||
return ((ServerWorld) (Object) this).getDimensionHeight();
|
||||
}
|
||||
|
||||
public ChunkGenerator vw$getGenerator() {
|
||||
return (ChunkGenerator) ((ServerWorld) (Object) this).getChunkManager().getChunkGenerator();
|
||||
}
|
||||
|
||||
public Chunk vw$getChunkAt(int x, int z) {
|
||||
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public Block vw$getBlockAt(int x, int y, int z) {
|
||||
return new FabricBlock(new BlockPos(x, y, z), ((ServerWorld) (Object) this));
|
||||
}
|
||||
|
||||
public Entity vw$spawnEntity(Location location, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ServerWorld) (Object) this));
|
||||
entity.setPos(location.getX(), location.getY(), location.getZ());
|
||||
((ServerWorld) (Object) this).spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
public int vw$getMinHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object vw$getHandle() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean vw$isTerraWorld() {
|
||||
return vw$getGenerator() instanceof GeneratorWrapper;
|
||||
}
|
||||
|
||||
public TerraChunkGenerator vw$getTerraGenerator() {
|
||||
return ((FabricChunkGeneratorWrapper) vw$getGenerator()).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,8 @@ 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.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorld;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -34,7 +31,7 @@ public abstract class WorldChunkMixin {
|
||||
}
|
||||
|
||||
public World vw$getWorld() {
|
||||
return new FabricWorld((ServerWorld) world, (ChunkGenerator) ((ServerWorld) world).getChunkManager().getChunkGenerator());
|
||||
return (World) world;
|
||||
}
|
||||
|
||||
public Block vw$getBlock(int x, int y, int z) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.dfsek.terra.fabric.world;
|
||||
import com.dfsek.terra.api.math.vector.Vector3;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlockType;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricDirectional;
|
||||
@@ -13,14 +12,11 @@ import com.dfsek.terra.fabric.world.block.data.FabricRotatable;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricSlab;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricStairs;
|
||||
import com.dfsek.terra.fabric.world.block.data.FabricWaterlogged;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -75,8 +71,4 @@ public final class FabricAdapter {
|
||||
public static BlockType adapt(Block block) {
|
||||
return new FabricBlockType(block);
|
||||
}
|
||||
|
||||
public WorldAccess adapt(FabricWorldHandle worldHandle) {
|
||||
return worldHandle.getWorld();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.world.Tree;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import com.dfsek.terra.profiler.ProfileFrame;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -27,9 +26,9 @@ public class FabricTree implements Tree {
|
||||
@SuppressWarnings("try")
|
||||
public boolean plant(Location l, Random r) {
|
||||
try(ProfileFrame ignore = TerraFabricPlugin.getInstance().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
|
||||
FabricWorldAccess fabricWorldAccess = ((FabricWorldAccess) l.getWorld());
|
||||
ChunkGenerator generatorWrapper = (ChunkGenerator) fabricWorldAccess.getGenerator();
|
||||
return delegate.generate((StructureWorldAccess) fabricWorldAccess.getHandle(), generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) l.getWorld());
|
||||
ChunkGenerator generatorWrapper = (ChunkGenerator) l.getWorld().getGenerator();
|
||||
return delegate.generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.block.BlockType;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.world.block.state.FabricBlockState;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
@@ -51,7 +51,7 @@ public class FabricBlock implements Block {
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return FabricAdapter.adapt(delegate.position).toLocation(new FabricWorldAccess(delegate.worldAccess));
|
||||
return FabricAdapter.adapt(delegate.position).toLocation((World) delegate.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.dfsek.terra.api.platform.block.BlockData;
|
||||
import com.dfsek.terra.api.platform.block.state.BlockState;
|
||||
import com.dfsek.terra.fabric.world.FabricAdapter;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
@@ -22,7 +21,7 @@ public class FabricBlockState implements BlockState {
|
||||
}
|
||||
|
||||
public static FabricBlockState newInstance(Block block) {
|
||||
WorldAccess worldAccess = ((FabricWorldHandle) block.getLocation().getWorld()).getWorld();
|
||||
WorldAccess worldAccess = (WorldAccess) block.getLocation().getWorld();
|
||||
|
||||
BlockEntity entity = worldAccess.getBlockEntity(FabricAdapter.adapt(block.getLocation().toVector()));
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.fabric.world.features;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.handles.FabricWorld;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
@@ -23,8 +23,7 @@ public class PopulatorFeature extends Feature<DefaultFeatureConfig> {
|
||||
@Override
|
||||
public boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig config) {
|
||||
FabricChunkGeneratorWrapper gen = (FabricChunkGeneratorWrapper) chunkGenerator;
|
||||
FabricWorld world1 = new FabricWorld(world.toServerWorld(), (com.dfsek.terra.api.platform.world.generator.ChunkGenerator) chunkGenerator);
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate(world1, (Chunk) world));
|
||||
gen.getHandle().getPopulators().forEach(populator -> populator.populate((World) world, (Chunk) world));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.fabric.world.generator;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
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;
|
||||
@@ -7,7 +8,6 @@ import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.config.pack.ConfigPack;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
import com.dfsek.terra.fabric.world.TerraBiomeSource;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricSeededWorldAccess;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
|
||||
import com.dfsek.terra.world.generation.math.samplers.Sampler;
|
||||
@@ -83,8 +83,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, (ChunkData) chunk);
|
||||
delegate.generateChunkData((World) world, new FastRandom(), chunk.getPos().x, chunk.getPos().z, (ChunkData) chunk);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.handles;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.world.handles.world.FabricWorldHandle;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class FabricWorld implements World, FabricWorldHandle {
|
||||
|
||||
private final Handle delegate;
|
||||
|
||||
public FabricWorld(ServerWorld world, ChunkGenerator generator) {
|
||||
this.delegate = new Handle(world, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return delegate.world.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.world.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return delegate.generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return (Chunk) delegate.world.getChunk(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(pos, delegate.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((ServerWorldAccess) delegate.world).toServerWorld().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof FabricWorld)) return false;
|
||||
return ((ServerWorldAccess) ((FabricWorld) obj).delegate.world).toServerWorld().equals(((ServerWorldAccess) delegate.world).toServerWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(delegate.world);
|
||||
entity.setPos(location.getX(), location.getY(), location.getZ());
|
||||
delegate.world.spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handle getHandle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldAccess getWorld() {
|
||||
return delegate.getWorld();
|
||||
}
|
||||
|
||||
public static final class Handle {
|
||||
private final ServerWorld world;
|
||||
private final ChunkGenerator generator;
|
||||
|
||||
private Handle(ServerWorld world, ChunkGenerator generator) {
|
||||
this.world = world;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public ChunkGenerator getGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
public ServerWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerraWorld() {
|
||||
return delegate.generator instanceof GeneratorWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getTerraGenerator() {
|
||||
return ((FabricChunkGeneratorWrapper) delegate.generator).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class FabricSeededWorldAccess implements World, FabricWorldHandle {
|
||||
|
||||
private final Handle handle;
|
||||
|
||||
public FabricSeededWorldAccess(WorldAccess access, long seed, net.minecraft.world.gen.chunk.ChunkGenerator generator) {
|
||||
this.handle = new Handle(access, seed, generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return handle.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return handle.getWorldAccess().getDimensionHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return (ChunkGenerator) handle.getGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(pos, handle.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create((ServerWorld) handle.worldAccess);
|
||||
entity.setPos(location.getX(), location.getY(), location.getZ());
|
||||
handle.worldAccess.spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((ServerWorldAccess) handle.worldAccess).toServerWorld().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof FabricSeededWorldAccess)) return false;
|
||||
return ((ServerWorldAccess) ((FabricSeededWorldAccess) obj).handle.worldAccess).toServerWorld().equals(((ServerWorldAccess) handle.worldAccess).toServerWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handle getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldAccess getWorld() {
|
||||
return handle.worldAccess;
|
||||
}
|
||||
|
||||
public static class Handle {
|
||||
private final WorldAccess worldAccess;
|
||||
private final long seed;
|
||||
private final net.minecraft.world.gen.chunk.ChunkGenerator generator;
|
||||
|
||||
public Handle(WorldAccess worldAccess, long seed, net.minecraft.world.gen.chunk.ChunkGenerator generator) {
|
||||
this.worldAccess = worldAccess;
|
||||
this.seed = seed;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public net.minecraft.world.gen.chunk.ChunkGenerator getGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public WorldAccess getWorldAccess() {
|
||||
return worldAccess;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerraWorld() {
|
||||
return handle.generator instanceof GeneratorWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getTerraGenerator() {
|
||||
return ((FabricChunkGeneratorWrapper) handle.generator).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.entity.Entity;
|
||||
import com.dfsek.terra.api.platform.entity.EntityType;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.platform.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.platform.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generation.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.world.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.world.generator.FabricChunkGeneratorWrapper;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.StructureWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class FabricWorldAccess implements World, FabricWorldHandle {
|
||||
private final WorldAccess delegate;
|
||||
|
||||
public FabricWorldAccess(WorldAccess delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return ((StructureWorldAccess) delegate).getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return delegate.getDimensionHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return (ChunkGenerator) ((ServerWorldAccess) delegate).toServerWorld().getChunkManager().getChunkGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlockAt(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
return new FabricBlock(pos, delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, EntityType entityType) {
|
||||
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ServerWorldAccess) delegate).toServerWorld());
|
||||
entity.setPos(location.getX(), location.getY(), location.getZ());
|
||||
delegate.spawnEntity(entity);
|
||||
return (Entity) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldAccess getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldAccess getWorld() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return ((ServerWorldAccess) delegate).toServerWorld().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof FabricWorldAccess)) return false;
|
||||
return ((ServerWorldAccess) ((FabricWorldAccess) obj).delegate).toServerWorld().equals(((ServerWorldAccess) delegate).toServerWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerraWorld() {
|
||||
return getGenerator() instanceof GeneratorWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerraChunkGenerator getTerraGenerator() {
|
||||
return ((FabricChunkGeneratorWrapper) getGenerator()).getHandle();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.dfsek.terra.fabric.world.handles.world;
|
||||
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public interface FabricWorldHandle {
|
||||
WorldAccess getWorld();
|
||||
}
|
||||
@@ -16,7 +16,9 @@
|
||||
"inventory.ItemStackMixin",
|
||||
"world.ChunkGeneratorMixin",
|
||||
"world.ChunkRegionMixin",
|
||||
"world.ChunkRegionWorldMixin",
|
||||
"world.ProtoChunkMixin",
|
||||
"world.ServerWorldMixin",
|
||||
"world.WorldChunkMixin"
|
||||
],
|
||||
"client": [
|
||||
|
||||
Reference in New Issue
Block a user