Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fabrication): improve IC blueprint configuration #1879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"projectred_fabrication.tooltip.io_types": "IO types",
"projectred_fabrication.tooltip.left": "Left",
"projectred_fabrication.tooltip.name": "Name",
"projectred_fabrication.tooltip.author": "by %s",
"projectred_fabrication.tooltip.output_mask": "Output mask",
"projectred_fabrication.tooltip.right": "Right",
"projectred_fabrication.tooltip.size": "Size",
Expand All @@ -132,6 +133,7 @@
"projectred_fabrication.ui.auto_compile_description": "Enable to auto-compile design on change",
"projectred_fabrication.ui.auto_compile_disabled": "Disabled. Design is too complex",
"projectred_fabrication.ui.blueprint_dim": "Dimensions",
"projectred_fabrication.ui.blueprint_title": "%s by %s",
"projectred_fabrication.ui.blueprint_info": "Blueprint Info",
"projectred_fabrication.ui.blueprint_layers": "Layers",
"projectred_fabrication.ui.blueprint_name": "Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class EditorDataUtils {
public static final String KEY_FORMAT = "format"; // int
public static final String KEY_ACTIVE = "active"; // boolean
public static final String KEY_IC_NAME = "ic_name"; // String
public static final String KEY_IC_AUTHOR = "ic_author"; // String
public static final String KEY_TILE_MAP = "tile_map"; // CompoundTag
public static final String KEY_TILE_COUNT = "tile_count"; // int
public static final String KEY_DIMENSIONS = "dimensions"; // int
public static final String KEY_IS_BUILT = "is_built"; // boolean
public static final String KEY_IO_SPEC = "io_spec";

