fix world coordinate issues on Fabric

This commit is contained in:
dfsek
2021-06-25 00:45:24 -07:00
parent ff4cbda294
commit da0fb7dd15
25 changed files with 89 additions and 79 deletions

View File

@@ -44,7 +44,7 @@ public class BukkitChunkGenerator implements com.dfsek.terra.api.world.generator
@Override
public @NotNull BlockData getBlockData(int x, int y, int z) {
public @NotNull BlockData getBlock(int x, int y, int z) {
return BukkitBlockData.newInstance(delegate.getBlockData(x, y, z));
}
}

View File

@@ -54,7 +54,7 @@ public class CommonListener implements Listener {
block.setType(Material.AIR);
Tree tree = c.getRegistry(Tree.class).get(TREE_TYPE_STRING_TRANSFORMER.translate(e.getSpecies()));
org.bukkit.Location location = e.getLocation();
if(!tree.plant(new LocationImpl(bukkit, location.getX(), location.getY(), location.getZ()), new FastRandom()))
if(!tree.plant(new LocationImpl(bukkit, location.getX(), location.getY(), location.getZ()), , new FastRandom()))
block.setBlockData(data);
}
}

View File

@@ -45,7 +45,7 @@ public class BukkitChunk implements Chunk {
}
@Override
public @NotNull BlockData getBlockData(int x, int y, int z) {
public @NotNull BlockData getBlock(int x, int y, int z) {
return getBlock(x, y, z).getBlockData();
}
}

View File

@@ -4,8 +4,9 @@ import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import org.bukkit.TreeType;
import java.util.Locale;
@@ -43,7 +44,7 @@ public class BukkitTree implements Tree {
@Override
@SuppressWarnings("try")
public boolean plant(Location l, Random r) {
public boolean plant(Vector3 l, World world, Random r) {
try(ProfileFrame ignore = main.getProfiler().profile("bukkit_tree:" + delegate.toString().toLowerCase(Locale.ROOT))) {
return ((BukkitWorld) l.getWorld()).getHandle().generateTree(BukkitAdapter.adapt(l), delegate);
}

View File

@@ -4,7 +4,9 @@ import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.BuiltinRegistries;
@@ -27,11 +29,11 @@ public abstract class ConfiguredFeatureMixin {
public abstract boolean generate(StructureWorldAccess world, ChunkGenerator chunkGenerator, Random random, BlockPos pos);
@SuppressWarnings({"ConstantConditions", "try"})
public boolean terra$plant(Location l, Random r) {
public boolean terra$plant(Vector3 l, World world, Random r) {
String id = BuiltinRegistries.CONFIGURED_FEATURE.getId((ConfiguredFeature<?, ?>) (Object) this).toString();
try(ProfileFrame ignore = TerraFabricPlugin.getInstance().getProfiler().profile("fabric_tree:" + id.toLowerCase(Locale.ROOT))) {
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) l.getWorld());
ChunkGenerator generatorWrapper = (ChunkGenerator) l.getWorld().getGenerator();
StructureWorldAccess fabricWorldAccess = ((StructureWorldAccess) world);
ChunkGenerator generatorWrapper = (ChunkGenerator) world.getGenerator();
return generate(fabricWorldAccess, generatorWrapper, r, new BlockPos(l.getBlockX(), l.getBlockY(), l.getBlockZ()));
}
}

View File

@@ -11,33 +11,35 @@ 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.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = Chunk.class, prefix = "terra$", remap = Interface.Remap.NONE))
@Implements(@Interface(iface = Chunk.class, prefix = "terraChunk$", remap = Interface.Remap.NONE))
public abstract class ChunkRegionMixin {
@Final
@Shadow
private ChunkPos centerPos;
public int terra$getX() {
public int terraChunk$getX() {
return centerPos.x;
}
public int terra$getZ() {
public int terraChunk$getZ() {
return centerPos.z;
}
public World terra$getWorld() {
public World terraChunk$getWorld() {
return (World) this;
}
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
public @NotNull BlockData terraChunk$getBlock(int x, int y, int z) {
return new FabricBlockData(((ChunkRegion) (Object) this).getBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4))));
}
public void terra$setBlockData(int x, int y, int z, @NotNull BlockData blockData, boolean physics) {
public void terraChunk$setBlock(int x, int y, int z, @NotNull BlockData blockData, boolean physics) {
((ChunkRegion) (Object) this).setBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4)), ((FabricBlockData) blockData).getHandle(), 0);
}

View File

