More Errors

This commit is contained in:
skippyall
2026-05-30 14:34:43 +02:00
parent 7ed686d8d9
commit d3c84ac000
5 changed files with 49 additions and 13 deletions
@@ -124,16 +124,26 @@ public class ConfigureInstructionGui extends MinionsGui implements ConfiguredIns
}
private void updateRunSlot() {
if(!instruction.isRunning()) {
gui.setSlot(26, new GuiElementBuilder(Items.ARROW)
.setName(Component.translatable("minions.gui.instruction.run"))
.setCallback(() -> instruction.run(minion.getInstructionManager()))
);
List<Component> errors = instruction.preCheck();
if(errors.isEmpty()) {
if (!instruction.isRunning()) {
gui.setSlot(26, new GuiElementBuilder(Items.ARROW)
.setName(Component.translatable("minions.gui.instruction.run"))
.setCallback(() -> instruction.run(minion.getInstructionManager()))
);
} else {
gui.setSlot(26, new GuiElementBuilder(Items.BARRIER)
.setName(Component.translatable("minions.gui.instruction.stop"))
.setCallback(() -> instruction.stop(minion.getInstructionManager()))
);
}
} else {
gui.setSlot(26, new GuiElementBuilder(Items.BARRIER)
.setName(Component.translatable("minions.gui.instruction.stop"))
.setCallback(() -> instruction.stop(minion.getInstructionManager()))
);
GuiElementBuilder builder = new GuiElementBuilder(Items.RED_WOOL)
.setName(Component.translatable("minions.gui.instruction.errors"));
for(Component error : errors) {
builder.addLoreLine(error);
}
gui.setSlot(26, builder);
}
}
@@ -51,12 +51,14 @@ import net.minecraft.world.level.storage.ValueInput;
import net.minecraft.world.level.storage.ValueOutput;
import net.minecraft.world.phys.Vec2;
import net.minecraft.world.phys.Vec3;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
@NullMarked
public class MinionFakePlayer extends ServerPlayer {
public Runnable fixStartingPosition = () -> {};
@@ -310,6 +312,7 @@ public class MinionFakePlayer extends ServerPlayer {
public void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) {
super.dropAllDeathLoot(world, damageSource);
ItemEntity entity = drop(toItemStack(world.getServer()), true, false);
//noinspection ConstantValue (Wrong nullability of drop)
if (entity != null) {
entity.setUnlimitedLifetime();
}
@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.function.Consumer;
public class ConverterList {
public static final Codec<ConverterList> CODEC = ValueConverter.CODEC.listOf().xmap(ConverterList::new, l -> l.converters);
@@ -55,7 +56,11 @@ public class ConverterList {
private <F,I,T> Result<TypedValue<?>, Component> convert(TypedValue<F> from, ValueConverter<I,T> converter, ListIterator<ValueConverter<?,?>> iterator) {
Result<I, Component> inter = Casts.castOrError(from, converter.getFrom());
if(inter instanceof Result.Error<I, Component> error) {
return new Result.Error<>(Component.translatable("minions.converter.list.passing_error", iterator.previousIndex(), error.message()));
return new Result.Error<>(
Component.translatable("minions.converter.list.passing_error", iterator.previousIndex())
.append("\n")
.append(error.message())
);
}
Result<T, Component> to = converter.convert(inter.getOrThrow());
@@ -81,6 +86,24 @@ public class ConverterList {
return warning;
}
public void check(Consumer<Component> errorConsumer, ValueType<?> input, ValueType<?> output) {
Component firstCastWarning = createCastWarning(input, converters.isEmpty() ? output : converters.get(0).getFrom());
if(firstCastWarning != null) {
errorConsumer.accept(firstCastWarning);
}
for(int i = 0; i < converters.size(); i++) {
ValueConverter<?,?> converter = converters.get(i);
Component converterWarning = createConverterWarning(converter);
if(converterWarning != null) {
errorConsumer.accept(converterWarning);
}
Component castWarning = createCastWarning(converter.getTo(), i + 1 < converters.size() ? converters.get(i + 1).getFrom() : output);
if(castWarning != null) {
errorConsumer.accept(castWarning);
}
}
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ConverterList that)) return false;
@@ -158,9 +158,8 @@ public class ValueSupplierList<R extends InstructionRuntime<R>> {
return convertedResult.flatMap(convertedValue -> Casts.castOrError(convertedValue, parameter.type()));
}
public @Nullable Component check(Consumer<Component> errorConsumer) {
//TODO check it
return null;
public void check(Consumer<Component> errorConsumer) {
converters.check(errorConsumer, parameter.type(), supplier.getValueType());
}
public static <R extends InstructionRuntime<R>> MapCodec<ValueSupplierEntry<?,R>> getCodec(Codec<ValueSupplier<?,R>> argumentCodec) {