location garbage

This commit is contained in:
dfsek
2021-06-23 12:03:17 -07:00
parent e34e2dd0b2
commit 686680d731
70 changed files with 488 additions and 341 deletions
@@ -22,6 +22,7 @@ import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.block.BlockData;
import com.dfsek.terra.api.handle.ItemHandle;
import com.dfsek.terra.api.handle.WorldHandle;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.registry.CheckedRegistry;
@@ -53,7 +54,7 @@ import com.dfsek.terra.profiler.ProfilerImpl;
import com.dfsek.terra.api.registry.DuplicateEntryException;
import com.dfsek.terra.registry.master.AddonRegistry;
import com.dfsek.terra.registry.master.ConfigRegistry;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.TerraWorldImpl;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.world.ServerWorld;
@@ -204,7 +205,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
worldMap.forEach((seed, pair) -> {
pair.getRight().getConfig().getSamplerCache().clear();
String packID = pair.getRight().getConfig().getTemplate().getID();
pair.setRight(new TerraWorld(pair.getRight().getWorld(), configRegistry.get(packID), this));
pair.setRight(new TerraWorldImpl(pair.getRight().getWorld(), configRegistry.get(packID), this));
});
return succeed;
}
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.block;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.block.Block;
import com.dfsek.terra.api.block.BlockData;
import com.dfsek.terra.api.block.BlockFace;
@@ -49,7 +49,7 @@ public class FabricBlock implements Block {
}
@Override
public Location getLocation() {
public LocationImpl getLocation() {
return FabricAdapter.adapt(delegate.position).toLocation((World) delegate.worldAccess);
}
@@ -1,6 +1,7 @@
package com.dfsek.terra.fabric.generation;
import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.TerraWorld;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.api.world.generator.ChunkData;
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
@@ -13,7 +14,6 @@ import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.block.FabricBlockData;
import com.dfsek.terra.fabric.mixin.StructureAccessorAccessor;
import com.dfsek.terra.fabric.util.FabricAdapter;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.generation.generators.DefaultChunkGenerator3D;
import com.dfsek.terra.world.population.items.TerraStructure;
import com.mojang.serialization.Codec;
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.handle;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.handle.WorldHandle;
@@ -39,7 +39,7 @@ public class FabricWorldHandle implements WorldHandle {
}
@Override
public Pair<Location, Location> getSelectedLocation(Player player) {
public Pair<LocationImpl, LocationImpl> getSelectedLocation(Player player) {
try {
Class.forName("com.sk89q.worldedit.WorldEdit");
} catch(ClassNotFoundException e) {
@@ -3,7 +3,7 @@ package com.dfsek.terra.fabric.mixin;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
import com.dfsek.terra.world.TerraWorld;
import com.dfsek.terra.world.TerraWorldImpl;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
@@ -27,7 +27,7 @@ public abstract class ServerWorldMixin {
@Inject(method = "<init>", at = @At(value = "RETURN"))
public void injectConstructor(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<World> registryKey, DimensionType dimensionType, WorldGenerationProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<Spawner> list, boolean bl, CallbackInfo ci) {
if(chunkGenerator instanceof FabricChunkGeneratorWrapper) {
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorld((com.dfsek.terra.api.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
TerraFabricPlugin.getInstance().getWorldMap().put(dimensionType, Pair.of((ServerWorld) (Object) this, new TerraWorldImpl((com.dfsek.terra.api.world.World) this, ((FabricChunkGeneratorWrapper) chunkGenerator).getPack(), TerraFabricPlugin.getInstance())));
((FabricChunkGeneratorWrapper) chunkGenerator).setDimensionType(dimensionType);
TerraFabricPlugin.getInstance().logger().info("Registered world " + this + " to dimension type " + dimensionType);
}
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.mixin.implementations;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.world.Tree;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.fabric.TerraFabricPlugin;
@@ -25,7 +25,7 @@ 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(LocationImpl l, 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());
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.mixin.implementations.entity;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.world.World;
import com.dfsek.terra.fabric.util.FabricAdapter;
import net.minecraft.entity.Entity;
@@ -35,11 +35,11 @@ public abstract class EntityMixin {
return this;
}
public Location terra$getLocation() {
return new Location((World) world, FabricAdapter.adapt(blockPos));
public LocationImpl terra$getLocation() {
return new LocationImpl((World) world, FabricAdapter.adapt(blockPos));
}
public void terra$setLocation(Location location) {
public void terra$setLocation(LocationImpl location) {
teleport(location.getX(), location.getY(), location.getZ());
}
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.mixin.implementations.world;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.block.Block;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
@@ -51,7 +51,7 @@ public abstract class ChunkRegionMixin {
}
@SuppressWarnings("deprecation")
public Entity terra$spawnEntity(Location location, EntityType entityType) {
public Entity terra$spawnEntity(LocationImpl 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);
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.mixin.implementations.world;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.block.Block;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.EntityType;
@@ -42,7 +42,7 @@ public abstract class ServerWorldMixin {
return new FabricBlock(new BlockPos(x, y, z), ((ServerWorld) (Object) this));
}
public Entity terra$spawnEntity(Location location, EntityType entityType) {
public Entity terra$spawnEntity(LocationImpl 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);
@@ -1,6 +1,6 @@
package com.dfsek.terra.fabric.util;
import com.dfsek.terra.api.vector.Location;
import com.dfsek.terra.vector.LocationImpl;
import com.dfsek.terra.api.entity.Player;
import com.dfsek.terra.api.util.generic.pair.Pair;
import com.sk89q.worldedit.IncompleteRegionException;
@@ -11,7 +11,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
public final class WorldEditUtil {
public static Pair<Location, Location> getSelection(Player player) {
public static Pair<LocationImpl, LocationImpl> getSelection(Player player) {
WorldEdit worldEdit = WorldEdit.getInstance();
try {
Region selection = worldEdit.getSessionManager()
@@ -19,8 +19,8 @@ public final class WorldEditUtil {
.getSelection(com.sk89q.worldedit.fabric.FabricAdapter.adapt((World) player.getWorld()));
BlockVector3 min = selection.getMinimumPoint();
BlockVector3 max = selection.getMaximumPoint();
Location l1 = new Location(player.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ());
Location l2 = new Location(player.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
LocationImpl l1 = new LocationImpl(player.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ());
LocationImpl l2 = new LocationImpl(player.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ());
return Pair.of(l1, l2);
} catch(IncompleteRegionException e) {
throw new IllegalStateException("No selection has been made", e);