@@ -43,11 +43,11 @@ public abstract class WorldChunkMixin {
return (World) world;
}
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
public @NotNull BlockData terra$getBlock(int x, int y, int z) {
return new FabricBlockData(getBlockState(new BlockPos(x, y, z)));
}
public void terra$setBlockData(int x, int y, int z, BlockData data, boolean physics) {
public void terra$setBlock(int x, int y, int z, BlockData data, boolean physics) {
setBlockState(new BlockPos(x, y, z), ((FabricBlockData) data).getHandle(), false);
}

View File

@@ -19,7 +19,7 @@ public abstract class ProtoChunkMixin {
@Shadow
public abstract BlockState getBlockState(BlockPos pos);
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
public @NotNull BlockData terra$getBlock(int x, int y, int z) {
return new FabricBlockData(getBlockState(new BlockPos(x, y, z)));
}

View File

@@ -27,9 +27,10 @@ import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Intrinsic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@Mixin(ChunkRegion.class)
@Implements(@Interface(iface = World.class, prefix = "terra$", remap = Interface.Remap.NONE))
@Implements(@Interface(iface = World.class, prefix = "terraWorld$", remap = Interface.Remap.NONE))
public abstract class ChunkRegionMixin {
@Shadow
@Final
@@ -45,36 +46,39 @@ public abstract class ChunkRegionMixin {
@Shadow
public abstract TickScheduler<Fluid> getFluidTickScheduler();
public int terra$getMaxHeight() {
public int terraWorld$getMaxHeight() {
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
}
@SuppressWarnings("deprecation")
public ChunkGenerator terra$getGenerator() {
public ChunkGenerator terraWorld$getGenerator() {
return (ChunkGenerator) ((ChunkRegion) (Object) this).toServerWorld().getChunkManager().getChunkGenerator();
}
public Chunk terra$getChunkAt(int x, int z) {
public Chunk terraWorld$getChunkAt(int x, int z) {
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
}
public com.dfsek.terra.api.block.state.BlockState terra$getBlockState(int x, int y, int z) {
public com.dfsek.terra.api.block.state.BlockState terraWorld$getBlockState(int x, int y, int z) {
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
}
@SuppressWarnings("deprecation")
public Entity terra$spawnEntity(Location location, EntityType entityType) {
public Entity terraWorld$spawnEntity(Location location, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(((ChunkRegion) (Object) this).toServerWorld());
entity.setPos(location.getX(), location.getY(), location.getZ());
((ChunkRegion) (Object) this).spawnEntity(entity);
return (Entity) entity;
}
public BlockData terra$getBlockData(int x, int y, int z) {
return new FabricBlockData(((ChunkRegion) (Object) this).getBlockState(new BlockPos(x, y, z)));
@Intrinsic(displace = true)
public BlockData terraWorld$getBlockData(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
return new FabricBlockData(((ChunkRegion) (Object) this).getBlockState(pos));
}
public void terra$setBlockData(int x, int y, int z, BlockData data, boolean physics) {
@Intrinsic(displace = true)
public void terraWorld$setBlockData(int x, int y, int z, BlockData data, boolean physics) {
BlockPos pos = new BlockPos(x, y, z);
((ChunkRegion) (Object) this).setBlockState(pos, ((FabricBlockData) data).getHandle(), physics ? 3 : 1042);
if(physics && ((FabricBlockData) data).getHandle().getBlock() instanceof FluidBlock) {
@@ -83,25 +87,25 @@ public abstract class ChunkRegionMixin {
}
@Intrinsic
public long terra$getSeed() {
public long terraWorld$getSeed() {
return seed;
}
public int terra$getMinHeight() {
public int terraWorld$getMinHeight() {
return ((ChunkRegion) (Object) this).getBottomY();
}
@Intrinsic
public Object terra$getHandle() {
public Object terraWorld$getHandle() {
return this;
}
public boolean terra$isTerraWorld() {
return terra$getGenerator() instanceof GeneratorWrapper;
public boolean terraWorld$isTerraWorld() {
return terraWorld$getGenerator() instanceof GeneratorWrapper;
}
public TerraChunkGenerator terra$getTerraGenerator() {
return ((FabricChunkGeneratorWrapper) terra$getGenerator()).getHandle();
public TerraChunkGenerator terraWorld$getTerraGenerator() {
return ((FabricChunkGeneratorWrapper) terraWorld$getGenerator()).getHandle();
}
/**

View File

@@ -58,7 +58,6 @@ public final class FabricUtil {
TerraFabricPlugin.FabricAddon fabricAddon = TerraFabricPlugin.getInstance().getFabricAddon();
Registry<Biome> biomeRegistry = registryManager.get(Registry.BIOME_KEY);
System.out.println(new ArrayList<>(biome.getVanillaBiomes().getContents()));
Biome vanilla = ((ProtoBiome) (new ArrayList<>(biome.getVanillaBiomes().getContents()).get(0))).get(biomeRegistry);
GenerationSettings.Builder generationSettings = new GenerationSettings.Builder();

View File

@@ -38,7 +38,7 @@ public class DirectChunkData implements ChunkData, com.dfsek.terra.api.world.Chu
}
@Override
public @NotNull BlockData getBlockData(int x, int y, int z) {
public @NotNull BlockData getBlock(int x, int y, int z) {
CompoundTag tag = delegate.getBlockStateAt(x, y, z);
if(tag == null) return new Data("minecraft:air");
return new Data(tag.getString("Name"));