Expand Down Expand Up @@ -82,7 +84,9 @@ public static CompoundTag createFabricationCopy(CompoundTag editorTag) {
copy.putInt(KEY_COMPILE_FORMAT, editorTag.getInt(KEY_COMPILE_FORMAT));
copy.putBoolean(KEY_IS_BUILT, editorTag.getBoolean(KEY_IS_BUILT));
copy.putString(KEY_IC_NAME, editorTag.getString(KEY_IC_NAME));
copy.putString(KEY_IC_AUTHOR, editorTag.getString(KEY_IC_AUTHOR));
copy.putInt(KEY_TILE_COUNT, editorTag.getInt(KEY_TILE_COUNT));
copy.putString(KEY_DIMENSIONS, editorTag.getString(KEY_DIMENSIONS));
copy.put(KEY_IO_SPEC, editorTag.getCompound(KEY_IO_SPEC));
copy.putString(KEY_FLAT_MAP, editorTag.getString(KEY_FLAT_MAP));
return copy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,30 @@
import static mrtjp.projectred.fabrication.editor.EditorDataUtils.*;

public class ICWorkbenchEditor implements ICEditorStateMachine.StateMachineCallback {

public static final Style UNIFORM = Style.EMPTY.withFont(new ResourceLocation("minecraft", "uniform"));
public static final Style UNIFORM = Style.EMPTY.withFont(new ResourceLocation("minecraft", "uniform"));
public static final Style UNIFORM_DARK_GRAY = UNIFORM.withColor(ChatFormatting.DARK_GRAY);
public static final Style UNIFORM_GRAY = UNIFORM.withColor(ChatFormatting.GRAY);
public static final Style UNIFORM_RED = UNIFORM.withColor(ChatFormatting.RED);
public static final Style UNIFORM_YELLOW = UNIFORM.withColor(ChatFormatting.YELLOW);
public static final Style UNIFORM_GRAY = UNIFORM.withColor(ChatFormatting.GRAY);
public static final Style UNIFORM_RED = UNIFORM.withColor(ChatFormatting.RED);
public static final Style UNIFORM_YELLOW = UNIFORM.withColor(ChatFormatting.YELLOW);

public static final int EDITOR_FORMAT = 1;

private static final int STREAM_ID_GENERAL = 0;
private static final int STREAM_ID_GENERAL = 0;
private static final int STREAM_ID_TILE_UPDATES = 1;
private static final int STREAM_ID_FSM = 2;
private static final int STREAM_ID_FSM = 2;

// Server to client keys
private static final int KEY_ADD_TILE = 1;
private static final int KEY_REMOVE_TILE = 2;
private static final int KEY_SET_IC_NAME = 3;
private static final int KEY_ADD_TILE = 1;
private static final int KEY_REMOVE_TILE = 2;
private static final int KEY_SET_IC_NAME = 3;
private static final int KEY_SET_IC_AUTHOR = 4;
private static final int KEY_SET_IC_DIMENSIONS = 5;

// Client to server keys
private static final int KEY_TOOL = 10;
private static final int KEY_CLIENT_SEND_IC_NAME = 11;
private static final int KEY_TOOL = 10;
private static final int KEY_CLIENT_SEND_IC_NAME = 11;
private static final int KEY_CLIENT_SEND_IC_AUTHOR = 12;
private static final int KEY_CLIENT_SEND_IC_DIMENSIONS = 13;

private final IICWorkbenchEditorNetwork network;
private final BaseTileMap tileMap = new BaseTileMap(this);
Expand All @@ -51,6 +54,7 @@ public class ICWorkbenchEditor implements ICEditorStateMachine.StateMachineCallb

private boolean isActive = false;
private String icName = "untitled";
private String icAuthor = "";

public ICWorkbenchEditor(IICWorkbenchEditorNetwork network) {
this.network = network;
Expand All @@ -61,6 +65,10 @@ public String getIcName() {
return icName;
}

public String getIcAuthor() {
return icAuthor;
}

public ArrayList<IICEditorTool> getToolList() {
return toolList;
}
Expand All @@ -87,6 +95,7 @@ public void save(CompoundTag tag) {
tag.putInt(KEY_FORMAT, EDITOR_FORMAT);
tag.putBoolean(KEY_ACTIVE, isActive);
tag.putString(KEY_IC_NAME, icName);
tag.putString(KEY_IC_AUTHOR, icAuthor);

CompoundTag tileMapTag = new CompoundTag();
tileMap.save(tileMapTag);
Expand All @@ -98,20 +107,23 @@ public void save(CompoundTag tag) {
public void load(CompoundTag tag) {
isActive = tag.getBoolean(KEY_ACTIVE);
icName = tag.getString(KEY_IC_NAME);
icAuthor = tag.getString(KEY_IC_AUTHOR);
tileMap.load(tag.getCompound(KEY_TILE_MAP));
stateMachine.load(tag);
}

public void writeDesc(MCDataOutput out) {
out.writeBoolean(isActive);
out.writeString(icName);
out.writeString(icAuthor);
tileMap.writeDesc(out);
stateMachine.writeDesc(out);
}

public void readDesc(MCDataInput in) {
isActive = in.readBoolean();
icName = in.readString();
icAuthor = in.readString();
tileMap.readDesc(in);
stateMachine.readDesc(in);
}
Expand All @@ -124,6 +136,7 @@ private void clear() {
tileMap.removeAll();
stateMachine.reset();
icName = "untitled";
icAuthor = "";
}

public void readBlueprintTagAndActivate(@Nullable CompoundTag tag) {
Expand All @@ -144,6 +157,7 @@ public void writeBlueprintTagAndDeactivate(CompoundTag tag) {
// Save additional metadata for blueprints
tileMap.getInterfaceSpec().saveTo(tag, KEY_IO_SPEC);
tag.putInt(KEY_TILE_COUNT, tileMap.getTileCount());
tag.putString(KEY_DIMENSIONS, tileMap.getDimensionsString());
tag.putBoolean(KEY_IS_BUILT, stateMachine.isSimulating());

// Deactivate editor
Expand Down Expand Up @@ -199,6 +213,15 @@ private void readGeneralStream(MCDataInput in, int frameKey) {
case KEY_SET_IC_NAME:
icName = in.readString();
break;
case KEY_SET_IC_AUTHOR:
icAuthor = in.readString();
break;
case KEY_SET_IC_DIMENSIONS:
tileMap.setBounds(
new TileCoord(in.readInt(), in.readInt(), in.readInt()),
new TileCoord(in.readInt(), in.readInt(), in.readInt())
);
break;
case KEY_TOOL:
toolList.get(in.readUByte()).readPacket(in);
break;
Expand All @@ -207,6 +230,23 @@ private void readGeneralStream(MCDataInput in, int frameKey) {
icName = in.readString();
network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_NAME).writeString(icName);
break;
case KEY_CLIENT_SEND_IC_AUTHOR:
icAuthor = in.readString();
network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_AUTHOR).writeString(icAuthor);
break;
case KEY_CLIENT_SEND_IC_DIMENSIONS:
tileMap.setBounds(
new TileCoord(in.readInt(), in.readInt(), in.readInt()),
new TileCoord(in.readInt(), in.readInt(), in.readInt())
);

TileCoord minBounds = tileMap.getMinBounds();
TileCoord maxBounds = tileMap.getMaxBounds();

network.getBufferedStream(STREAM_ID_GENERAL, KEY_SET_IC_DIMENSIONS)
.writeInt(minBounds.x).writeInt(minBounds.y).writeInt(minBounds.z)
.writeInt(maxBounds.x).writeInt(maxBounds.y).writeInt(maxBounds.z);
break;
default:
LOGGER.error("Unknown key " + frameKey + " in general stream");
}
Expand Down Expand Up @@ -315,6 +355,18 @@ public void sendNewICName(String name) {
// Notifies server to set a new IC name
network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_NAME).writeString(name);
}

public void sendNewICAuthor(String author) {
// Notifies server to set a new IC author
network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_AUTHOR).writeString(author);
}

public void sendNewICDimensions(TileCoord minBounds, TileCoord maxBounds) {
// Notifies server to set new IC dimensions
MCDataOutput out = network.getBufferedStream(STREAM_ID_GENERAL, KEY_CLIENT_SEND_IC_DIMENSIONS);
out.writeInt(minBounds.x).writeInt(minBounds.y).writeInt(minBounds.z);
out.writeInt(maxBounds.x).writeInt(maxBounds.y).writeInt(maxBounds.z);
}
//endregion

//region State Machine callbacks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mrtjp.projectred.fabrication.editor;

import mrtjp.fengine.TileCoord;

public enum WorkbenchDimension {
SIXTEEN(new TileCoord(-8, 0, -8), new TileCoord(7, 0, 7), "16x16"),
TWENTY_FOUR(new TileCoord(-12, 0, -12), new TileCoord(11, 0, 11), "24x24"),
THIRTY_TWO(new TileCoord(-16, 0, -16), new TileCoord(15, 0, 15), "32x32"),
FORTY_EIGHT(new TileCoord(-24, 0, -24), new TileCoord(23, 0, 23), "48x48");

private final TileCoord minBounds;
private final TileCoord maxBounds;
private final String unlocalizedName;

WorkbenchDimension(TileCoord minBounds, TileCoord maxBounds, String unlocalizedName) {
this.minBounds = minBounds;
this.maxBounds = maxBounds;
this.unlocalizedName = unlocalizedName;
}

public TileCoord getMinBounds() {
return minBounds;
}

public TileCoord getMaxBounds() {
return maxBounds;
}

public String getUnlocalizedName() {
return unlocalizedName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mrtjp.fengine.tiles.FETile;
import mrtjp.fengine.tiles.FETileMap;
import mrtjp.projectred.fabrication.editor.ICWorkbenchEditor;
import mrtjp.projectred.fabrication.editor.WorkbenchDimension;
import net.covers1624.quack.collection.FastStream;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand All @@ -16,18 +17,14 @@
import static mrtjp.projectred.fabrication.editor.EditorDataUtils.saveTileCoord;

public class BaseTileMap implements FETileMap {

private static final TileCoord defaultMinBounds = new TileCoord(-8, 0, -8);
private static final TileCoord defaultMaxBounds = new TileCoord(7, 0, 7);

private final Map<TileCoord, BaseTile> tileMap = new HashMap<>();
private final ICWorkbenchEditor editor;

private final Set<IIOConnectionTile> ioTiles = new HashSet<>();
private final Map<Integer, Map<TileCoord, BaseTile>> layerToTileMap = new HashMap<>();

private TileCoord minBounds = defaultMinBounds;
private TileCoord maxBounds = defaultMaxBounds;
private TileCoord minBounds = WorkbenchDimension.SIXTEEN.getMinBounds();
private TileCoord maxBounds = WorkbenchDimension.SIXTEEN.getMaxBounds();

public BaseTileMap(ICWorkbenchEditor editor) {
this.editor = editor;
Expand All @@ -49,6 +46,10 @@ public TileCoord getDimensions() {
return maxBounds.subtract(minBounds).add(1, 1, 1);
}

public String getDimensionsString() {
return String.format("%d x %d x %d", getDimensions().x, getDimensions().y, getDimensions().z);
}

public void setBounds(TileCoord minBounds, TileCoord maxBounds) {
this.minBounds = minBounds;
this.maxBounds = maxBounds;
Expand Down Expand Up @@ -108,8 +109,8 @@ public void removeAll() {
tileMap.clear();
layerToTileMap.clear();

minBounds = defaultMinBounds;
maxBounds = defaultMaxBounds;
minBounds = WorkbenchDimension.SIXTEEN.getMinBounds();
maxBounds = WorkbenchDimension.SIXTEEN.getMaxBounds();
}

private void cacheType(TileCoord coord, BaseTile tile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ICRenderNode extends ViewportRenderNode {
private static final int CAMERA_ANIMATION_TIME_MS = 100;
private static final int FOCUS_ANIMATION_TIME_MS = 400;
private static final int ZOOM_DIST_MAX = 18;
private static final int ZOOM_DIST_MIN = 2;
private static final int ZOOM_DIST_MIN = 1;

private final ICWorkbenchEditor editor;
private final IICRenderNodeEventReceiver eventReceiver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,20 @@ public void drawBack(GuiGraphics graphics, Point mouse, float partialFrame) {
RenderSystem.setShaderTexture(0, TAB_BACKGROUND);
graphics.blit(TAB_BACKGROUND, getFrame().x(), getFrame().y(), 0, 0, getFrame().width(), getFrame().height(), 512, 512);

String icName = editor.getIcName();
String icAuthor = editor.getIcAuthor();

// Blueprint name in top left corner
graphics.drawString(getRoot().getFontRenderer(), editor.getIcName(), getFrame().x() + 8, getFrame().y() + 6, EnumColour.GRAY.argb(), false);
graphics.drawString(
getRoot().getFontRenderer(),
!icAuthor.isEmpty() ?
Component.translatable(UL_BLUEPRINT_TITLE, icName, icAuthor).getString() :
icName,
getFrame().x() + 8,
getFrame().y() + 6,
EnumColour.GRAY.argb(),
false
);

// Progress bar
RenderSystem.setShaderTexture(0, TAB_BACKGROUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import mrtjp.projectred.redui.AbstractGuiNode;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;

import static mrtjp.projectred.fabrication.init.FabricationUnlocal.UL_BLUEPRINT_TITLE;

public class ICWorkbenchEditTab extends AbstractGuiNode {

Expand Down Expand Up @@ -80,8 +83,20 @@ public void drawBack(GuiGraphics graphics, Point mouse, float partialFrame) {

graphics.blit(ICWorkbenchScreen.BACKGROUND, frame.x(), frame.y(), 0, 0, frame.width(), frame.height(), 512, 512);

String icName = editor.getIcName();
String icAuthor = editor.getIcAuthor();

// Blueprint name in top left corner
graphics.drawString(fontRenderer, editor.getIcName(), frame.x() + 8, frame.y() + 6, EnumColour.GRAY.argb(), false);
graphics.drawString(
fontRenderer,
!icAuthor.isEmpty() ?
Component.translatable(UL_BLUEPRINT_TITLE, icName, icAuthor).getString() :
icName,
frame.x() + 8,
frame.y() + 6,
EnumColour.GRAY.argb(),
false
);
}

@Override
Expand Down
Loading