Skip to content

Commit

Permalink
Merge pull request #134 from LandOfRails/develop
Browse files Browse the repository at this point in the history
Sync develop -> main
  • Loading branch information
Danielxs01 authored Dec 20, 2023
2 parents 1a4b897 + cdc8355 commit 187e810
Show file tree
Hide file tree
Showing 27 changed files with 2,285 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ jobs:
id: getsuffix
run: echo "suffix=$(cat SUFFIX)" >> $GITHUB_OUTPUT
- name: Rename with suffix
run: mv -n build/libs/LandOfSignals-${{matrix.branch}}-${{ steps.getversion.outputs.version }}.jar build/libs/LandOfSignals-${{matrix.branch}}-${{ steps.getversion.outputs.version }}${{ steps.getsuffix.outputs.suffix }}.jar
run: |
ls ./build/libs/
mv -n build/libs/LandOfSignals-${{matrix.branch}}-${{ steps.getversion.outputs.version }}.jar build/libs/LandOfSignals-${{matrix.branch}}-${{ steps.getversion.outputs.version }}${{ steps.getsuffix.outputs.suffix }}.jar
- uses: actions/upload-artifact@v3
with:
name: LandOfSignals ${{matrix.branch}}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#### Release 1.2.0

* Added [#125] : Levers w/o animation (extendable via contentpacks)


* Fixed [#127] : Magnifyingglass crashes server

#### Release 1.1.0

Fixed #109 : ContentPackComplexSignal can now be added to a contentpackset
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.2.0
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
apply plugin: 'cam72cam.universalmodcore'
apply plugin: 'maven'

String version = '1.1.0'
String version = '1.2.0
universalmodcore {
modPackage = 'net.landofrails.landofsignals'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum EntryType {
BLOCKCOMPLEXSIGNAL(() -> LOSItems.ITEM_COMPLEX_SIGNAL),
BLOCKSIGN(() -> LOSItems.ITEM_SIGN_PART),
BLOCKSIGNALBOX(() -> LOSItems.ITEM_SIGNAL_BOX),
BLOCKDECO(() -> LOSItems.ITEM_DECO);
BLOCKDECO(() -> LOSItems.ITEM_DECO),
BLOCKLEVER(() -> LOSItems.ITEM_CUSTOM_LEVER);
// @formatter:on

private final Supplier<CustomItem> itemSupplier;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
package net.landofrails.api.contentpacks.v2.lever;

import com.google.gson.Gson;
import net.landofrails.api.contentpacks.v2.ContentPack;
import net.landofrails.api.contentpacks.v2.ContentPackException;
import net.landofrails.api.contentpacks.v2.parent.ContentPackModel;
import net.landofrails.api.contentpacks.v2.parent.ContentPackReferences;
import net.landofrails.landofsignals.LOSTabs;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class ContentPackLever {
private static final Gson GSON = new Gson();

private String name;
private String id;
private Float rotationSteps;
private String creativeTab;
private Boolean writeable;
// objPath : objProperties
private Map<String, ContentPackModel[]> active;
// objPath : objProperties
private Map<String, ContentPackModel[]> inactive;
private ContentPackReferences references;
// metadataId : data
private Map<String, Object> metadata;

// Processed data
private Map<String, Set<String>> objTextures;
private String uniqueId;
private Boolean isUTF8;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Float getRotationSteps() {
return rotationSteps;
}

public void setRotationSteps(Float rotationSteps) {
this.rotationSteps = rotationSteps;
}

public String getCreativeTab() {
return creativeTab;
}

public void setCreativeTab(String creativeTab) {
this.creativeTab = creativeTab;
}

public boolean isWriteable() {
return Boolean.TRUE.equals(writeable);
}

public void setWriteable(Boolean writeable) {
this.writeable = writeable;
}

public Map<String, ContentPackModel[]> getActive() {
return active;
}

public void setActive(Map<String, ContentPackModel[]> active) {
this.active = active;
}

public Map<String, ContentPackModel[]> getInactive() {
return inactive;
}

public void setInactive(Map<String, ContentPackModel[]> inactive) {
this.inactive = inactive;
}

public ContentPackReferences getReferences() {
return references;
}

public void setReferences(ContentPackReferences references) {
this.references = references;
}

public Map<String, Object> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, Object> metadata) {
this.metadata = metadata;
}

public Map<String, Set<String>> getObjTextures() {
return objTextures;
}

public void setObjTextures(Map<String, Set<String>> objTextures) {
this.objTextures = objTextures;
}

public String getUniqueId() {
return uniqueId;
}

public static ContentPackLever fromJson(InputStream inputStream) {
StringBuilder s = new StringBuilder();
byte[] buffer = new byte[1024];
int read;

try {
while ((read = inputStream.read(buffer, 0, 1024)) >= 0) {
s.append(new String(buffer, 0, read));
}
} catch (IOException e) {
throw new ContentPackException("Cant read ContentPackSign: " + e.getMessage());
}

String json = s.toString();
return GSON.fromJson(json, ContentPackLever.class);
}

public void validate(Consumer<String> invalid, ContentPack contentPack) {

if (references == null) {
references = new ContentPackReferences();
}
Consumer<String> referencesConsumer = text -> invalid.accept("references" + ": [" + text + "]");
references.validate(referencesConsumer);

defaultMissing();

StringJoiner joiner = new StringJoiner(",", "[", "]");
if (name == null)
joiner.add("name");
if (id == null)
joiner.add("id");
if (isUTF8 == null)
joiner.add("isUTF8");
if (joiner.length() > 2) {
invalid.accept(joiner.toString());
} else if (!active.isEmpty() && !inactive.isEmpty()) {
if (!"MISSING".equalsIgnoreCase(id)) {
uniqueId = contentPack.getId() + ":" + id;
} else {
uniqueId = id;
}

for (Map.Entry<String, ContentPackModel[]> activeModelEntry : active.entrySet()) {

Consumer<String> activeConsumer = text -> invalid.accept(activeModelEntry.getKey() + ": [" + text + "]");
Stream.of(activeModelEntry.getValue()).forEach(model -> model.validate(activeConsumer, references));
}

for (Map.Entry<String, ContentPackModel[]> inactiveModelEntry : inactive.entrySet()) {

Consumer<String> inactiveConsumer = text -> invalid.accept(inactiveModelEntry.getKey() + ": [" + text + "]");
Stream.of(inactiveModelEntry.getValue()).forEach(model -> model.validate(inactiveConsumer, references));
}
}

if (objTextures.isEmpty()) {
for (Map.Entry<String, ContentPackModel[]> modelEntry : active.entrySet()) {
for (ContentPackModel model : modelEntry.getValue()) {
String objPath = modelEntry.getKey();
objTextures.putIfAbsent(objPath, new HashSet<>());
objTextures.computeIfPresent(objPath, (key, value) -> {
value.addAll(Arrays.asList(model.getTextures()));
return value;
});
}
}

for (Map.Entry<String, ContentPackModel[]> modelEntry : inactive.entrySet()) {
for (ContentPackModel model : modelEntry.getValue()) {
String objPath = modelEntry.getKey();
objTextures.putIfAbsent(objPath, new HashSet<>());
objTextures.computeIfPresent(objPath, (key, value) -> {
value.addAll(Arrays.asList(model.getTextures()));
return value;
});
}
}
}

}

private void defaultMissing() {

if (rotationSteps == null) {
rotationSteps = 10f;
} else {
rotationSteps = Math.min(Math.max(10, rotationSteps), 90);
}

if (creativeTab == null) {
creativeTab = LOSTabs.ASSETS_TAB;
}

if (metadata == null) {
metadata = new HashMap<>();
}

if (active == null) {
active = new HashMap<>();
}

if (inactive == null) {
inactive = new HashMap<>();
}

if (objTextures == null) {
objTextures = new HashMap<>();
}
}

public void setUTF8(boolean isUTF8) {
this.isUTF8 = isUTF8;
}

public boolean isUTF8() {
return isUTF8;
}
}
33 changes: 33 additions & 0 deletions src/main/java/net/landofrails/landofsignals/LOSBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.landofrails.api.contentpacks.v2.ContentPackException;
import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackComplexSignal;
import net.landofrails.api.contentpacks.v2.deco.ContentPackDeco;
import net.landofrails.api.contentpacks.v2.lever.ContentPackLever;
import net.landofrails.api.contentpacks.v2.parent.ContentPackModel;
import net.landofrails.api.contentpacks.v2.sign.ContentPackSign;
import net.landofrails.api.contentpacks.v2.signalbox.ContentPackSignalbox;
Expand All @@ -26,6 +27,7 @@ private LOSBlocks() {
public static final BlockTicketMachineSBB BLOCK_TICKET_MACHINE_SBB = new BlockTicketMachineSBB(LandOfSignals.MODID, "BlockTicketMachineSBB");
public static final BlockSignalBox BLOCK_SIGNAL_BOX = new BlockSignalBox(LandOfSignals.MODID, "BlockSignalBox");
public static final BlockDeco BLOCK_DECO = new BlockDeco(LandOfSignals.MODID, "BlockDeco");
public static final BlockCustomLever BLOCK_CUSTOM_LEVER = new BlockCustomLever(LandOfSignals.MODID, "BlockCustomLever");

// Contentpack
private static final ContentPack CONTENTPACK = new ContentPack("LandOfSignals", "LandOfSignals", "1.0", "2", null, null);
Expand Down Expand Up @@ -407,6 +409,22 @@ public static void register() {
registerDecoContentPackStellwand("deco_trackdiag_up_left", "Diagonal track (up - left)", models("models/block/stellwand/blockfiller/trackdiag/ul/trackdiag.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0.5f, 0.5f}, new float[]{0.5f, 0.5f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0f, 180f, 0f})}));
registerDecoContentPackStellwand("deco_trackdiag_up_right", "Diagonal track (up - right)", models("models/block/stellwand/blockfiller/trackdiag/ur/trackdiag.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0.5f, 0.5f}, new float[]{0.5f, 0.5f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0f, 180f, 0f})}));

// Lever

registerLeverContentPack(
Static.MISSING,
Static.MISSING_NAME,
models(Static.MISSING_OBJ, new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0.5f, 0.5f}, new float[]{0.5f, 0.5f, 0.5f}, new float[]{1f, 1f, 1f})}),
models(Static.MISSING_OBJ, new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0.5f, 0.5f}, new float[]{0.5f, 0.5f, 0.5f}, new float[]{1f, 1f, 1f})})
);

registerLeverContentPack(
"switchstand_jake",
"Switch stand by Jake Steampson",
models("models/block/landofsignals/switchstand_jake/switch_on.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0f, 180f, 0f})}),
models("models/block/landofsignals/switchstand_jake/switch_off.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0f, 180f, 0f})})
);

}

private static void registerStreckenblock() {
Expand Down Expand Up @@ -487,6 +505,21 @@ private static void registerDecoContentPack(String id, String name, Map<String,
BLOCK_DECO.add(contentPackDeco);
}

private static void registerLeverContentPack(String id, String name, Map<String, ContentPackModel[]> active, Map<String, ContentPackModel[]> inactive) {
ContentPackLever contentPackLever = new ContentPackLever();
contentPackLever.setId(id);
contentPackLever.setName(name);
contentPackLever.setActive(active);
contentPackLever.setInactive(inactive);
contentPackLever.setUTF8(true);

contentPackLever.validate(missing -> {
throw new ContentPackException(String.format(Static.MISSING_ATTRIBUTES, missing));
}, CONTENTPACK);

BLOCK_CUSTOM_LEVER.add(contentPackLever);
}

private static void registerDecoContentPackStellwand(String id, String name, Map<String, ContentPackModel[]> models) {
ContentPackDeco contentPackDeco = new ContentPackDeco();
contentPackDeco.setId(id);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/landofrails/landofsignals/LOSItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private LOSItems() {
public static final ItemSignPart ITEM_SIGN_PART = new ItemSignPart(LandOfSignals.MODID, "item_sign");
public static final ItemSignalBox ITEM_SIGNAL_BOX = new ItemSignalBox(LandOfSignals.MODID, "item_signal_box");
public static final ItemDeco ITEM_DECO = new ItemDeco(LandOfSignals.MODID, "item_deco");
public static final ItemCustomLever ITEM_CUSTOM_LEVER = new ItemCustomLever(LandOfSignals.MODID, "item_custom_lever");

public static void register() {
// loads static classes and ctrs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LandOfSignals extends ModCore.Mod {
public static final String MODID = "landofsignals";
// Current version
@SuppressWarnings("unused")
public static final String VERSION = "1.1.0";
public static final String VERSION = "1.2.0";

@Override
public String modID() {
Expand Down Expand Up @@ -89,6 +89,7 @@ public void clientEvent(final ModEvent event) {
BlockRender.register(LOSBlocks.BLOCK_SIGNAL_LEVER, TileSignalLeverRender::render, TileSignalLever.class);
BlockRender.register(LOSBlocks.BLOCK_SIGNAL_BOX, TileSignalBoxRender::render, TileSignalBox.class);
BlockRender.register(LOSBlocks.BLOCK_DECO, TileDecoRender::render, TileDeco.class);
BlockRender.register(LOSBlocks.BLOCK_CUSTOM_LEVER, TileCustomLeverRender::render, TileCustomLever.class);

// Items
ItemRender.register(LOSItems.ITEM_SIGNAL_LEVER, ObjItemRender.getModelFor(new Identifier(LandOfSignals.MODID, "models/block/landofsignals/signalslever/signalslever.obj"), new Vec3d(0.5, 0.6, 0.5), 1));
Expand All @@ -109,6 +110,7 @@ public void clientEvent(final ModEvent event) {
ItemRender.register(LOSItems.ITEM_SIGN_PART, new ItemSignPartRender());
ItemRender.register(LOSItems.ITEM_SIGNAL_BOX, new ItemSignalBoxRender());
ItemRender.register(LOSItems.ITEM_DECO, new ItemDecoRender());
ItemRender.register(LOSItems.ITEM_CUSTOM_LEVER, new ItemCustomLeverRender());

// Deprecated: Only for compatability - Removes warnings
BlockRender.register(LOSBlocks.BLOCK_SIGNAL_SO_12, TileMissingRender::render, TileSignalSO12.class);
Expand Down
Loading

0 comments on commit 187e810

Please sign in to comment.