Runtime & MinionTriggerBlock start

This commit is contained in:
skippyall
2025-11-06 22:48:20 +01:00
parent cc1320d5c6
commit b413592abf
40 changed files with 726 additions and 473 deletions
@@ -5,6 +5,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import eu.pb4.polymer.core.api.other.PolymerComponent;
import io.github.skippyall.minions.MinionRegistries;
import io.github.skippyall.minions.Minions;
import io.github.skippyall.minions.minion.MinionRuntime;
import io.github.skippyall.minions.program.instruction.InstructionType;
import net.minecraft.component.ComponentType;
import net.minecraft.registry.Registries;
@@ -13,10 +14,11 @@ import net.minecraft.util.Identifier;
import java.util.List;
public record MinionModule(List<InstructionType<?>> instructions) {
public record MinionModule(List<InstructionType<MinionRuntime>> instructions, List<String> specialBehaviour) {
public static final Codec<MinionModule> CODEC = RecordCodecBuilder.create(instance ->
instance.group(
MinionRegistries.INSTRUCTION_TYPES.getCodec().listOf().fieldOf("instructions").forGetter(MinionModule::instructions)
MinionRegistries.INSTRUCTION_TYPES.getCodec().listOf().fieldOf("instructions").forGetter(MinionModule::instructions),
Codec.STRING.listOf().fieldOf("specialBehaviour").forGetter(MinionModule::specialBehaviour)
).apply(instance, MinionModule::new)
);
@@ -24,8 +26,13 @@ public record MinionModule(List<InstructionType<?>> instructions) {
public static final MinionModule EMPTY = new MinionModule(List.of());
public MinionModule(List<InstructionType<?>> instructions) {
public MinionModule(List<InstructionType<MinionRuntime>> instructions) {
this(instructions, List.of());
}
public MinionModule(List<InstructionType<MinionRuntime>> instructions, List<String> specialBehaviour) {
this.instructions = List.copyOf(instructions);
this.specialBehaviour = List.copyOf(specialBehaviour);
}
public static void register() {
@@ -19,6 +19,8 @@ import java.util.Set;
public class ModuleInventory extends SimpleInventory {
private final Set<MinionModule> modules = new HashSet<>();
private final Set<String> specialAbilities = new HashSet<>();
public ModuleInventory() {
super(27);
}
@@ -45,10 +47,12 @@ public class ModuleInventory extends SimpleInventory {
public void updateModules() {
modules.clear();
specialAbilities.clear();
for (ItemStack heldStack : heldStacks) {
MinionModule module = heldStack.get(MinionModule.COMPONENT_TYPE);
if(module != null) {
modules.add(module);
specialAbilities.addAll(module.specialBehaviour());
}
}
}
@@ -62,14 +66,14 @@ public class ModuleInventory extends SimpleInventory {
Inventories.writeData(view, heldStacks);
}
public boolean hasModule(MinionModule module) {
return modules.contains(module);
}
public Collection<MinionModule> getModules() {
return modules;
}
public boolean hasAbility(String ability) {
return specialAbilities.contains(ability);
}
public List<InstructionType<?>> getAllInstructions() {
ArrayList<InstructionType<?>> instructionTypes = new ArrayList<>();
for(MinionModule module : modules) {
@@ -11,6 +11,7 @@ import net.minecraft.screen.slot.Slot;
public class ModuleInventoryScreenHandler extends ScreenHandler {
private final int rows = 3;
private final ModuleInventory inventory;
public ModuleInventoryScreenHandler(int syncId, ModuleInventory inventory) {
super(ScreenHandlerType.GENERIC_9X3, syncId);
this.inventory = inventory;
@@ -18,14 +19,13 @@ public class ModuleInventoryScreenHandler extends ScreenHandler {
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
super(ScreenHandlerType.GENERIC_9X3, syncId);
int k;
int j;
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
this.inventory = inventory;
inventory.onOpen(playerInventory.player);
int i = (rows - 4) * 18;
for (j = 0; j < rows; ++j) {
for (k = 0; k < 9; ++k) {
for (int j = 0; j < rows; ++j) {
for (int k = 0; k < 9; ++k) {
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
@Override
public boolean canInsert(ItemStack stack) {
@@ -34,14 +34,8 @@ public class ModuleInventoryScreenHandler extends ScreenHandler {
});
}
}
for (j = 0; j < 3; ++j) {
for (k = 0; k < 9; ++k) {
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
}
}
for (j = 0; j < 9; ++j) {
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
}
addPlayerSlots(playerInventory, 8, 85);
}
@Override