Skip to content

Commit

Permalink
[#133] WIP: Flares now have the correct height even if block is large…
Browse files Browse the repository at this point in the history
…r or smaller than 1 block
  • Loading branch information
Danielxs01 committed Feb 24, 2024
1 parent 3793e8e commit e84ffaf
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public class Flare {
*/
private Map<String, String> groupStates;

/**
* Required if: signal/sign/signalbox/asset contains more than one OBJ. Maps the flare to the specified obj
*/
private String objPath;

/**
* Required if: Only parts of the OBJ are used. Needed to calculate accurate center of model
*/
private String[] objGroups;

private PrecalculatedData precalculatedData;

public Flare(String id, String color, int rotation, int pitch, float offset, boolean alwaysOn, String[] states) {
Expand All @@ -71,6 +81,15 @@ public Flare(String id, String color, int rotation, int pitch, float offset, boo
this.groupStates = groupStates;
}

public Flare(String id, String color, int rotation, int pitch, float offset, boolean alwaysOn) {
this.id = id;
this.color = color;
this.rotation = rotation;
this.pitch = pitch;
this.offset = offset;
this.alwaysOn = alwaysOn;
}

public String getId() {
return id;
}
Expand Down Expand Up @@ -135,6 +154,22 @@ public void setGroupStates(Map<String, String> groupStates) {
this.groupStates = groupStates;
}

public String getObjPath() {
return objPath;
}

public void setObjPath(String objPath) {
this.objPath = objPath;
}

public String[] getObjGroups() {
return objGroups;
}

public void setObjGroups(String[] objGroups) {
this.objGroups = objGroups;
}

public float[] getRenderColor(){
float[] rgb = new float[3];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.flares.Flare;
import net.landofrails.api.contentpacks.v2.parent.ContentPackModel;
import net.landofrails.api.contentpacks.v2.parent.ContentPackReferences;
import net.landofrails.landofsignals.LOSTabs;
Expand All @@ -24,6 +25,7 @@ public class ContentPackSign {
private Boolean writeable;
// objPath : objProperties
private Map<String, ContentPackModel[]> base;
private Flare[] flares;
private ContentPackReferences references;
// metadataId : data
private Map<String, Object> metadata;
Expand All @@ -49,6 +51,14 @@ public void setId(String id) {
this.id = id;
}

public Flare[] getFlares() {
return flares;
}

public void setFlares(Flare[] flares) {
this.flares = flares;
}

public Float getRotationSteps() {
return rotationSteps;
}
Expand Down Expand Up @@ -157,6 +167,8 @@ public void validate(Consumer<String> invalid, ContentPack contentPack) {
Consumer<String> signConsumer = text -> invalid.accept(signModelEntry.getKey() + ": [" + text + "]");
Stream.of(signModelEntry.getValue()).forEach(model -> model.validate(signConsumer, references));
}
}else if(Arrays.stream(flares).anyMatch(flare -> flare.getObjPath() == null)){
invalid.accept("Unable to determine obj path for the flares, add/check obj paths");
}

if (objTextures.isEmpty()) {
Expand Down Expand Up @@ -194,10 +206,25 @@ private void defaultMissing() {
base = new HashMap<>();
}


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

if(flares == null){
flares = new Flare[0];
}

for(Flare flare : flares){
if(flare.getObjPath() == null && base.size() == 1){
String firstEntryKey = base.keySet().iterator().next();
flare.setObjPath(firstEntryKey);
String[] groups = base.get(firstEntryKey)[0].getObj_groups();
if(groups == null)
groups = new String[0];
flare.setObjGroups(groups);
}
}

}

public void setUTF8(boolean isUTF8) {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/net/landofrails/landofsignals/LOSBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ public static void register() {
// Signs: SH2
registerSignContentPack("block_sign_part_gsar_sh2_full_wo_light", "GSAR Schutzsignal SH2 (Full, w/o light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0.5f, 0.5f, 0.5f}, new String[]{"Sign01_SI01", "MetalRodLong_MR02"})}));
registerSignContentPack("block_sign_part_gsar_sh2_top_wo_light", "GSAR Schutzsignal SH2 (Top, w/o light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.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 String[]{"Sign01_SI01", "MetalRod_MR01"})}));
registerSignContentPack("block_sign_part_gsar_sh2_full_w_light", "GSAR Schutzsignal SH2 (Full, with light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0.5f, 0.5f, 0.5f}, new String[]{"Sign01_SI01", "MetalRodLong_MR02", "RedLightOn_RLOn", "RedLightOff_RLOff"})}));
registerSignContentPack("block_sign_part_gsar_sh2_top_w_light", "GSAR Schutzsignal SH2 (Top, with light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.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 String[]{"Sign01_SI01", "MetalRod_MR01", "RedLightOn_RLOn", "RedLightOff_RLOff"})}));
registerSignContentPack("block_sign_part_gsar_sh2_full_w_light", "GSAR Schutzsignal SH2 (Full, with light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f}, new float[]{1f, 1f, 1f}, new float[]{0.5f, 0.5f, 0.5f}, new String[]{"Sign01_SI01", "MetalRodLong_MR02", "RedLightOn_RLOn", "RedLightOff_RLOff"})}), new Flare[]{
new Flare("RedLightOn_RLOn", "255;255;255", 180,0, 0.2f, true)
});
registerSignContentPack("block_sign_part_gsar_sh2_top_w_light", "GSAR Schutzsignal SH2 (Top, with light)", false, Collections.singletonMap("models/block/landofsignals/signs/gsar/sh2/signalsh2.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 String[]{"Sign01_SI01", "MetalRod_MR01", "RedLightOn_RLOn", "RedLightOff_RLOff"})}), new Flare[]{
new Flare("RedLightOn_RLOn", "255;255;255", 180,0, 0.426f, true)
});

// Signs: Hecto Signs
registerSignContentPack("block_sign_part_gsar_hecto_sign", "GSAR Hectosignal", true, models("models/block/landofsignals/signs/gsar/hectosign/hectosign.obj", new ContentPackModel[]{new ContentPackModel(new float[]{0.5f, 0f, 0.5f}, new float[]{0.5f, 0f, 0.5f}, new float[]{1f, 1f, 1f})}, blockSignPartMetalRod.getKey(), blockSignPartMetalRod.getValue()));
Expand Down Expand Up @@ -512,11 +516,16 @@ private static void registerSignalContentPack(ContentPackSignalPart contentPackS
}

private static void registerSignContentPack(String id, String name, boolean writable, Map<String, ContentPackModel[]> models) {
registerSignContentPack(id, name, writable, models, null);
}

private static void registerSignContentPack(String id, String name, boolean writable, Map<String, ContentPackModel[]> models, Flare[] flares) {
ContentPackSign contentPackSign = new ContentPackSign();
contentPackSign.setId(id);
contentPackSign.setName(name);
contentPackSign.setWriteable(writable);
contentPackSign.setBase(models);
contentPackSign.setFlares(flares);
contentPackSign.setUTF8(true);

contentPackSign.validate(missing -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import net.landofrails.api.contentpacks.GenericContentPack;
import net.landofrails.api.contentpacks.v2.complexsignal.ContentPackSignalGroup;
import net.landofrails.api.contentpacks.v2.parent.ContentPackModel;
import net.landofrails.api.contentpacks.v2.sign.ContentPackSign;
import net.landofrails.api.contentpacks.v2.signal.ContentPackSignal;
import net.landofrails.landofsignals.LOSBlocks;
import net.landofrails.landofsignals.LandOfSignals;
import net.landofrails.landofsignals.configs.LandOfSignalsConfig;
import net.landofrails.landofsignals.render.block.*;
import net.landofrails.landofsignals.render.item.*;
import net.landofrails.landofsignals.utils.FlareUtils;
import net.landofrails.landofsignals.utils.Static;
import net.landofrails.stellwand.utils.exceptions.ContentPackException;

Expand Down Expand Up @@ -171,7 +173,7 @@ public static void preloadModels() {
// Cache blocks
try {
TileSignalPartRender.cache().put(objPath, new OBJModel(new Identifier(LandOfSignals.MODID, objPath), 0, Arrays.asList(states)));
TileSignalPartRender.cacheFlares(id, signal);
FlareUtils.cacheFlares(id, signal);
} catch (Exception e) {
String errmsg = "Couldn't preload block with id \"%s\" (objPath: %s). Cause:";
throw new ContentPackException(String.format(errmsg, id, objPath), e);
Expand Down Expand Up @@ -235,7 +237,9 @@ public static void preloadModels() {
progressBar = Progress.push("Sign", LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().size());
for (String id : LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().keySet()) {
ModCore.info("Preloading sign %s", id);
progressBar.step(LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(id).getName());

final ContentPackSign sign = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(id);
progressBar.step(sign.getName());

final Map<String, ContentPackModel[]> base = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(id).getBase();

Expand All @@ -249,6 +253,7 @@ public static void preloadModels() {
// Cache blocks
try {
TileSignPartRender.checkCache(id, base);
FlareUtils.cacheFlares(id, sign);
} catch (Exception e) {
throw new ContentPackException(String.format(GENERIC_BLOCK_ERRMSG, id), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.landofrails.landofsignals.LOSBlocks;
import net.landofrails.landofsignals.LandOfSignals;
import net.landofrails.landofsignals.tile.TileSignPart;
import net.landofrails.landofsignals.utils.FlareUtils;
import net.landofrails.landofsignals.utils.Static;

import java.util.*;
Expand Down Expand Up @@ -72,21 +73,21 @@ private static void renderStuff(TileSignPart tsp, RenderState state) {

String id = tsp.getId();

if (id == null) {
id = Static.MISSING;
}
if (id == null) id = Static.MISSING;
ContentPackSign contentPackSign = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(id);
if(contentPackSign == null) contentPackSign = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(Static.MISSING);

renderBase(id, tsp, state);
renderBase(id, contentPackSign, tsp, state.clone());

if(contentPackSign.getFlares().length > 0)
FlareUtils.renderFlares(id, contentPackSign, tsp, state.clone());

}

private static void renderBase(String blockId, TileSignPart tile, RenderState state) {
private static void renderBase(String blockId, ContentPackSign contentPackSign, TileSignPart tile, RenderState state) {

Vec3d offset = tile.getOffset();
Vec3d customScaling = tile.getScaling();
ContentPackSign contentPackSign = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(blockId);

if(contentPackSign == null) contentPackSign = LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(Static.MISSING);

checkCache(blockId, LOSBlocks.BLOCK_SIGN_PART.getContentpackSigns().get(blockId).getBase());
for (Map.Entry<String, ContentPackModel[]> baseModels : contentPackSign.getBase().entrySet()) {
Expand Down Expand Up @@ -140,4 +141,8 @@ private static void renderBase(String blockId, TileSignPart tile, RenderState st
}
}

public static Map<String, OBJModel> cache(){
return cache;
}

}
Loading

0 comments on commit e84ffaf

Please sign in to comment.