mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Cleanup Fabric BlockState and EntityType Extended implementation
This commit is contained in:
@@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||||
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
import com.dfsek.terra.addons.terrascript.tokenizer.Position;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public interface FunctionBuilder<T extends Function<?>> {
|
public interface FunctionBuilder<T extends Function<?>> {
|
||||||
T build(List<Returnable<?>> argumentList, Position position);
|
T build(List<Returnable<?>> argumentList, Position position);
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
package com.dfsek.terra.bukkit.util;
|
package com.dfsek.terra.bukkit.util;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.dfsek.terra.bukkit.TerraBukkitPlugin;
|
|
||||||
|
|
||||||
import static io.papermc.lib.PaperLib.suggestPaper;
|
import static io.papermc.lib.PaperLib.suggestPaper;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import com.dfsek.tectonic.api.depth.DepthTracker;
|
|||||||
import com.dfsek.tectonic.api.exception.LoadException;
|
import com.dfsek.tectonic.api.exception.LoadException;
|
||||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.registry.RegistryKey;
|
||||||
import org.intellij.lang.annotations.Subst;
|
import org.intellij.lang.annotations.Subst;
|
||||||
@@ -11,8 +14,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.lang.reflect.AnnotatedType;
|
import java.lang.reflect.AnnotatedType;
|
||||||
|
|
||||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
|
||||||
|
|
||||||
|
|
||||||
public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
|
public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.dfsek.terra.minestom.entity;
|
package com.dfsek.terra.minestom.entity;
|
||||||
|
|
||||||
|
import com.dfsek.terra.minestom.api.EntityFactory;
|
||||||
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
|
|
||||||
import com.dfsek.terra.minestom.api.EntityFactory;
|
|
||||||
|
|
||||||
|
|
||||||
public class DefaultEntityFactory implements EntityFactory {
|
public class DefaultEntityFactory implements EntityFactory {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -34,14 +34,12 @@ import net.minecraft.registry.entry.RegistryEntry.Reference;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
||||||
import com.dfsek.terra.api.entity.EntityType;
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
import com.dfsek.terra.mod.implmentation.FabricEntityTypeExtended;
|
import com.dfsek.terra.mod.implmentation.MinecraftEntityTypeExtended;
|
||||||
|
|
||||||
import static net.minecraft.command.argument.BlockArgumentParser.INVALID_BLOCK_ID_EXCEPTION;
|
import static net.minecraft.command.argument.BlockArgumentParser.INVALID_BLOCK_ID_EXCEPTION;
|
||||||
|
|
||||||
@@ -51,8 +49,6 @@ public class MinecraftWorldHandle implements WorldHandle {
|
|||||||
|
|
||||||
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();
|
private static final BlockState AIR = (BlockState) Blocks.AIR.getDefaultState();
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(MinecraftWorldHandle.class);
|
|
||||||
|
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
@Override
|
@Override
|
||||||
public @NotNull BlockState createBlockState(@NotNull String data) {
|
public @NotNull BlockState createBlockState(@NotNull String data) {
|
||||||
@@ -117,7 +113,7 @@ public class MinecraftWorldHandle implements WorldHandle {
|
|||||||
|
|
||||||
EntityType entityType;
|
EntityType entityType;
|
||||||
if(nbtData != null) {
|
if(nbtData != null) {
|
||||||
entityType = new FabricEntityTypeExtended(entity, nbtData);
|
entityType = new MinecraftEntityTypeExtended(entity, nbtData);
|
||||||
} else {
|
} else {
|
||||||
entityType = (EntityType) entity;
|
entityType = (EntityType) entity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.api.entity.EntityType;
|
|||||||
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
import com.dfsek.terra.api.entity.EntityTypeExtended;
|
||||||
|
|
||||||
|
|
||||||
public record FabricEntityTypeExtended(net.minecraft.entity.EntityType<?> entityType, NbtCompound nbtCompound)
|
public record MinecraftEntityTypeExtended(net.minecraft.entity.EntityType<?> entityType, NbtCompound nbtCompound)
|
||||||
implements EntityTypeExtended {
|
implements EntityTypeExtended {
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
@Override
|
@Override
|
||||||
@@ -18,7 +18,8 @@ public record FabricEntityTypeExtended(net.minecraft.entity.EntityType<?> entity
|
|||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
@Override
|
@Override
|
||||||
public EntityTypeExtended setData(ExtendedData data) {
|
public EntityTypeExtended setData(ExtendedData data) {
|
||||||
return new FabricEntityTypeExtended(entityType, data.getClass().equals(NbtCompound.class) ? ((NbtCompound) ((Object) data)) : null);
|
return new MinecraftEntityTypeExtended(entityType,
|
||||||
|
data.getClass().equals(NbtCompound.class) ? ((NbtCompound) ((Object) data)) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.dfsek.terra.mod.mixin.access;
|
||||||
|
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.chunk.WorldChunk;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
|
||||||
|
@Mixin(WorldChunk.class)
|
||||||
|
public interface WorldChunkAccessor {
|
||||||
|
@Invoker("loadBlockEntity")
|
||||||
|
public BlockEntity invokeLoadBlockEntity(BlockPos pos, NbtCompound nbt);
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@ import com.dfsek.terra.api.block.entity.MobSpawner;
|
|||||||
import com.dfsek.terra.api.block.entity.SerialState;
|
import com.dfsek.terra.api.block.entity.SerialState;
|
||||||
import com.dfsek.terra.api.entity.EntityType;
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
import com.dfsek.terra.mod.CommonPlatform;
|
import com.dfsek.terra.mod.CommonPlatform;
|
||||||
import com.dfsek.terra.mod.implmentation.FabricEntityTypeExtended;
|
import com.dfsek.terra.mod.implmentation.MinecraftEntityTypeExtended;
|
||||||
import com.dfsek.terra.mod.mixin.access.MobSpawnerLogicAccessor;
|
import com.dfsek.terra.mod.mixin.access.MobSpawnerLogicAccessor;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
|
|||||||
}
|
}
|
||||||
net.minecraft.entity.EntityType<?> entityType =
|
net.minecraft.entity.EntityType<?> entityType =
|
||||||
(((net.minecraft.entity.EntityType<?>) (creatureType.isExtended() && creatureType.getClass().equals(
|
(((net.minecraft.entity.EntityType<?>) (creatureType.isExtended() && creatureType.getClass().equals(
|
||||||
FabricEntityTypeExtended.class) ? ((FabricEntityTypeExtended) creatureType).getType() : creatureType)));
|
MinecraftEntityTypeExtended.class) ? ((MinecraftEntityTypeExtended) creatureType).getType() : creatureType)));
|
||||||
setEntityType(entityType, rand);
|
setEntityType(entityType, rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ package com.dfsek.terra.mod.mixin.implementations.terra.chunk;
|
|||||||
|
|
||||||
import com.dfsek.seismic.math.coord.CoordFunctions;
|
import com.dfsek.seismic.math.coord.CoordFunctions;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
|
||||||
import net.minecraft.block.entity.BlockEntity;
|
|
||||||
import net.minecraft.command.argument.BlockStateArgument;
|
import net.minecraft.command.argument.BlockStateArgument;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
@@ -30,7 +28,6 @@ import net.minecraft.util.math.ChunkPos;
|
|||||||
import net.minecraft.world.ChunkRegion;
|
import net.minecraft.world.ChunkRegion;
|
||||||
import net.minecraft.world.StructureWorldAccess;
|
import net.minecraft.world.StructureWorldAccess;
|
||||||
import net.minecraft.world.tick.MultiTickScheduler;
|
import net.minecraft.world.tick.MultiTickScheduler;
|
||||||
import net.minecraft.world.tick.OrderedTick;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
@@ -42,6 +39,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
|||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
||||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||||
|
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||||
|
|
||||||
|
|
||||||
@Mixin(ChunkRegion.class)
|
@Mixin(ChunkRegion.class)
|
||||||
@@ -76,40 +74,24 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
|
|||||||
ChunkPos pos = centerPos.getPos();
|
ChunkPos pos = centerPos.getPos();
|
||||||
BlockPos blockPos = new BlockPos(CoordFunctions.chunkAndRelativeToAbsolute(pos.x, x), y,
|
BlockPos blockPos = new BlockPos(CoordFunctions.chunkAndRelativeToAbsolute(pos.x, x), y,
|
||||||
CoordFunctions.chunkAndRelativeToAbsolute(pos.z, z));
|
CoordFunctions.chunkAndRelativeToAbsolute(pos.z, z));
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
|
net.minecraft.block.BlockState state;
|
||||||
|
|
||||||
|
boolean isExtended = MinecraftUtil.isCompatibleBlockStateExtended(data);
|
||||||
|
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
BlockStateArgument arg = ((BlockStateArgument) data);
|
BlockStateArgument arg = ((BlockStateArgument) data);
|
||||||
net.minecraft.block.BlockState state = arg.getBlockState();
|
state = arg.getBlockState();
|
||||||
setBlockState(blockPos, state, 0, 512);
|
setBlockState(blockPos, state, 0, 512);
|
||||||
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
|
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
|
||||||
BlockEntity blockEntity;
|
|
||||||
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
|
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
|
||||||
if("DUMMY".equals(nbt.getString("id", ""))) {
|
MinecraftUtil.loadBlockEntity(chunk, world, blockPos, state, nbt);
|
||||||
if(state.hasBlockEntity()) {
|
|
||||||
blockEntity = ((BlockEntityProvider) state.getBlock()).createBlockEntity(blockPos, state);
|
|
||||||
} else {
|
|
||||||
blockEntity = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
blockEntity = BlockEntity.createFromNbt(blockPos, state, nbt, this.world.getRegistryManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(blockEntity != null) {
|
|
||||||
blockEntity.setWorld(this.world);
|
|
||||||
chunk.setBlockEntity(blockEntity);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0, 512);
|
state = (net.minecraft.block.BlockState) data;
|
||||||
|
setBlockState(blockPos, state, 0, 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(physics) {
|
if(physics) {
|
||||||
net.minecraft.block.BlockState state =
|
MinecraftUtil.schedulePhysics(state, blockPos, getFluidTickScheduler(), getBlockTickScheduler());
|
||||||
isExtended ? ((BlockStateArgument) data).getBlockState() : ((net.minecraft.block.BlockState) data);
|
|
||||||
if(state.isLiquid()) {
|
|
||||||
fluidTickScheduler.scheduleTick(OrderedTick.create(state.getFluidState().getFluid(), blockPos));
|
|
||||||
} else {
|
|
||||||
blockTickScheduler.scheduleTick(OrderedTick.create(state.getBlock(), blockPos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import net.minecraft.command.argument.BlockStateArgument;
|
|||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.chunk.WorldChunk;
|
import net.minecraft.world.chunk.WorldChunk;
|
||||||
import net.minecraft.world.tick.OrderedTick;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
@@ -36,6 +35,7 @@ import com.dfsek.terra.api.block.state.BlockState;
|
|||||||
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
import com.dfsek.terra.api.block.state.BlockStateExtended;
|
||||||
import com.dfsek.terra.api.world.ServerWorld;
|
import com.dfsek.terra.api.world.ServerWorld;
|
||||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||||
|
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||||
|
|
||||||
|
|
||||||
@Mixin(WorldChunk.class)
|
@Mixin(WorldChunk.class)
|
||||||
@@ -58,24 +58,22 @@ public abstract class WorldChunkMixin {
|
|||||||
@SuppressWarnings("ConstantValue")
|
@SuppressWarnings("ConstantValue")
|
||||||
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||||
BlockPos blockPos = new BlockPos(x, y, z);
|
BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
|
net.minecraft.block.BlockState state;
|
||||||
|
|
||||||
|
boolean isExtended = MinecraftUtil.isCompatibleBlockStateExtended(data);
|
||||||
|
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
BlockStateArgument arg = ((BlockStateArgument) data);
|
BlockStateArgument arg = ((BlockStateArgument) data);
|
||||||
net.minecraft.block.BlockState state = arg.getBlockState();
|
state = arg.getBlockState();
|
||||||
setBlockState(blockPos, state, 0);
|
setBlockState(blockPos, state, 0);
|
||||||
loadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).getData()));
|
loadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).getData()));
|
||||||
} else {
|
} else {
|
||||||
setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0);
|
state = (net.minecraft.block.BlockState) data;
|
||||||
|
setBlockState(blockPos, state, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(physics) {
|
if(physics) {
|
||||||
net.minecraft.block.BlockState state =
|
MinecraftUtil.schedulePhysics(state, blockPos, world.getFluidTickScheduler(), world.getBlockTickScheduler());
|
||||||
isExtended ? ((BlockStateArgument) data).getBlockState() : ((net.minecraft.block.BlockState) data);
|
|
||||||
if(state.isLiquid()) {
|
|
||||||
world.getFluidTickScheduler().scheduleTick(OrderedTick.create(state.getFluidState().getFluid(), blockPos));
|
|
||||||
} else {
|
|
||||||
world.getBlockTickScheduler().scheduleTick(OrderedTick.create(state.getBlock(), blockPos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package com.dfsek.terra.mod.mixin.implementations.terra.world;
|
package com.dfsek.terra.mod.mixin.implementations.terra.world;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
|
||||||
import net.minecraft.command.argument.BlockStateArgument;
|
import net.minecraft.command.argument.BlockStateArgument;
|
||||||
import net.minecraft.entity.SpawnReason;
|
import net.minecraft.entity.SpawnReason;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
@@ -30,7 +29,6 @@ import net.minecraft.world.StructureWorldAccess;
|
|||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.ChunkGenerationStep;
|
import net.minecraft.world.chunk.ChunkGenerationStep;
|
||||||
import net.minecraft.world.tick.MultiTickScheduler;
|
import net.minecraft.world.tick.MultiTickScheduler;
|
||||||
import net.minecraft.world.tick.OrderedTick;
|
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Implements;
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
import org.spongepowered.asm.mixin.Interface;
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
@@ -52,7 +50,7 @@ import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
|||||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.mod.implmentation.FabricEntityTypeExtended;
|
import com.dfsek.terra.mod.implmentation.MinecraftEntityTypeExtended;
|
||||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||||
|
|
||||||
|
|
||||||
@@ -94,41 +92,25 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
|
|||||||
@Intrinsic(displace = true)
|
@Intrinsic(displace = true)
|
||||||
public void terraWorld$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
public void terraWorld$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||||
BlockPos blockPos = new BlockPos(x, y, z);
|
BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
|
net.minecraft.block.BlockState state;
|
||||||
|
|
||||||
int flags = physics ? 3 : 1042;
|
int flags = physics ? 3 : 1042;
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
|
boolean isExtended = MinecraftUtil.isCompatibleBlockStateExtended(data);
|
||||||
|
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
BlockStateArgument arg = ((BlockStateArgument) data);
|
BlockStateArgument arg = ((BlockStateArgument) data);
|
||||||
net.minecraft.block.BlockState state = arg.getBlockState();
|
state = arg.getBlockState();
|
||||||
setBlockState(blockPos, state, flags);
|
setBlockState(blockPos, state, flags);
|
||||||
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
|
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
|
||||||
net.minecraft.block.entity.BlockEntity blockEntity;
|
|
||||||
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
|
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
|
||||||
if("DUMMY".equals(nbt.getString("id", ""))) {
|
MinecraftUtil.loadBlockEntity(chunk, world, blockPos, state, nbt);
|
||||||
if(state.hasBlockEntity()) {
|
|
||||||
blockEntity = ((BlockEntityProvider) state.getBlock()).createBlockEntity(blockPos, state);
|
|
||||||
} else {
|
|
||||||
blockEntity = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
blockEntity = net.minecraft.block.entity.BlockEntity.createFromNbt(blockPos, state, nbt, getRegistryManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(blockEntity != null) {
|
|
||||||
blockEntity.setWorld(world);
|
|
||||||
chunk.setBlockEntity(blockEntity);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setBlockState(blockPos, (net.minecraft.block.BlockState) data, flags);
|
state = (net.minecraft.block.BlockState) data;
|
||||||
|
setBlockState(blockPos, state, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(physics) {
|
if(physics) {
|
||||||
net.minecraft.block.BlockState state =
|
MinecraftUtil.schedulePhysics(state, blockPos, getFluidTickScheduler(), getBlockTickScheduler());
|
||||||
isExtended ? ((BlockStateArgument) data).getBlockState() : ((net.minecraft.block.BlockState) data);
|
|
||||||
if(state.isLiquid()) {
|
|
||||||
getFluidTickScheduler().scheduleTick(OrderedTick.create(state.getFluidState().getFluid(), blockPos));
|
|
||||||
} else {
|
|
||||||
getBlockTickScheduler().scheduleTick(OrderedTick.create(state.getBlock(), blockPos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +130,7 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockEntity terraWorld$getBlockEntity(int x, int y, int z) {
|
public BlockEntity terraWorld$getBlockEntity(int x, int y, int z) {
|
||||||
return MinecraftUtil.createState(this, new BlockPos(x, y, z));
|
return MinecraftUtil.createBlockEntity(this, new BlockPos(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int terraWorld$getMinHeight() {
|
public int terraWorld$getMinHeight() {
|
||||||
@@ -165,10 +147,10 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
|
|||||||
|
|
||||||
@SuppressWarnings("DataFlowIssue")
|
@SuppressWarnings("DataFlowIssue")
|
||||||
public Entity terraWorld$spawnEntity(double x, double y, double z, EntityType data) {
|
public Entity terraWorld$spawnEntity(double x, double y, double z, EntityType data) {
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(FabricEntityTypeExtended.class);
|
boolean isExtended = MinecraftUtil.isCompatibleEntityTypeExtended(data);
|
||||||
net.minecraft.entity.Entity entity;
|
net.minecraft.entity.Entity entity;
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
FabricEntityTypeExtended type = ((FabricEntityTypeExtended) data);
|
MinecraftEntityTypeExtended type = ((MinecraftEntityTypeExtended) data);
|
||||||
NbtCompound nbt = (NbtCompound) ((Object) type.getData());
|
NbtCompound nbt = (NbtCompound) ((Object) type.getData());
|
||||||
entity = net.minecraft.entity.EntityType.loadEntityWithPassengers(nbt, world, SpawnReason.CHUNK_GENERATION, (entityx) -> {
|
entity = net.minecraft.entity.EntityType.loadEntityWithPassengers(nbt, world, SpawnReason.CHUNK_GENERATION, (entityx) -> {
|
||||||
entityx.refreshPositionAndAngles(x, y, z, entityx.getYaw(), entityx.getPitch());
|
entityx.refreshPositionAndAngles(x, y, z, entityx.getYaw(), entityx.getPitch());
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package com.dfsek.terra.mod.mixin.implementations.terra.world;
|
package com.dfsek.terra.mod.mixin.implementations.terra.world;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
|
||||||
import net.minecraft.command.argument.BlockStateArgument;
|
import net.minecraft.command.argument.BlockStateArgument;
|
||||||
import net.minecraft.entity.SpawnReason;
|
import net.minecraft.entity.SpawnReason;
|
||||||
import net.minecraft.fluid.Fluid;
|
import net.minecraft.fluid.Fluid;
|
||||||
@@ -30,7 +29,6 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.MutableWorldProperties;
|
import net.minecraft.world.MutableWorldProperties;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import net.minecraft.world.tick.OrderedTick;
|
|
||||||
import net.minecraft.world.tick.WorldTickScheduler;
|
import net.minecraft.world.tick.WorldTickScheduler;
|
||||||
import org.spongepowered.asm.mixin.Implements;
|
import org.spongepowered.asm.mixin.Implements;
|
||||||
import org.spongepowered.asm.mixin.Interface;
|
import org.spongepowered.asm.mixin.Interface;
|
||||||
@@ -50,7 +48,8 @@ import com.dfsek.terra.api.world.chunk.Chunk;
|
|||||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||||
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.mod.generation.TerraBiomeSource;
|
import com.dfsek.terra.mod.generation.TerraBiomeSource;
|
||||||
import com.dfsek.terra.mod.implmentation.FabricEntityTypeExtended;
|
import com.dfsek.terra.mod.implmentation.MinecraftEntityTypeExtended;
|
||||||
|
import com.dfsek.terra.mod.mixin.access.WorldChunkAccessor;
|
||||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||||
|
|
||||||
|
|
||||||
@@ -71,10 +70,10 @@ public abstract class ServerWorldMixin extends World {
|
|||||||
|
|
||||||
|
|
||||||
public Entity terra$spawnEntity(double x, double y, double z, EntityType data) {
|
public Entity terra$spawnEntity(double x, double y, double z, EntityType data) {
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(FabricEntityTypeExtended.class);
|
boolean isExtended = MinecraftUtil.isCompatibleEntityTypeExtended(data);
|
||||||
net.minecraft.entity.Entity entity;
|
net.minecraft.entity.Entity entity;
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
FabricEntityTypeExtended type = ((FabricEntityTypeExtended) data);
|
MinecraftEntityTypeExtended type = ((MinecraftEntityTypeExtended) data);
|
||||||
NbtCompound nbt = (NbtCompound) ((Object) type.getData());
|
NbtCompound nbt = (NbtCompound) ((Object) type.getData());
|
||||||
entity = net.minecraft.entity.EntityType.loadEntityWithPassengers(nbt, this, SpawnReason.CHUNK_GENERATION, (entityx) -> {
|
entity = net.minecraft.entity.EntityType.loadEntityWithPassengers(nbt, this, SpawnReason.CHUNK_GENERATION, (entityx) -> {
|
||||||
entityx.refreshPositionAndAngles(x, y, z, entityx.getYaw(), entityx.getPitch());
|
entityx.refreshPositionAndAngles(x, y, z, entityx.getYaw(), entityx.getPitch());
|
||||||
@@ -92,44 +91,28 @@ public abstract class ServerWorldMixin extends World {
|
|||||||
|
|
||||||
public void terra$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
public void terra$setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||||
BlockPos blockPos = new BlockPos(x, y, z);
|
BlockPos blockPos = new BlockPos(x, y, z);
|
||||||
|
net.minecraft.block.BlockState state;
|
||||||
|
|
||||||
int flags = physics ? 3 : 1042;
|
int flags = physics ? 3 : 1042;
|
||||||
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
|
boolean isExtended = MinecraftUtil.isCompatibleBlockStateExtended(data);
|
||||||
|
|
||||||
if(isExtended) {
|
if(isExtended) {
|
||||||
BlockStateArgument arg = ((BlockStateArgument) data);
|
BlockStateArgument arg = ((BlockStateArgument) data);
|
||||||
net.minecraft.block.BlockState state = arg.getBlockState();
|
state = arg.getBlockState();
|
||||||
setBlockState(blockPos, state, flags);
|
setBlockState(blockPos, state, flags);
|
||||||
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
|
net.minecraft.world.chunk.Chunk chunk = getWorldChunk(blockPos);
|
||||||
net.minecraft.block.entity.BlockEntity blockEntity;
|
((WorldChunkAccessor) chunk).invokeLoadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).getData()));
|
||||||
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
|
|
||||||
if("DUMMY".equals(nbt.getString("id", ""))) {
|
|
||||||
if(state.hasBlockEntity()) {
|
|
||||||
blockEntity = ((BlockEntityProvider) state.getBlock()).createBlockEntity(blockPos, state);
|
|
||||||
} else {
|
|
||||||
blockEntity = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
blockEntity = net.minecraft.block.entity.BlockEntity.createFromNbt(blockPos, state, nbt, getRegistryManager());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(blockEntity != null) {
|
|
||||||
blockEntity.setWorld(this);
|
|
||||||
chunk.setBlockEntity(blockEntity);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setBlockState(blockPos, (net.minecraft.block.BlockState) data, flags);
|
state = (net.minecraft.block.BlockState) data;
|
||||||
|
setBlockState(blockPos, state, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(physics) {
|
if(physics) {
|
||||||
net.minecraft.block.BlockState state =
|
MinecraftUtil.schedulePhysics(state, blockPos, this.getFluidTickScheduler(), this.getBlockTickScheduler());
|
||||||
isExtended ? ((BlockStateArgument) data).getBlockState() : ((net.minecraft.block.BlockState) data);
|
|
||||||
if(state.isLiquid()) {
|
|
||||||
getFluidTickScheduler().scheduleTick(OrderedTick.create(state.getFluidState().getFluid(), blockPos));
|
|
||||||
} else {
|
|
||||||
getBlockTickScheduler().scheduleTick(OrderedTick.create(state.getBlock(), blockPos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Intrinsic
|
@Intrinsic
|
||||||
public long terra$getSeed() {
|
public long terra$getSeed() {
|
||||||
return ((net.minecraft.server.world.ServerWorld) (Object) this).getSeed();
|
return ((net.minecraft.server.world.ServerWorld) (Object) this).getSeed();
|
||||||
@@ -149,7 +132,7 @@ public abstract class ServerWorldMixin extends World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BlockEntity terra$getBlockEntity(int x, int y, int z) {
|
public BlockEntity terra$getBlockEntity(int x, int y, int z) {
|
||||||
return MinecraftUtil.createState(this, new BlockPos(x, y, z));
|
return MinecraftUtil.createBlockEntity(this, new BlockPos(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int terra$getMinHeight() {
|
public int terra$getMinHeight() {
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package com.dfsek.terra.mod.util;
|
package com.dfsek.terra.mod.util;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
import net.minecraft.block.entity.LootableContainerBlockEntity;
|
||||||
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
import net.minecraft.block.entity.MobSpawnerBlockEntity;
|
||||||
import net.minecraft.block.entity.SignBlockEntity;
|
import net.minecraft.block.entity.SignBlockEntity;
|
||||||
|
import net.minecraft.command.argument.BlockStateArgument;
|
||||||
|
import net.minecraft.fluid.Fluid;
|
||||||
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.registry.RegistryKeys;
|
||||||
@@ -10,10 +16,14 @@ import net.minecraft.registry.entry.RegistryEntry;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.intprovider.IntProviderType;
|
import net.minecraft.util.math.intprovider.IntProviderType;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldAccess;
|
import net.minecraft.world.WorldAccess;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||||
|
import net.minecraft.world.tick.OrderedTick;
|
||||||
|
import net.minecraft.world.tick.TickScheduler;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -25,11 +35,13 @@ import com.dfsek.terra.api.block.entity.Container;
|
|||||||
import com.dfsek.terra.api.block.entity.MobSpawner;
|
import com.dfsek.terra.api.block.entity.MobSpawner;
|
||||||
import com.dfsek.terra.api.block.entity.Sign;
|
import com.dfsek.terra.api.block.entity.Sign;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
import com.dfsek.terra.api.util.range.ConstantRange;
|
import com.dfsek.terra.api.util.range.ConstantRange;
|
||||||
import com.dfsek.terra.mod.CommonPlatform;
|
import com.dfsek.terra.mod.CommonPlatform;
|
||||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||||
import com.dfsek.terra.mod.data.Codecs;
|
import com.dfsek.terra.mod.data.Codecs;
|
||||||
|
import com.dfsek.terra.mod.implmentation.MinecraftEntityTypeExtended;
|
||||||
import com.dfsek.terra.mod.implmentation.TerraIntProvider;
|
import com.dfsek.terra.mod.implmentation.TerraIntProvider;
|
||||||
import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
|
import com.dfsek.terra.mod.mixin_ifaces.FloraFeatureHolder;
|
||||||
|
|
||||||
@@ -46,7 +58,7 @@ public final class MinecraftUtil {
|
|||||||
.flatMap(id -> Optional.ofNullable(registry.getEntry(id)));
|
.flatMap(id -> Optional.ofNullable(registry.getEntry(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {
|
public static BlockEntity createBlockEntity(WorldAccess worldAccess, BlockPos pos) {
|
||||||
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
net.minecraft.block.entity.BlockEntity entity = worldAccess.getBlockEntity(pos);
|
||||||
if(entity instanceof SignBlockEntity) {
|
if(entity instanceof SignBlockEntity) {
|
||||||
return (Sign) entity;
|
return (Sign) entity;
|
||||||
@@ -58,6 +70,42 @@ public final class MinecraftUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void schedulePhysics(BlockState blockState, BlockPos blockPos, TickScheduler<Fluid> fluidScheduler,
|
||||||
|
TickScheduler<Block> blockScheduler) {
|
||||||
|
if(blockState.isLiquid()) {
|
||||||
|
fluidScheduler.scheduleTick(OrderedTick.create(blockState.getFluidState().getFluid(), blockPos));
|
||||||
|
} else {
|
||||||
|
blockScheduler.scheduleTick(OrderedTick.create(blockState.getBlock(), blockPos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCompatibleBlockStateExtended(com.dfsek.terra.api.block.state.BlockState blockState) {
|
||||||
|
return blockState.isExtended() && BlockStateArgument.class.isAssignableFrom(blockState.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
//[Vanilla Copy]
|
||||||
|
public static void loadBlockEntity(Chunk chunk, World world, BlockPos blockPos, BlockState state, NbtCompound nbt) {
|
||||||
|
net.minecraft.block.entity.BlockEntity blockEntity;
|
||||||
|
if("DUMMY".equals(nbt.getString("id", ""))) {
|
||||||
|
if(state.hasBlockEntity()) {
|
||||||
|
blockEntity = ((BlockEntityProvider) state.getBlock()).createBlockEntity(blockPos, state);
|
||||||
|
} else {
|
||||||
|
blockEntity = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
blockEntity = net.minecraft.block.entity.BlockEntity.createFromNbt(blockPos, state, nbt, world.getRegistryManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(blockEntity != null) {
|
||||||
|
blockEntity.setWorld(world);
|
||||||
|
chunk.setBlockEntity(blockEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isCompatibleEntityTypeExtended(EntityType entityType) {
|
||||||
|
return entityType.isExtended() && MinecraftEntityTypeExtended.class.isAssignableFrom(entityType.getClass());
|
||||||
|
}
|
||||||
|
|
||||||
public static void registerIntProviderTypes() {
|
public static void registerIntProviderTypes() {
|
||||||
IntProviderType<TerraIntProvider> CONSTANT = IntProviderType.register("terra:constant_range",
|
IntProviderType<TerraIntProvider> CONSTANT = IntProviderType.register("terra:constant_range",
|
||||||
Codecs.TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE);
|
Codecs.TERRA_CONSTANT_RANGE_INT_PROVIDER_TYPE);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
"access.StateAccessor",
|
"access.StateAccessor",
|
||||||
"access.StructureAccessorAccessor",
|
"access.StructureAccessorAccessor",
|
||||||
"access.VillagerTypeAccessor",
|
"access.VillagerTypeAccessor",
|
||||||
|
"access.WorldChunkAccessor",
|
||||||
"generalize.ServerWorldMixin",
|
"generalize.ServerWorldMixin",
|
||||||
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
"implementations.compat.GenerationSettingsFloraFeaturesMixin",
|
||||||
"implementations.terra.BiomeMixin",
|
"implementations.terra.BiomeMixin",
|
||||||
|
|||||||
Reference in New Issue
Block a user