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

@@ -3,6 +3,7 @@ package com.dfsek.terra.api.structure;
import com.dfsek.terra.api.structure.buffer.Buffer;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.World;
@@ -29,7 +30,7 @@ public interface Structure {
boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions);
@SuppressWarnings("try")
boolean generateDirect(Location location, Random random, Rotation rotation);
boolean generateDirect(Vector3 location, World world, Random random, Rotation rotation);
String getId();
}

View File

@@ -9,11 +9,11 @@ public interface Chunk extends ChunkAccess {
World getWorld();
BlockData getBlockData(int x, int y, int z);
BlockData getBlock(int x, int y, int z);
void setBlockData(int x, int y, int z, BlockData data, boolean physics);
void setBlock(int x, int y, int z, BlockData data, boolean physics);
default void setBlockData(int x, int y, int z, BlockData data) {
setBlockData(x, y, z, data, false);
default void setBlock(int x, int y, int z, BlockData data) {
setBlock(x, y, z, data, false);
}
}

View File

@@ -27,5 +27,5 @@ public interface ChunkAccess extends Handle {
* @param z the z location in the chunk from 0-15 inclusive
* @return the data of the block or the BlockData for air if x, y or z are outside the chunk's bounds
*/
@NotNull BlockData getBlockData(int x, int y, int z);
@NotNull BlockData getBlock(int x, int y, int z);
}

View File

@@ -3,12 +3,13 @@ package com.dfsek.terra.api.world;
import com.dfsek.terra.api.block.BlockType;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import java.util.Random;
import java.util.Set;
public interface Tree {
boolean plant(Location l, Random r);
boolean plant(Vector3 l, World world, Random r);
Set<BlockType> getSpawnable();
}

View File

@@ -165,10 +165,10 @@ public class StructureScript implements Structure {
@Override
@SuppressWarnings("try")
public boolean generateDirect(Location location, Random random, Rotation rotation) {
public boolean generateDirect(Vector3 location, World world, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) {
DirectBuffer buffer = new DirectBuffer(location.toVector(), location.getWorld());
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, location.getWorld(), 0));
DirectBuffer buffer = new DirectBuffer(location, world);
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0));
}
}

View File

@@ -42,7 +42,7 @@ public class BiomeFunction implements Function<String> {
BiomeProvider grid = main.getWorld(arguments.getWorld()).getBiomeProvider();
return ((UserDefinedBiome) grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3Impl(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ()))))).getID();
return grid.getBiome(arguments.getBuffer().getOrigin().clone().add(new Vector3Impl(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(), FastMath.roundToInt(xz.getZ())))).getID();
}

View File

