Skip to content

Commit

Permalink
Merge pull request #243 from MrTroble/feats/1.18
Browse files Browse the repository at this point in the history
Feats/1.18
  • Loading branch information
Uhutown authored Oct 23, 2024
2 parents 057faab + 533b373 commit 308577f
Show file tree
Hide file tree
Showing 65 changed files with 2,261 additions and 727 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
if: endswith(github.ref_name, 'master') && github.ref_protected && github.ref_type == 'branch'
runs-on: ubuntu-latest
env:
APPVEYOR_BUILD_VERSION: '3.6.1'
APPVEYOR_BUILD_VERSION: '3.6.2'
CURSETOKEN: ${{ secrets.CURSETOKEN }}
steps:
- uses: actions/checkout@v3
Expand Down
31 changes: 31 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## [1.18.2 - 3.6.2]
* feat: added train length signs
* feat: added trainnumber element
* feat: added configurable shunting pw color
* feat: added system to select pathway type when several are possible
* fix: problems with 'dead signal'
* fix: end is not a valid end point
* fix: disappearing signals in signalbox
* fix: issue in signal configs
* fix: skipping same signals
* fix: issue with names not shown every time
* fix: issue with trainnumbers
* fix: problem with shunting and normal pathway
* fix: UI line and background coloring
* fix: issue with delay intersignalbox pathway
* fix: issue with wrong feedback signal
* fix: intersignalbox can be added to saver
* fix: delay with shunting pathway
* fix: wn signals
* fix: item dropping
* fix: sh statuslight wrong lamp
* fix: issues with intersignalbox pathway
* fix: not updating signals in signalbox
* ref: remove CUSTOMNAME from saving into files
* ref: better signalbox UI
* ref: better error handling
* ref: better code performance
* ref: added arrow to possible shunting pathway end
* ref: better signalbox NBT saving
* ref: better signalbox loading system for names and signals

## [1.18.2 - 3.6.1]

* fix: issue with InterSignalBoxPathway
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/troblecodings/signals/blocks/BasicBlock.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package com.troblecodings.signals.blocks;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import com.troblecodings.signals.core.TileEntitySupplierWrapper;

import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;

