mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-02 16:05:29 +00:00
compile Fabric
This commit is contained in:
parent
ab9f98994d
commit
dc1f1a0339
@ -50,14 +50,6 @@ public interface World extends Handle {
|
||||
return getBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
|
||||
void setBlockState(int x, int y, int z, BlockState state);
|
||||
|
||||
default void setBlockState(Vector3 position, BlockState state) {
|
||||
setBlockState(position.getBlockX(), position.getBlockY(), position.getBlockZ(), state);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Entity spawnEntity(Location location, EntityType entityType);
|
||||
|
||||
int getMinHeight();
|
||||
|
@ -20,8 +20,6 @@ public class BufferedStateManipulator implements BufferedItem {
|
||||
BlockState state = origin.getWorld().getBlockState(origin.getVector());
|
||||
state.applyState(data);
|
||||
state.update(false);
|
||||
|
||||
origin.getWorld().setBlockState(origin.getVector(), state);
|
||||
} catch(Exception e) {
|
||||
main.logger().warning("Could not apply BlockState at " + origin + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
@ -51,11 +51,6 @@ public class DummyWorld implements World {
|
||||
throw new UnsupportedOperationException("Cannot get block in DummyWorld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState state) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(Location location, EntityType entityType) {
|
||||
throw new UnsupportedOperationException("Cannot spawn entity in DummyWorld");
|
||||
|
@ -128,9 +128,9 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
private final PluginConfig config = new PluginConfigImpl();
|
||||
|
||||
private ProtoBiome parseBiome(String id) {
|
||||
private ProtoBiome parseBiome(String id) throws LoadException {
|
||||
Identifier identifier = Identifier.tryParse(id);
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) return null; // failure.
|
||||
if(BuiltinRegistries.BIOME.get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier); // failure.
|
||||
return new ProtoBiome(identifier);
|
||||
}
|
||||
|
||||
|
@ -1,95 +0,0 @@
|
||||
package com.dfsek.terra.fabric.block;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.BlockFace;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.vector.Location;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class FabricBlock implements Block {
|
||||
private final Handle delegate;
|
||||
|
||||
public FabricBlock(BlockPos position, WorldAccess worldAccess) {
|
||||
this.delegate = new Handle(position, worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockData(BlockData data, boolean physics) {
|
||||
delegate.worldAccess.setBlockState(delegate.position, ((FabricBlockData) data).getHandle(), physics ? 3 : 1042);
|
||||
if(physics && ((FabricBlockData) data).getHandle().getBlock() instanceof FluidBlock) {
|
||||
delegate.worldAccess.getFluidTickScheduler().schedule(delegate.position, ((FluidBlock) ((FabricBlockData) data).getHandle().getBlock()).getFluidState(((FabricBlockData) data).getHandle()).getFluid(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getBlockData() {
|
||||
return new FabricBlockData(delegate.worldAccess.getBlockState(delegate.position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getState() {
|
||||
return FabricAdapter.adapt(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getRelative(BlockFace face, int len) {
|
||||
BlockPos newPos = delegate.position.add(face.getModX() * len, face.getModY() * len, face.getModZ() * len);
|
||||
return new FabricBlock(newPos, delegate.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getBlockData().isAir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return FabricAdapter.adapt(delegate.position).toLocation((World) delegate.worldAccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType getType() {
|
||||
return getBlockData().getBlockType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return delegate.position.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return delegate.position.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
return delegate.position.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassable() {
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Handle getHandle() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
public static final class Handle {
|
||||
private final BlockPos position;
|
||||
private final WorldAccess worldAccess;
|
||||
|
||||
public Handle(BlockPos position, WorldAccess worldAccess) {
|
||||
this.position = position;
|
||||
this.worldAccess = worldAccess;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,7 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.block;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.util.FabricAdapter;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -37,10 +35,6 @@ public abstract class BlockEntityMixin {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Block terra$getBlock() {
|
||||
return new FabricBlock(pos, world);
|
||||
}
|
||||
|
||||
public int terra$getX() {
|
||||
return pos.getX();
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.chunk;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
@ -35,16 +33,11 @@ public abstract class ChunkRegionMixin {
|
||||
return (World) this;
|
||||
}
|
||||
|
||||
public Block terra$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4));
|
||||
return new FabricBlock(pos, (ChunkRegion) (Object) this);
|
||||
}
|
||||
|
||||
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
|
||||
return terra$getBlock(x, y, z).getBlockData();
|
||||
return new FabricBlockData(((ChunkRegion) (Object) this).getBlockState(new BlockPos(x + (centerPos.x << 4), y, z + (centerPos.z << 4))));
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
public void terra$setBlockData(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);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.chunk;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@ -23,6 +24,13 @@ public abstract class WorldChunkMixin {
|
||||
@Shadow
|
||||
private net.minecraft.world.World world;
|
||||
|
||||
@Shadow
|
||||
public abstract BlockState getBlockState(BlockPos pos);
|
||||
|
||||
@Shadow
|
||||
@Nullable
|
||||
public abstract BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
|
||||
|
||||
public int terra$getX() {
|
||||
return ((net.minecraft.world.chunk.Chunk) this).getPos().x;
|
||||
}
|
||||
@ -35,13 +43,12 @@ public abstract class WorldChunkMixin {
|
||||
return (World) world;
|
||||
}
|
||||
|
||||
public Block terra$getBlock(int x, int y, int z) {
|
||||
BlockPos pos = new BlockPos(x + (terra$getX() << 4), y, z + (terra$getZ() << 4));
|
||||
return new FabricBlock(pos, world);
|
||||
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
|
||||
return new FabricBlockData(getBlockState(new BlockPos(x, y, z)));
|
||||
}
|
||||
|
||||
public @NotNull BlockData terra$getBlockData(int x, int y, int z) {
|
||||
return terra$getBlock(x, y, z).getBlockData();
|
||||
public void terra$setBlockData(int x, int y, int z, BlockData data, boolean physics) {
|
||||
setBlockState(new BlockPos(x, y, z), ((FabricBlockData) data).getHandle(), false);
|
||||
}
|
||||
|
||||
public void terra$setBlock(int x, int y, int z, @NotNull BlockData blockData) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.world;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Location;
|
||||
@ -9,12 +9,18 @@ import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generator.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FluidBlock;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.TickScheduler;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
@ -33,6 +39,12 @@ public abstract class ChunkRegionMixin {
|
||||
@Final
|
||||
private long seed;
|
||||
|
||||
@Shadow
|
||||
public abstract boolean setBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth);
|
||||
|
||||
@Shadow
|
||||
public abstract TickScheduler<Fluid> getFluidTickScheduler();
|
||||
|
||||
public int terra$getMaxHeight() {
|
||||
return (((ChunkRegion) (Object) this).getBottomY()) + ((ChunkRegion) (Object) this).getHeight();
|
||||
}
|
||||
@ -46,8 +58,8 @@ public abstract class ChunkRegionMixin {
|
||||
return (Chunk) ((ChunkRegion) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public Block terra$getBlockAt(int x, int y, int z) {
|
||||
return new FabricBlock(new BlockPos(x, y, z), ((ChunkRegion) (Object) this));
|
||||
public com.dfsek.terra.api.block.state.BlockState terra$getBlockState(int x, int y, int z) {
|
||||
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -58,6 +70,18 @@ public abstract class ChunkRegionMixin {
|
||||
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)));
|
||||
}
|
||||
|
||||
public void terra$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) {
|
||||
getFluidTickScheduler().schedule(pos, ((FluidBlock) ((FabricBlockData) data).getHandle().getBlock()).getFluidState(((FabricBlockData) data).getHandle()).getFluid(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Intrinsic
|
||||
public long terra$getSeed() {
|
||||
return seed;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.fabric.mixin.implementations.world;
|
||||
|
||||
import com.dfsek.terra.api.block.Block;
|
||||
import com.dfsek.terra.api.block.BlockData;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.vector.Location;
|
||||
@ -9,11 +9,13 @@ import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.generator.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.generator.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.generator.TerraChunkGenerator;
|
||||
import com.dfsek.terra.fabric.block.FabricBlock;
|
||||
import com.dfsek.terra.fabric.block.FabricBlockData;
|
||||
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.fabric.util.FabricUtil;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import org.spongepowered.asm.mixin.Implements;
|
||||
import org.spongepowered.asm.mixin.Interface;
|
||||
import org.spongepowered.asm.mixin.Intrinsic;
|
||||
@ -38,8 +40,17 @@ public abstract class ServerWorldMixin {
|
||||
return (Chunk) ((ServerWorld) (Object) this).getChunk(x, z);
|
||||
}
|
||||
|
||||
public Block terra$getBlockAt(int x, int y, int z) {
|
||||
return new FabricBlock(new BlockPos(x, y, z), ((ServerWorld) (Object) this));
|
||||
public com.dfsek.terra.api.block.state.BlockState terra$getBlockState(int x, int y, int z) {
|
||||
return FabricUtil.createState((WorldAccess) this, new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
public BlockData terra$getBlockData(int x, int y, int z) {
|
||||
return new FabricBlockData(((ServerWorld) (Object) this).getBlockState(new BlockPos(x, y, z)));
|
||||
}
|
||||
|
||||
public void terra$setBlockData(int x, int y, int z, BlockData data, boolean physics) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
((ServerWorld) (Object) this).setBlockState(pos, ((FabricBlockData) data).getHandle(), physics ? 3 : 1042);
|
||||
}
|
||||
|
||||
public Entity terra$spawnEntity(Location location, EntityType entityType) {
|
||||
|
@ -81,21 +81,6 @@ public final class FabricAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static com.dfsek.terra.api.block.state.BlockState adapt(com.dfsek.terra.api.block.Block block) {
|
||||
WorldAccess worldAccess = (WorldAccess) block.getLocation().getWorld();
|
||||
|
||||
BlockEntity entity = worldAccess.getBlockEntity(adapt(block.getLocation().toVector()));
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerBlockEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof LootableContainerBlockEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Stairs.Shape adapt(StairShape shape) {
|
||||
switch(shape) {
|
||||
case OUTER_RIGHT:
|
||||
|
@ -1,7 +1,12 @@
|
||||
package com.dfsek.terra.fabric.util;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.Container;
|
||||
import com.dfsek.terra.api.block.state.MobSpawner;
|
||||
import com.dfsek.terra.api.block.state.Sign;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.config.builder.BiomeBuilder;
|
||||
import com.dfsek.terra.config.templates.BiomeTemplate;
|
||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||
@ -9,11 +14,17 @@ import com.dfsek.terra.fabric.config.PostLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.fabric.mixin.access.BiomeEffectsAccessor;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.MutableRegistry;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
@ -47,6 +58,7 @@ 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();
|
||||
@ -130,4 +142,16 @@ public final class FabricUtil {
|
||||
Registry.register(registry, identifier, item);
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockState createState(WorldAccess worldAccess, BlockPos pos) {
|
||||
BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||
if(entity instanceof SignBlockEntity) {
|
||||
return (Sign) entity;
|
||||
} else if(entity instanceof MobSpawnerBlockEntity) {
|
||||
return (MobSpawner) entity;
|
||||
} else if(entity instanceof LootableContainerBlockEntity) {
|
||||
return (Container) entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user