Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ org.gradle.caching=true

# Dependencies
graal_version=25.2.4
cyclopscore_version=1.25.5-643
cyclopscore_version=1.30.0-1205
integrateddynamics_version=1.24.1-1004
jei_version=19.16.0.152
commoncapabilities_version=2.9.3-147
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ public void setExposedDiskId(int exposedDiskId) {
this.onDirty();
ScriptingNetworkHelpers.getScriptingNetwork(getNetwork())
.ifPresent(scriptingNetwork -> {
if (exposedDiskId == -1) {
// Also remove the old disk when it is directly replaced by another one
if (oldExposedDiskId >= 0) {
scriptingNetwork.removeDisk(oldExposedDiskId);
} else {
}
if (exposedDiskId >= 0) {
scriptingNetwork.addDisk(exposedDiskId);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mojang.blaze3d.systems.RenderSystem;
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.client.KeyMapping;
Expand Down Expand Up @@ -87,6 +86,8 @@ public class ContainerScreenTerminalScripting extends ContainerScreenExtended<Co
public static int SCRIPT_Y = 18;
public static int SCRIPT_WIDTH = 168;
public static int SCRIPT_HEIGHT = 115;
// Darkens areas that are not usable yet
private static final int INACTIVE_OVERLAY = Helpers.RGBAToInt(0, 0, 0, 60);
public static int FOCUS_MARGIN = 20;
// JEI keeps its bookmark and config buttons in the bottom corners, even when its overlay is hidden
public static int FOCUS_MARGIN_JEI = 28;
Expand Down Expand Up @@ -151,7 +152,8 @@ public void init() {
fieldDisk.setTextColor(16777215);
fieldDisk.setCanLoseFocus(true);
fieldDisk.setEditable(true);
fieldDisk.setValue(String.valueOf(getMenu().getActiveDisk()));
// Without disks, the active disk is -1, which is not a real disk
fieldDisk.setValue(getMenu().getActiveDisk() >= 0 ? String.valueOf(getMenu().getActiveDisk()) : "");

scrollBar = new WidgetScrollBar(leftPos + 5, topPos + 18, 162,
Component.translatable("gui.cyclopscore.scrollbar"), this::setFirstRow, PATHS_MAX_ROWS) {
Expand Down Expand Up @@ -216,7 +218,8 @@ public int getTotalRows() {
(button) -> this.createNewFile(), true);
buttonOpenFolder = null;
buttonOpenFolderDisk = Integer.MIN_VALUE;
if (!focusMode) {
// Scripts can only be created or opened on a disk
if (!focusMode && !getMenu().getAvailableDisks().isEmpty()) {
addRenderableWidget(buttonCreateFile);
if (canOpenFolder) {
buttonOpenFolder = new ButtonIcon(this.leftPos + PATHS_X + PATHS_WIDTH - 10, this.topPos + 222, 10, 10,
Expand Down Expand Up @@ -440,22 +443,38 @@ protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int mouseX,
this.renderScriptPaths(guiGraphics, mouseX, mouseY, partialTicks);
} else {
// Gray-out editor and file list
RenderSystem.setShaderColor(0.3F, 0.3F, 0.3F, 0.3F);
guiGraphics.fill(leftPos + PATHS_X, topPos + PATHS_Y, leftPos + PATHS_X + PATHS_WIDTH, topPos + PATHS_Y + PATHS_HEIGHT, Helpers.RGBAToInt(50, 50, 50, 100));
RenderSystem.setShaderColor(1, 1, 1, 1);
guiGraphics.fill(leftPos + PATHS_X, topPos + PATHS_Y, leftPos + PATHS_X + PATHS_WIDTH, topPos + PATHS_Y + PATHS_HEIGHT, INACTIVE_OVERLAY);
}

if (this.getMenu().getActiveScript() == null) {
// Gray-out editor and file list
RenderSystem.setShaderColor(0.3F, 0.3F, 0.3F, 0.3F);
guiGraphics.fill(leftPos + SCRIPT_X_INNER, topPos + SCRIPT_Y, leftPos + SCRIPT_X_INNER + SCRIPT_WIDTH, topPos + SCRIPT_Y + SCRIPT_HEIGHT, Helpers.RGBAToInt(50, 50, 50, 100));
RenderSystem.setShaderColor(1, 1, 1, 1);
// Gray-out the whole editor, but center the hint right of the line numbers
int editorX = leftPos + SCRIPT_X_INNER;
int editorY = topPos + SCRIPT_Y + 1;
int editorWidth = SCRIPT_X + 1 + SCRIPT_WIDTH - SCRIPT_X_INNER;
guiGraphics.fill(leftPos + SCRIPT_X + 1, editorY, editorX + editorWidth, editorY + SCRIPT_HEIGHT, INACTIVE_OVERLAY);

// Explain what to do to start editing, centered in the editor
List<FormattedCharSequence> lines = font.split(getEmptyEditorHint(), editorWidth - 8);
int lineY = editorY + (SCRIPT_HEIGHT - lines.size() * font.lineHeight) / 2;
for (FormattedCharSequence line : lines) {
guiGraphics.drawString(font, line, editorX + (editorWidth - font.width(line)) / 2, lineY, Helpers.RGBToInt(60, 60, 60), false);
lineY += font.lineHeight;
}
}

displayErrors.drawBackground(guiGraphics, getMenu().getReadErrors(), getErrorX(), getErrorY(), getErrorX(), getErrorY(), this,
this.leftPos, this.topPos, getMenu().canWriteScriptToVariable());
}

protected Component getEmptyEditorHint() {
if (getMenu().getAvailableDisks().isEmpty()) {
return Component.translatable("gui.integratedscripting.hint.no_disks");
}
Map<Path, String> scripts = getActiveScripts();
return Component.translatable(scripts == null || scripts.isEmpty() ? "gui.integratedscripting.hint.no_scripts" : "gui.integratedscripting.hint.select_script");
}

@Nullable
protected Map<Path, String> getActiveScripts() {
return this.container.getLastScripts().get(this.container.getActiveDisk());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public boolean onNetworkAddition(INetwork network) {
if(super.onNetworkAddition(network)) {
return ScriptingNetworkHelpers.getScriptingNetwork(network)
.map(scriptingNetwork -> {
scriptingNetwork.addDisk(getId());
// An empty drive has no disk to expose
if (getId() >= 0) {
scriptingNetwork.addDisk(getId());
}
return true;
})
.orElse(false);
Expand All @@ -55,7 +58,9 @@ public void onNetworkRemoval(INetwork network) {
super.onNetworkRemoval(network);
ScriptingNetworkHelpers.getScriptingNetwork(network)
.ifPresent(scriptingNetwork -> {
scriptingNetwork.removeDisk(getId());
if (getId() >= 0) {
scriptingNetwork.removeDisk(getId());
}
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.cyclops.integratedscripting.gametest;

import net.minecraft.core.BlockPos;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.gametest.GameTestHolder;
import net.neoforged.neoforge.gametest.PrefixGameTestTemplate;
import org.cyclops.integrateddynamics.RegistryEntries;
import org.cyclops.integratedscripting.Reference;
import org.cyclops.integratedscripting.blockentity.BlockEntityScriptingDrive;
import org.cyclops.integratedscripting.core.network.ScriptingNetworkHelpers;

import java.util.Set;

@GameTestHolder(Reference.MOD_ID)
@PrefixGameTestTemplate(false)
public class GameTestsScriptingDrive {

public static final String TEMPLATE_EMPTY = "empty10";
public static final BlockPos POS = BlockPos.ZERO.offset(2, 0, 2);

@GameTest(template = TEMPLATE_EMPTY)
public void testScriptingDriveExposedDisks(GameTestHelper helper) {
// An empty drive in a network
helper.setBlock(POS, RegistryEntries.BLOCK_CABLE.value());
helper.setBlock(POS.south(), org.cyclops.integratedscripting.RegistryEntries.BLOCK_SCRIPTING_DRIVE.value());
BlockEntityScriptingDrive drive = helper.getBlockEntity(POS.south());
assertDisks(helper, drive, Set.of());

// Insert a disk
ItemStack disk1 = new ItemStack(org.cyclops.integratedscripting.RegistryEntries.ITEM_SCRIPTING_DISK);
int id1 = org.cyclops.integratedscripting.RegistryEntries.ITEM_SCRIPTING_DISK.get().getOrCreateDiskId(disk1);
drive.getInventory().setItem(0, disk1);
assertDisks(helper, drive, Set.of(id1));

// Swap it for another disk
ItemStack disk2 = new ItemStack(org.cyclops.integratedscripting.RegistryEntries.ITEM_SCRIPTING_DISK);
int id2 = org.cyclops.integratedscripting.RegistryEntries.ITEM_SCRIPTING_DISK.get().getOrCreateDiskId(disk2);
drive.getInventory().setItem(0, disk2);
assertDisks(helper, drive, Set.of(id2));

// Remove it
drive.getInventory().setItem(0, ItemStack.EMPTY);
assertDisks(helper, drive, Set.of());

helper.succeed();
}

private static void assertDisks(GameTestHelper helper, BlockEntityScriptingDrive drive, Set<Integer> expected) {
Set<Integer> disks = ScriptingNetworkHelpers.getScriptingNetwork(drive.getNetwork()).orElseThrow().getDisks();
helper.assertTrue(disks.equals(expected), "Expected disks " + expected + " but got " + disks);
}

}
3 changes: 3 additions & 0 deletions src/main/resources/assets/integratedscripting/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"_comment": "Gui",
"gui.integratedscripting.disk": "Disk",
"gui.integratedscripting.script": "Script",
"gui.integratedscripting.hint.no_disks": "Insert a Scripting Disk into a connected Scripting Drive.",
"gui.integratedscripting.hint.no_scripts": "Click + to create a script.",
"gui.integratedscripting.hint.select_script": "Select a script from the list.",
"gui.integratedscripting.create_file": "Create File",
"gui.integratedscripting.open_folder": "Open scripts folder",
"gui.integratedscripting.find": "Find",
Expand Down
Loading