More Errors
This commit is contained in:
+19
-9
@@ -124,16 +124,26 @@ public class ConfigureInstructionGui extends MinionsGui implements ConfiguredIns
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRunSlot() {
|
private void updateRunSlot() {
|
||||||
if(!instruction.isRunning()) {
|
List<Component> errors = instruction.preCheck();
|
||||||
gui.setSlot(26, new GuiElementBuilder(Items.ARROW)
|
if(errors.isEmpty()) {
|
||||||
.setName(Component.translatable("minions.gui.instruction.run"))
|
if (!instruction.isRunning()) {
|
||||||
.setCallback(() -> instruction.run(minion.getInstructionManager()))
|
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 {
|
} else {
|
||||||
gui.setSlot(26, new GuiElementBuilder(Items.BARRIER)
|
GuiElementBuilder builder = new GuiElementBuilder(Items.RED_WOOL)
|
||||||
.setName(Component.translatable("minions.gui.instruction.stop"))
|
.setName(Component.translatable("minions.gui.instruction.errors"));
|
||||||
.setCallback(() -> instruction.stop(minion.getInstructionManager()))
|
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.level.storage.ValueOutput;
|
||||||
import net.minecraft.world.phys.Vec2;
|
import net.minecraft.world.phys.Vec2;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import org.jspecify.annotations.NullMarked;
|
||||||
import org.jspecify.annotations.Nullable;
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@NullMarked
|
||||||
public class MinionFakePlayer extends ServerPlayer {
|
public class MinionFakePlayer extends ServerPlayer {
|
||||||
public Runnable fixStartingPosition = () -> {};
|
public Runnable fixStartingPosition = () -> {};
|
||||||
|
|
||||||
@@ -310,6 +312,7 @@ public class MinionFakePlayer extends ServerPlayer {
|
|||||||
public void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) {
|
public void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) {
|
||||||
super.dropAllDeathLoot(world, damageSource);
|
super.dropAllDeathLoot(world, damageSource);
|
||||||
ItemEntity entity = drop(toItemStack(world.getServer()), true, false);
|
ItemEntity entity = drop(toItemStack(world.getServer()), true, false);
|
||||||
|
//noinspection ConstantValue (Wrong nullability of drop)
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
entity.setUnlimitedLifetime();
|
entity.setUnlimitedLifetime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class ConverterList {
|
public class ConverterList {
|
||||||
public static final Codec<ConverterList> CODEC = ValueConverter.CODEC.listOf().xmap(ConverterList::new, l -> l.converters);
|
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) {
|
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());
|
Result<I, Component> inter = Casts.castOrError(from, converter.getFrom());
|
||||||
if(inter instanceof Result.Error<I, Component> error) {
|
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());
|
Result<T, Component> to = converter.convert(inter.getOrThrow());
|
||||||
|
|
||||||
@@ -81,6 +86,24 @@ public class ConverterList {
|
|||||||
return warning;
|
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
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (!(o instanceof ConverterList that)) return false;
|
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()));
|
return convertedResult.flatMap(convertedValue -> Casts.castOrError(convertedValue, parameter.type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Component check(Consumer<Component> errorConsumer) {
|
public void check(Consumer<Component> errorConsumer) {
|
||||||
//TODO check it
|
converters.check(errorConsumer, parameter.type(), supplier.getValueType());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R extends InstructionRuntime<R>> MapCodec<ValueSupplierEntry<?,R>> getCodec(Codec<ValueSupplier<?,R>> argumentCodec) {
|
public static <R extends InstructionRuntime<R>> MapCodec<ValueSupplierEntry<?,R>> getCodec(Codec<ValueSupplier<?,R>> argumentCodec) {
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
"minions.gui.instruction.configure.delete.confirm": "Delete %s?",
|
"minions.gui.instruction.configure.delete.confirm": "Delete %s?",
|
||||||
"minions.gui.instruction.configure.copy": "Copy Reference",
|
"minions.gui.instruction.configure.copy": "Copy Reference",
|
||||||
"minions.gui.instruction.configure.copy.description": "Click here and then use a Minion Trigger Block to bind it",
|
"minions.gui.instruction.configure.copy.description": "Click here and then use a Minion Trigger Block to bind it",
|
||||||
|
"minions.gui.instruction.errors": "Errors",
|
||||||
"minions.gui.instruction.last_errors": "Last Errors",
|
"minions.gui.instruction.last_errors": "Last Errors",
|
||||||
"minions.gui.instruction.run": "Run",
|
"minions.gui.instruction.run": "Run",
|
||||||
"minions.gui.instruction.stop": "Stop",
|
"minions.gui.instruction.stop": "Stop",
|
||||||
|
|||||||
Reference in New Issue
Block a user