start working on error handling stuff

This commit is contained in:
dfsek
2025-12-29 22:18:44 -07:00
parent 9a16336f53
commit cb08401536
76 changed files with 212 additions and 165 deletions
@@ -76,7 +76,7 @@ public abstract class MinecraftAddon implements BaseAddon {
}
@Override
public Version getVersion() {
public Version version() {
return VERSION;
}
}
@@ -18,7 +18,7 @@ public final class Codecs {
public static final Codec<RegistryKey> TERRA_REGISTRY_KEY = RecordCodecBuilder
.create(registryKey -> registryKey.group(Codec.STRING.fieldOf("namespace")
.stable()
.forGetter(RegistryKey::getNamespace),
.forGetter(RegistryKey::namespace),
Codec.STRING.fieldOf("id")
.stable()
.forGetter(RegistryKey::getID))
@@ -138,11 +138,11 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
com.dfsek.terra.api.block.state.BlockState data = delegate.getPalette(x + xi, y, z + zi, world, biomeProvider).get(
depth, x + xi, y, z + zi, world.getSeed());
BlockPos blockPos = new BlockPos(x, y, z);
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
boolean isExtended = data.extended() && data.getClass().equals(BlockStateArgument.class);
if(isExtended) {
BlockStateExtended blockStateExtended = (BlockStateExtended) data;
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.getState();
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.state();
chunk.setBlockState(blockPos, blockState, 0);
} else {
chunk.setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0);
@@ -196,7 +196,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
for(int y = height.getTopYInclusive() - 1; y >= min; y--) {
com.dfsek.terra.api.block.state.BlockState terraBlockState = delegate.getBlock(properties, x, y, z, biomeProvider);
BlockState blockState =
(BlockState) (terraBlockState.isExtended() ? ((BlockStateExtended) terraBlockState).getState() : terraBlockState);
(BlockState) (terraBlockState.extended() ? ((BlockStateExtended) terraBlockState).state() : terraBlockState);
if(heightmap
.getBlockPredicate()
.test(blockState)) return y + 1;
@@ -212,7 +212,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
for(int y = height.getTopYInclusive() - 1; y >= height.getBottomY(); y--) {
com.dfsek.terra.api.block.state.BlockState terraBlockState = delegate.getBlock(properties, x, y, z, biomeProvider);
BlockState blockState =
(BlockState) (terraBlockState.isExtended() ? ((BlockStateExtended) terraBlockState).getState() : terraBlockState);
(BlockState) (terraBlockState.extended() ? ((BlockStateExtended) terraBlockState).state() : terraBlockState);
array[y - height.getBottomY()] = blockState;
}
return new VerticalBlockSample(height.getBottomY(), array);
@@ -17,6 +17,9 @@
package com.dfsek.terra.mod.handle;
import com.dfsek.terra.api.error.Invalid;
import com.dfsek.terra.api.error.InvalidBlockStateError;
import com.dfsek.terra.api.util.generic.data.types.Either;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockEntityProvider;
@@ -51,7 +54,7 @@ public class MinecraftWorldHandle implements WorldHandle {
@SuppressWarnings("DataFlowIssue")
@Override
public @NotNull BlockState createBlockState(@NotNull String data) {
public @NotNull Either<Invalid, BlockState> createBlockState(@NotNull String data) {
try {
BlockResult blockResult = BlockArgumentParser.block(Registries.BLOCK, data, true);
BlockState blockState;
@@ -76,10 +79,10 @@ public class MinecraftWorldHandle implements WorldHandle {
blockState = (BlockState) blockResult.blockState();
}
if(blockState == null) throw new IllegalArgumentException("Invalid data: " + data);
return blockState;
if(blockState == null) return new InvalidBlockStateError(new IllegalArgumentException("Invalid data: " + data)).left();
return Either.right(blockState);
} catch(CommandSyntaxException e) {
throw new IllegalArgumentException(e);
return new InvalidBlockStateError(e).left();
}
}
@@ -29,16 +29,16 @@ import com.dfsek.terra.api.block.BlockType;
@Mixin(Block.class)
@Implements(@Interface(iface = BlockType.class, prefix = "terra$"))
public abstract class BlockMixin {
public com.dfsek.terra.api.block.state.BlockState terra$getDefaultState() {
public com.dfsek.terra.api.block.state.BlockState terra$defaultState() {
return (com.dfsek.terra.api.block.state.BlockState) ((Block) (Object) this).getDefaultState();
}
public boolean terra$isSolid() {
public boolean terra$solid() {
return ((Block) (Object) this).getDefaultState().isOpaque();
}
@SuppressWarnings("ConstantConditions")
public boolean terra$isWater() {
public boolean terra$water() {
return ((Object) this) == Blocks.WATER;
}
}
@@ -68,7 +68,7 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
rand = Random.create();
}
net.minecraft.entity.EntityType<?> entityType =
(((net.minecraft.entity.EntityType<?>) (creatureType.isExtended() && creatureType.getClass().equals(
(((net.minecraft.entity.EntityType<?>) (creatureType.extended() && creatureType.getClass().equals(
MinecraftEntityTypeExtended.class) ? ((MinecraftEntityTypeExtended) creatureType).getType() : creatureType)));
setEntityType(entityType, rand);
}
@@ -57,17 +57,17 @@ public abstract class BlockStateArgumentMixin implements Predicate<CachedBlockPo
@Intrinsic
public BlockType terra$getBlockType() {
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).getBlockType();
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).blockType();
}
@Intrinsic
public String terra$getAsString(boolean properties) {
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).getAsString(properties);
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).asString(properties);
}
@Intrinsic
public boolean terra$isAir() {
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).isAir();
return ((com.dfsek.terra.api.block.state.BlockState) getBlockState()).air();
}
@SuppressWarnings({ "ConstantValue", "DataFlowIssue", "EqualsBetweenInconvertibleTypes" })
@@ -79,12 +79,12 @@ public abstract class BlockStateArgumentMixin implements Predicate<CachedBlockPo
@SuppressWarnings("DataFlowIssue")
@Intrinsic
public ExtendedData terra$getData() {
public ExtendedData terra$data() {
return ((ExtendedData) ((Object) data));
}
@Intrinsic
public com.dfsek.terra.api.block.state.BlockState terra$getState() {
public com.dfsek.terra.api.block.state.BlockState terra$state() {
return (com.dfsek.terra.api.block.state.BlockState) getBlockState();
}
@@ -60,12 +60,12 @@ public abstract class BlockStateMixin extends State<Block, net.minecraft.block.B
}
@Intrinsic
public BlockType terra$getBlockType() {
public BlockType terra$blockType() {
return (BlockType) getBlock();
}
@Intrinsic
public String terra$getAsString(boolean properties) {
public String terra$asString(boolean properties) {
StringBuilder data = new StringBuilder(Registries.BLOCK.getId(getBlock()).toString());
if(properties && !getEntries().isEmpty()) {
data.append('[');
@@ -77,7 +77,7 @@ public abstract class BlockStateMixin extends State<Block, net.minecraft.block.B
}
@Intrinsic
public boolean terra$isAir() {
public boolean terra$air() {
return isAir();
}
}
@@ -83,7 +83,7 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
state = arg.getBlockState();
setBlockState(blockPos, state, 0, 512);
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).data());
MinecraftUtil.loadBlockEntity(chunk, world, blockPos, state, nbt);
} else {
state = (net.minecraft.block.BlockState) data;
@@ -66,7 +66,7 @@ public abstract class WorldChunkMixin {
BlockStateArgument arg = ((BlockStateArgument) data);
state = arg.getBlockState();
setBlockState(blockPos, state, 0);
loadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).getData()));
loadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).data()));
} else {
state = (net.minecraft.block.BlockState) data;
setBlockState(blockPos, state, 0);
@@ -54,11 +54,11 @@ public abstract class ProtoChunkMixin extends Chunk {
public void terra$setBlock(int x, int y, int z, @NotNull BlockState data) {
BlockPos blockPos = new BlockPos(x, y, z);
boolean isExtended = data.isExtended() && data.getClass().equals(BlockStateArgument.class);
boolean isExtended = data.extended() && data.getClass().equals(BlockStateArgument.class);
if(isExtended) {
BlockStateExtended blockStateExtended = (BlockStateExtended) data;
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.getState();
net.minecraft.block.BlockState blockState = (net.minecraft.block.BlockState) blockStateExtended.state();
this.setBlockState(blockPos, blockState, 0);
} else {
this.setBlockState(blockPos, (net.minecraft.block.BlockState) data, 0);
@@ -17,6 +17,8 @@
package com.dfsek.terra.mod.mixin.implementations.terra.entity;
import com.dfsek.terra.api.util.generic.data.types.Maybe;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
@@ -27,8 +29,6 @@ import org.spongepowered.asm.mixin.Interface;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Optional;
import com.dfsek.terra.api.command.CommandSender;
import com.dfsek.terra.api.entity.Entity;
import com.dfsek.terra.api.entity.Player;
@@ -52,15 +52,15 @@ public abstract class ServerCommandSourceMixin {
}
@Nullable
public Optional<Entity> terra$getEntity() {
return Optional.ofNullable((Entity) getEntity());
public Maybe<Entity> terra$entity() {
return Maybe.ofNullable((Entity) getEntity());
}
public Optional<Player> terra$getPlayer() {
public Maybe<Player> terra$player() {
try {
return Optional.ofNullable((Player) getPlayer());
return Maybe.ofNullable((Player) getPlayer());
} catch(CommandSyntaxException e) {
return Optional.empty();
return Maybe.nothing();
}
}
}
@@ -102,7 +102,7 @@ public abstract class ChunkRegionMixin implements StructureWorldAccess {
state = arg.getBlockState();
setBlockState(blockPos, state, flags);
net.minecraft.world.chunk.Chunk chunk = getChunk(blockPos);
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).getData());
NbtCompound nbt = ((NbtCompound) (Object) ((BlockStateExtended) data).data());
MinecraftUtil.loadBlockEntity(chunk, world, blockPos, state, nbt);
} else {
state = (net.minecraft.block.BlockState) data;
@@ -101,7 +101,7 @@ public abstract class ServerWorldMixin extends World {
state = arg.getBlockState();
setBlockState(blockPos, state, flags);
net.minecraft.world.chunk.Chunk chunk = getWorldChunk(blockPos);
((WorldChunkAccessor) chunk).invokeLoadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).getData()));
((WorldChunkAccessor) chunk).invokeLoadBlockEntity(blockPos, ((NbtCompound) (Object) ((BlockStateExtended) data).data()));
} else {
state = (net.minecraft.block.BlockState) data;
setBlockState(blockPos, state, flags);
@@ -103,7 +103,7 @@ public class BiomeUtil {
public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
return pack.getID()
.toLowerCase() + "/" + biomeID.getNamespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
.toLowerCase() + "/" + biomeID.namespace().toLowerCase(Locale.ROOT) + "/" + biomeID.getID().toLowerCase(Locale.ROOT);
}
public static Map<Identifier, List<Identifier>> getTerraBiomeMap() {
@@ -80,7 +80,7 @@ public final class MinecraftUtil {
}
public static boolean isCompatibleBlockStateExtended(com.dfsek.terra.api.block.state.BlockState blockState) {
return blockState.isExtended() && BlockStateArgument.class.isAssignableFrom(blockState.getClass());
return blockState.extended() && BlockStateArgument.class.isAssignableFrom(blockState.getClass());
}
//[Vanilla Copy]
@@ -103,7 +103,7 @@ public final class MinecraftUtil {
}
public static boolean isCompatibleEntityTypeExtended(EntityType entityType) {
return entityType.isExtended() && MinecraftEntityTypeExtended.class.isAssignableFrom(entityType.getClass());
return entityType.extended() && MinecraftEntityTypeExtended.class.isAssignableFrom(entityType.getClass());
}
public static void registerIntProviderTypes() {
@@ -49,7 +49,7 @@ public class PresetUtil {
Identifier generatorID = Identifier.tryParse(
"terra:" + pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.getNamespace().toLowerCase(
"terra:" + pack.getID().toLowerCase(Locale.ROOT) + "/" + pack.namespace().toLowerCase(
Locale.ROOT));
PRESETS.add(Pair.of(generatorID, extended));
@@ -74,7 +74,7 @@ public class PresetUtil {
platform.multiNoiseBiomeSourceParameterListRegistry();
Identifier generatorID = Identifier.of("terra",
metaPack.getID().toLowerCase(Locale.ROOT) + "/" + metaPack.getNamespace().toLowerCase(
metaPack.getID().toLowerCase(Locale.ROOT) + "/" + metaPack.namespace().toLowerCase(
Locale.ROOT));
PRESETS.add(Pair.of(generatorID, extended));