@@ -28,7 +28,7 @@ public class IntermediateBuffer implements Buffer {
@Override
public Buffer addItem(BufferedItem item, Vector3 location) {
return original.addItem(item, location.add(offset));
return original.addItem(item, location.clone().add(offset));
}
@Override
@@ -38,12 +38,12 @@ public class IntermediateBuffer implements Buffer {
@Override
public String getMark(Vector3 location) {
return original.getMark(location.add(offset));
return original.getMark(location.clone().add(offset));
}
@Override
public Buffer setMark(String mark, Vector3 location) {
original.setMark(mark, location.add(offset));
original.setMark(mark, location.clone().add(offset));
return this;
}
}

View File

@@ -110,20 +110,20 @@ public class DefaultChunkGenerator3D implements TerraChunkGenerator {
data = PaletteUtil.getPalette(x, y, z, c, sampler).get(paletteLevel, cx, y, cz);
chunk.setBlock(x, y, z, data);
if(paletteLevel == 0 && c.doSlabs() && y < 255) {
prepareBlockPartFloor(data, chunk.getBlockData(x, y + 1, z), chunk, new Vector3Impl(x, y + 1, z), c.getSlabPalettes(),
prepareBlockPartFloor(data, chunk.getBlock(x, y + 1, z), chunk, new Vector3Impl(x, y + 1, z), c.getSlabPalettes(),
c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
paletteLevel++;
} else if(y <= sea) {
chunk.setBlock(x, y, z, seaPalette.get(sea - y, x + xOrig, y, z + zOrig));
if(justSet && c.doSlabs()) {
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3Impl(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
prepareBlockPartCeiling(data, chunk.getBlock(x, y, z), chunk, new Vector3Impl(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
justSet = false;
paletteLevel = 0;
} else {
if(justSet && c.doSlabs()) {
prepareBlockPartCeiling(data, chunk.getBlockData(x, y, z), chunk, new Vector3Impl(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
prepareBlockPartCeiling(data, chunk.getBlock(x, y, z), chunk, new Vector3Impl(x, y, z), c.getSlabPalettes(), c.getStairPalettes(), c.getSlabThreshold(), sampler);
}
justSet = false;
paletteLevel = 0;

View File

@@ -7,7 +7,6 @@ import com.dfsek.terra.api.config.WorldConfig;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.profiler.ProfileFrame;
import com.dfsek.terra.api.util.PopulationUtil;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.api.vector.Vector3;
import com.dfsek.terra.api.world.Chunk;
import com.dfsek.terra.api.world.TerraWorld;
@@ -19,10 +18,8 @@ import com.dfsek.terra.config.templates.CarverTemplate;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
public class CavePopulator implements TerraBlockPopulator, Chunkified {
private static final Map<BlockType, BlockData> shiftStorage = new HashMap<>(); // Persist BlockData created for shifts, to avoid re-calculating each time.
@@ -49,30 +46,30 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
Map<Vector3, BlockData> shiftCandidate = new HashMap<>();
c.carve(chunk.getX(), chunk.getZ(), world, (v, type) -> {
try(ProfileFrame ignored = main.getProfiler().profile("carving:" + c.getConfig().getID())) {
BlockData m = chunk.getBlockData(v.getBlockX(), v.getBlockY(), v.getBlockZ());
BlockData m = chunk.getBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
BlockType re = m.getBlockType();
switch(type) {
case CENTER:
if(template.getInner().canReplace(re)) {
chunk.setBlockData(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getInner().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getInner().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
}
break;
case WALL:
if(template.getOuter().canReplace(re)) {
chunk.setBlockData(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getOuter().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getOuter().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
}
break;
case TOP:
if(template.getTop().canReplace(re)) {
chunk.setBlockData(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getTop().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getTop().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
}
break;
case BOTTOM:
if(template.getBottom().canReplace(re)) {
chunk.setBlockData(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getBottom().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
chunk.setBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ(), template.getBottom().get(v.getBlockY()).get(random), template.getUpdate().contains(re));
if(template.getShift().containsKey(re)) shiftCandidate.put(v, m);
}
break;
@@ -82,12 +79,12 @@ public class CavePopulator implements TerraBlockPopulator, Chunkified {
for(Map.Entry<Vector3, BlockData> entry : shiftCandidate.entrySet()) {
Vector3 l = entry.getKey();
Vector3 mut = l.clone();
BlockData orig = chunk.getBlockData(l.getBlockX(), l.getBlockY(), l.getBlockZ());
BlockData orig = chunk.getBlock(l.getBlockX(), l.getBlockY(), l.getBlockZ());
do mut.subtract(0, 1, 0);
while(mut.getY() > world.getMinHeight() && chunk.getBlockData(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).matches(orig));
while(mut.getY() > world.getMinHeight() && chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).matches(orig));
try {
if(template.getShift().get(entry.getValue().getBlockType()).contains(chunk.getBlockData(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).getBlockType())) {
chunk.setBlockData(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
if(template.getShift().get(entry.getValue().getBlockType()).contains(chunk.getBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ()).getBlockType())) {
chunk.setBlock(mut.getBlockX(), mut.getBlockY(), mut.getBlockZ(), shiftStorage.computeIfAbsent(entry.getValue().getBlockType(), BlockType::getDefaultData), false);
}
} catch(NullPointerException ignored) {
}

View File

@@ -20,7 +20,9 @@ public class FloraLayer extends PlaceableLayer<Flora> {
@Override
public void place(Chunk chunk, Vector2 coords) {
Flora item = layer.get(noise, (chunk.getX() << 4) + coords.getX(), (chunk.getZ() << 4) + coords.getZ());
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.toLocation(chunk.getWorld())));
int cx = chunk.getX() << 4;
int cz = chunk.getZ() << 4;
Flora item = layer.get(noise, coords.getX() + cx, coords.getZ() + cz);
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.toLocation(chunk.getWorld()).add(cx, 0, cz)));
}
}

View File

@@ -67,7 +67,7 @@ public class TerraFlora implements Flora {
for(int y : range) {
if(y > 255 || y < 0) continue;
current = current.add(0, search.equals(Search.UP) ? 1 : -1, 0);
if((spawnBlacklist != spawnable.contains(chunk.getBlockData(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(current.add(0, irrigableOffset, 0), chunk) && valid(size, current.clone(), chunk)) {
if((spawnBlacklist != spawnable.contains(chunk.getBlock(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(current.add(0, irrigableOffset, 0), chunk) && valid(size, current.clone(), chunk)) {
blocks.add(current.clone());
if(maxPlacements > 0 && blocks.size() >= maxPlacements) break;
}
@@ -79,17 +79,17 @@ public class TerraFlora implements Flora {
for(int i = 0; i < size; i++) { // Down if ceiling, up if floor
if(block.getY() + 1 > 255 || block.getY() < 0) return false;
block.add(0, ceiling ? -1 : 1, 0);
if(!replaceable.contains(chunk.getBlockData(block.getBlockX(), block.getBlockY(), block.getBlockZ()).getBlockType())) return false;
if(!replaceable.contains(chunk.getBlock(block.getBlockX(), block.getBlockY(), block.getBlockZ()).getBlockType())) return false;
}
return true;
}
private boolean isIrrigated(Vector3 b, Chunk chunk) {
if(irrigable == null) return true;
return irrigable.contains(chunk.getBlockData(b.getBlockX()+1, b.getBlockY(), b.getBlockZ()).getBlockType())
|| irrigable.contains(chunk.getBlockData(b.getBlockX()-1, b.getBlockY(), b.getBlockZ()).getBlockType())
|| irrigable.contains(chunk.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ()+1).getBlockType())
|| irrigable.contains(chunk.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ()-1).getBlockType());
return irrigable.contains(chunk.getBlock(b.getBlockX()+1, b.getBlockY(), b.getBlockZ()).getBlockType())
|| irrigable.contains(chunk.getBlock(b.getBlockX()-1, b.getBlockY(), b.getBlockZ()).getBlockType())
|| irrigable.contains(chunk.getBlock(b.getBlockX(), b.getBlockY(), b.getBlockZ()+1).getBlockType())
|| irrigable.contains(chunk.getBlock(b.getBlockX(), b.getBlockY(), b.getBlockZ()-1).getBlockType());
}

View File

@@ -68,9 +68,9 @@ public class VanillaOre extends Ore {
double d15 = (z + 0.5D - (d3 + (d4 - d3) * iFactor)) / (d11 / 2.0D);
if(x > 15 || z > 15 || y > 255 || x < 0 || z < 0 || y < 0) continue;
BlockType type = chunk.getBlockData(x, y, z).getBlockType();
BlockType type = chunk.getBlock(x, y, z).getBlockType();
if((d13 * d13 + d14 * d14 + d15 * d15 < 1.0D) && getReplaceable().contains(type)) {
chunk.setBlockData(x, y, z, getMaterial(type), isApplyGravity());
chunk.setBlock(x, y, z, getMaterial(type), isApplyGravity());
}
}
}

View File

@@ -4,8 +4,9 @@ import com.dfsek.terra.api.structure.Structure;
import com.dfsek.terra.api.structure.rotation.Rotation;
import com.dfsek.terra.api.util.ProbabilityCollection;
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 java.util.Random;
@@ -21,8 +22,8 @@ public class TerraTree implements Tree {
}
@Override
public synchronized boolean plant(Location location, Random random) {
return structure.get(random).generateDirect(location.clone().add(0, yOffset, 0), random, Rotation.fromDegrees(90 * random.nextInt(4)));
public synchronized boolean plant(Vector3 location, World world, Random random) {
return structure.get(random).generateDirect(location.clone().add(0, yOffset, 0), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
}
@Override

View File

@@ -24,8 +24,8 @@ public class TreeLayer extends PlaceableLayer<Tree> {
Vector3 running = coords.extrude(level.getMax());
for(int ignored : level) {
running.subtract(0,1,0);
if(item.getSpawnable().contains(chunk.getBlockData(running.getBlockX(), running.getBlockY(), running.getBlockZ()).getBlockType())) {
item.plant(running.toLocation(chunk.getWorld()).add(cx, 1, cz), PopulationUtil.getRandom(chunk, coords.hashCode()));
if(item.getSpawnable().contains(chunk.getBlock(running.getBlockX(), running.getBlockY(), running.getBlockZ()).getBlockType())) {
item.plant(running.clone().add(cx, 1, cz), chunk.getWorld(), PopulationUtil.getRandom(chunk, coords.hashCode()));
}
}
}

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"));