public class BasicBlock extends Block implements EntityBlock {

private static final Map<TileEntitySupplierWrapper, String> BLOCK_NAMES = new HashMap<>();
private static final Map<TileEntitySupplierWrapper, Set<BasicBlock>> BLOCK_SUPPLIER = new HashMap<>();
public static final Map<TileEntitySupplierWrapper, BlockEntityType<?>> BLOCK_ENTITYS = new HashMap<>();
private static final Map<TileEntitySupplierWrapper, Set<BasicBlock>> BLOCK_SUPPLIER =
new HashMap<>();
public static final Map<TileEntitySupplierWrapper, BlockEntityType<?>> BLOCK_ENTITYS =
new HashMap<>();

public BasicBlock(final Properties properties) {
super(properties);
Expand Down Expand Up @@ -63,4 +69,11 @@ public static void prepare() {
public BlockEntity newBlockEntity(final BlockPos pos, final BlockState state) {
return getSupplierWrapper().map(type -> type.create(pos, state)).orElse(null);
}

@Override
public List<ItemStack> getDrops(final BlockState state, final LootContext.Builder builder) {
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(new ItemStack(this.asBlock().asItem()));
return drops;
}
}
18 changes: 14 additions & 4 deletions src/main/java/com/troblecodings/signals/config/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static class Client {
public final ConfigValue<Integer> signalboxUsedColor;
public final ConfigValue<Integer> signalboxPreparedColor;
public final ConfigValue<Integer> signalboxTrainNumberColor;
public final ConfigValue<Integer> signalboxShuntingColor;
public final ConfigValue<Integer> signalboxTrainnumberBackgroundColor;

public Client(final ForgeConfigSpec.Builder builder) {
String desc;
Expand All @@ -69,9 +71,17 @@ public Client(final ForgeConfigSpec.Builder builder) {
signalboxPreparedColor = builder.comment(desc).define("Signalbox prepared color",
0xffff00);

desc = "Change the color of the TrainNumber in the UI. Default: -1";
signalboxTrainNumberColor = builder.comment(desc).define("Signalbox TrainNumber color",
0xFFFFFFFF);
desc = "Change the color of a selected shunting path. Default: -16711936";
signalboxShuntingColor = builder.comment(desc).define("Signalbox shunting color",
0xFF00FF00);

desc = "Change the color of trainnumber in the signalbox. Default: -65536";
signalboxTrainNumberColor = builder.comment(desc)
.define("Signalbox trainnumber text color", 0xFFFF0000);

desc = "Change the background color of trainnumber in the signalbox. Default: -11534336";
signalboxTrainnumberBackgroundColor = builder.comment(desc)
.define("Signalbox trainnumber background color", 0xFF500000);

desc = "Change the color of a default text. Default: -16777216";
GuiConfigHandler.basicTextColor = builder.comment(desc).define("Basic text color",
Expand All @@ -91,4 +101,4 @@ public Client(final ForgeConfigSpec.Builder builder) {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,97 +53,105 @@ public static void loadChangeConfigs() {
private static void loadConfigForPair(final String fileName, final String currentSignal,
final String nextSignal, final Map<String, String> savedPredicates,
final Map<String, List<String>> values) {
final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase());
final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase());
if (start == null || end == null) {
OpenSignalsMain.getLogger()
.warn("The signal '" + nextSignal + "' or the signal '" + nextSignal
+ "' doen't exists! " + "This config with filename '" + fileName
+ "' will be skiped!");
return;
}
final Map.Entry<Signal, Signal> pair = Maps.immutableEntry(start, end);
if (CHANGECONFIGS.containsKey(pair)) {
throw new LogicalParserException(
"A signalconfig with the signals [" + start.getSignalTypeName() + ", "
+ end.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register a chaneconfig for the same signalpair!");
}
final FunctionParsingInfo startInfo = new FunctionParsingInfo(start);
final FunctionParsingInfo endInfo = new FunctionParsingInfo(
LogicParser.UNIVERSAL_TRANSLATION_TABLE, end);
final List<ConfigProperty> properties = new ArrayList<>();

for (final Map.Entry<String, List<String>> entry : values.entrySet()) {

String valueToParse = entry.getKey().toLowerCase();
Predicate<Map<Class<?>, Object>> predicate = t -> true;

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
final char[] chars = entry.getKey().toCharArray();
String names = "";
boolean readKey = false;
final StringBuilder builder = new StringBuilder();
String mapKey = "";
for (final char letter : chars) {

final String current = builder.append(letter).toString();
final boolean isOpenBracket = current.equals("(");
final boolean isCloseBracket = current.equals(")");
builder.setLength(0);

if (readKey) {
try {
if (isCloseBracket) {
valueToParse = valueToParse.replace("map(" + mapKey + ")",
"(" + savedPredicates.get(mapKey).toLowerCase() + ")");
names = "";
mapKey = "";
readKey = false;
try {

final Signal start = Signal.SIGNALS.get(currentSignal.toLowerCase());
final Signal end = Signal.SIGNALS.get(nextSignal.toLowerCase());
if (start == null || end == null) {
OpenSignalsMain.getLogger()
.warn("The signal '" + nextSignal + "' or the signal '" + nextSignal
+ "' doen't exists! " + "This config with filename '" + fileName
+ "' will be skiped!");
return;
}
final Map.Entry<Signal, Signal> pair = Maps.immutableEntry(start, end);
if (CHANGECONFIGS.containsKey(pair)) {
throw new LogicalParserException(
"A signalconfig with the signals [" + start.getSignalTypeName() + ", "
+ end.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register a chaneconfig for the same signalpair!");
}
final FunctionParsingInfo startInfo = new FunctionParsingInfo(start);
final FunctionParsingInfo endInfo = new FunctionParsingInfo(
LogicParser.UNIVERSAL_TRANSLATION_TABLE, end);
final List<ConfigProperty> properties = new ArrayList<>();

for (final Map.Entry<String, List<String>> entry : values.entrySet()) {

String valueToParse = entry.getKey().toLowerCase();
Predicate<Map<Class<?>, Object>> predicate = t -> true;

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
final char[] chars = entry.getKey().toCharArray();
String names = "";
boolean readKey = false;
final StringBuilder builder = new StringBuilder();
String mapKey = "";
for (final char letter : chars) {

final String current = builder.append(letter).toString();
final boolean isOpenBracket = current.equals("(");
final boolean isCloseBracket = current.equals(")");
builder.setLength(0);

if (readKey) {
try {
if (isCloseBracket) {
valueToParse = valueToParse.replace("map(" + mapKey + ")",
"(" + savedPredicates.get(mapKey).toLowerCase() + ")");
names = "";
mapKey = "";
readKey = false;
continue;
}
mapKey += current;
continue;
} catch (final Exception e) {
OpenSignalsMain.exitMinecraftWithMessage(
"Something went wrong with the predicate saver in "
+ fileName + "! Did you used it correctly?");
}
mapKey += current;
}
if (current.equals("(") && names.equals("map")) {
readKey = true;
mapKey = "";
continue;
} catch (final Exception e) {
OpenSignalsMain.exitMinecraftWithMessage(
"Something went wrong with the predicate saver in " + fileName
+ "! Did you used it correctly?");
}
final boolean isBracket = isCloseBracket || isOpenBracket;
if (Character.isWhitespace(letter) || current.equals("!") || isBracket) {
names = "";
mapKey = "";
continue;
}
names += current;
}
if (current.equals("(") && names.equals("map")) {
readKey = true;
mapKey = "";
continue;
}
final boolean isBracket = isCloseBracket || isOpenBracket;
if (Character.isWhitespace(letter) || current.equals("!") || isBracket) {
names = "";
mapKey = "";
continue;
}
names += current;
}
}

if (valueToParse != null && !valueToParse.isEmpty()
&& !valueToParse.equalsIgnoreCase("true")) {
predicate = LogicParser.predicate(valueToParse, endInfo);
}
if (valueToParse != null && !valueToParse.isEmpty()
&& !valueToParse.equalsIgnoreCase("true")) {
predicate = LogicParser.predicate(valueToParse, endInfo);
}

final Map<SEProperty, String> propertiesToSet = new HashMap<>();
final Map<SEProperty, String> propertiesToSet = new HashMap<>();

for (final String value : entry.getValue()) {
for (final String value : entry.getValue()) {

final String[] valuetoChange = value.split("\\.");
final SEProperty property = (SEProperty) startInfo.getProperty(valuetoChange[0]);
propertiesToSet.put(property, valuetoChange[1]);
}
final String[] valuetoChange = value.split("\\.");
final SEProperty property = (SEProperty) startInfo
.getProperty(valuetoChange[0]);
propertiesToSet.put(property, valuetoChange[1]);
}

properties.add(new ConfigProperty(predicate, propertiesToSet));
properties.add(new ConfigProperty(predicate, propertiesToSet));

}
CHANGECONFIGS.put(pair, properties);
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("There was a problem loading the ChangeConfig ["
+ fileName + "]! Please check the file!");
e.printStackTrace();
}
CHANGECONFIGS.put(pair, properties);
}

private static class ChangeConfigParserV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,45 @@ public static void loadOneSignalNonPredicateConfig(final Map<Signal, List<Config
final OneSignalNonPredicateConfigParserV2 parser = GSON.fromJson(files.getValue(),
OneSignalNonPredicateConfigParserV2.class);
for (final String currentSignal : parser.currentSignals) {
loadConfig(map, files.getKey(), currentSignal, parser.values);
loadConfig(map, files.getKey(), currentSignal, parser.values, path);
}
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("Please update your config [" + files.getKey()
+ "] located in [" + path + "]!");
final OneSignalNonPredicateConfigParser parser = GSON.fromJson(files.getValue(),
OneSignalNonPredicateConfigParser.class);
loadConfig(map, files.getKey(), parser.currentSignal, parser.values);
loadConfig(map, files.getKey(), parser.currentSignal, parser.values, path);
}

}

private static void loadConfig(final Map<Signal, List<ConfigProperty>> map,
final String fileName, final String currentSignal, final List<String> values) {
final Signal signal = checkSignal(currentSignal, fileName);
if (signal == null)
return;

if (map.containsKey(signal)) {
throw new LogicalParserException("A signalconfig with the signals ["
+ signal.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register the same signalconfig!");
}
final String fileName, final String currentSignal, final List<String> values,
final String path) {
try {
final Signal signal = checkSignal(currentSignal, fileName);
if (signal == null)
return;

if (map.containsKey(signal)) {
throw new LogicalParserException("A signalconfig with the signals ["
+ signal.getSignalTypeName() + "] does alredy exists! '" + fileName
+ "' tried to register the same signalconfig!");
}

final FunctionParsingInfo info = new FunctionParsingInfo(signal);
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : values) {
final String[] value = property.split("\\.");
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
final FunctionParsingInfo info = new FunctionParsingInfo(signal);
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : values) {
final String[] value = property.split("\\.");
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
}
map.put(signal, propertes);
} catch (final Exception e) {
OpenSignalsMain.getLogger().error("There was a problem loading the config [" + fileName
+ "] located in [" + path + "]! Please check the file!");
e.printStackTrace();
}
map.put(signal, propertes);
}

private static Signal checkSignal(final String signalName, final String filename) {
Expand Down
Loading

0 comments on commit 308577f

Please sign in to comment.