Skip to content

Commit

Permalink
feat: 1.18 feats
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Sep 20, 2023
1 parent 1011f6f commit e4a4c4d
Show file tree
Hide file tree
Showing 55 changed files with 1,424 additions and 653 deletions.
4 changes: 0 additions & 4 deletions src/main/java/com/troblecodings/signals/SEProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ public boolean testMap(final Map<SEProperty, String> t) {
return this.deps.test(t);
}

public static SEProperty cst(final Object iup) {
return (SEProperty) iup;
}

public JsonEnum getParent() {
return parent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class GhostBlock extends BasicBlock {
public GhostBlock() {
super(Properties.of(Material.GLASS).noOcclusion().lightLevel(u -> 1));
registerDefaultState(defaultBlockState());
// TODO Config Light Level
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/troblecodings/signals/blocks/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public VoxelShape getShape(final BlockState state, final IBlockReader getter,
final BlockPos pos, final ISelectionContext context) {
return BOUNDING_BOX;
}
}
}
83 changes: 41 additions & 42 deletions src/main/java/com/troblecodings/signals/blocks/Signal.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import com.troblecodings.signals.init.OSItems;
import com.troblecodings.signals.items.Placementtool;
import com.troblecodings.signals.parser.ValuePack;
import com.troblecodings.signals.properties.BooleanProperty;
import com.troblecodings.signals.properties.FloatProperty;
import com.troblecodings.signals.properties.HeightProperty;
import com.troblecodings.signals.properties.PredicatedPropertyBase.PredicateProperty;
import com.troblecodings.signals.properties.SoundProperty;
import com.troblecodings.signals.tileentitys.SignalTileEntity;

Expand Down Expand Up @@ -78,7 +76,6 @@ public class Signal extends BasicBlock {
private final int id;
private List<SEProperty> signalProperties;
private final Map<SEProperty, Integer> signalPropertiesToInt = new HashMap<>();
private SEProperty powerProperty = null;

public Signal(final SignalProperties prop) {
super(Properties.of(Material.STONE).noOcclusion().lightLevel(u -> 1));
Expand All @@ -91,6 +88,7 @@ public Signal(final SignalProperties prop) {
final SEProperty property = signalProperties.get(i);
signalPropertiesToInt.put(property, i);
}
// TODO Light Level
}

public int getID() {
Expand Down Expand Up @@ -185,9 +183,9 @@ public void destroy(final IWorld worldIn, final BlockPos pos, final BlockState s

@SuppressWarnings("unchecked")
public int getHeight(final Map<SEProperty, String> map) {
for (final HeightProperty property : this.prop.signalHeights) {
if (property.predicate.test(map))
return property.height;
for (final PredicateProperty<Integer> property : this.prop.signalHeights) {
if (property.test(map))
return property.state;
}
return this.prop.defaultHeight;
}
Expand Down Expand Up @@ -239,9 +237,9 @@ public void renderScaleOverlay(final RenderOverlayInfo info, final float renderH
if (customNameState == null || customNameState.equalsIgnoreCase("FALSE"))
return;
float customRenderHeight = renderHeight;
for (final FloatProperty property : this.prop.customRenderHeights) {
for (final PredicateProperty<Float> property : this.prop.customRenderHeights) {
if (property.predicate.test(map)) {
customRenderHeight = property.height;
customRenderHeight = property.state;
}
if (customRenderHeight == -1)
return;
Expand All @@ -253,9 +251,9 @@ public void renderScaleOverlay(final RenderOverlayInfo info, final float renderH
return;
}
boolean doubleSidedText = false;
for (final BooleanProperty boolProp : this.prop.doubleSidedText) {
for (final PredicateProperty<Boolean> boolProp : this.prop.doubleSidedText) {
if (boolProp.predicate.test(map)) {
doubleSidedText = boolProp.doubleSided;
doubleSidedText = boolProp.state;
}
}
final SignalAngel face = state.getValue(Signal.ANGEL);
Expand Down Expand Up @@ -300,9 +298,9 @@ public void renderOverlay(final RenderOverlayInfo info, final float renderHeight
final String customNameState = map.get(CUSTOMNAME);
if (customNameState == null || customNameState.equalsIgnoreCase("FALSE"))
return;
for (final FloatProperty property : this.prop.customRenderHeights) {
for (final PredicateProperty<Float> property : this.prop.customRenderHeights) {
if (property.predicate.test(map)) {
customRenderHeight = property.height;
customRenderHeight = property.state;
}
}
if (customRenderHeight == -1)
Expand All @@ -314,9 +312,9 @@ public void renderOverlay(final RenderOverlayInfo info, final float renderHeight
return;
}
boolean doubleSidedText = false;
for (final BooleanProperty boolProp : this.prop.doubleSidedText) {
for (final PredicateProperty<Boolean> boolProp : this.prop.doubleSidedText) {
if (boolProp.predicate.test(map)) {
doubleSidedText = boolProp.doubleSided;
doubleSidedText = boolProp.state;
}
}
final String name = info.tileEntity.getNameWrapper();
Expand Down Expand Up @@ -375,41 +373,42 @@ public ActionResultType use(final BlockState state, final World world, final Blo
return ActionResultType.FAIL;
}
final SignalStateInfo stateInfo = new SignalStateInfo(world, pos, this);
if (loadRedstoneOutput(world, stateInfo)) {
world.blockUpdated(pos, state.getBlock());
return ActionResultType.SUCCESS;
}
final boolean customname = canHaveCustomname(SignalStateHandler.getStates(stateInfo));
if (!player.getItemInHand(Hand.MAIN_HAND).getItem().equals(OSItems.LINKING_TOOL)
final Map<SEProperty, String> properties = SignalStateHandler.getStates(stateInfo);
final boolean customname = canHaveCustomname(properties);
if (player.getItemInHand(Hand.MAIN_HAND).getItem().equals(OSItems.MANIPULATOR)
&& (canBeLinked() || customname)) {
OpenSignalsMain.handler.invokeGui(Signal.class, player, world, pos, "signal");
return ActionResultType.SUCCESS;
}
if (loadRedstoneOutput(world, stateInfo, properties)) {
world.blockUpdated(pos, state.getBlock());
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}

@SuppressWarnings("unchecked")
private boolean loadRedstoneOutput(final World worldIn, final SignalStateInfo info) {
private boolean loadRedstoneOutput(final World worldIn, final SignalStateInfo info,
final Map<SEProperty, String> properties) {
if (!this.prop.redstoneOutputs.isEmpty()) {
final Map<SEProperty, String> properties = SignalStateHandler.getStates(info);
this.powerProperty = null;
for (final ValuePack pack : this.prop.redstoneOutputs) {
if (pack.predicate.test(properties)) {
this.powerProperty = pack.property;
if (properties.containsKey(pack.property)) {
SignalStateHandler.setState(info, powerProperty,
Boolean.toString(!Boolean.valueOf(properties.get(pack.property))));
}
if (properties.containsKey(pack.property) && pack.predicate.test(properties)) {
SignalStateHandler.setState(info, pack.property,
Boolean.toString(!Boolean.valueOf(properties.get(pack.property))));
return true;
}
}
}
return false;
}

public boolean hasRedstoneOut() {
return !this.prop.redstoneOutputs.isEmpty() || !this.prop.redstoneOutputPacks.isEmpty();
}

@Override
public boolean isSignalSource(final BlockState state) {
return !this.prop.redstoneOutputs.isEmpty();
return hasRedstoneOut();
}

@Override
Expand All @@ -422,19 +421,19 @@ public int getSignal(final BlockState state, final IBlockReader getter, final Bl
@Override
public int getDirectSignal(final BlockState blockState, final IBlockReader blockAccess,
final BlockPos pos, final Direction side) {
if (this.prop.redstoneOutputs.isEmpty() || this.powerProperty == null
|| !(blockAccess instanceof World)) {
if (!hasRedstoneOut() || !(blockAccess instanceof World)) {
return 0;
}
final SignalStateInfo stateInfo = new SignalStateInfo((World) blockAccess, pos, this);
if (SignalStateHandler.getState(stateInfo, powerProperty)
.filter(power -> power.equalsIgnoreCase("false")).isPresent()) {
return 0;
}
final Map<SEProperty, String> properties = SignalStateHandler.getStates(stateInfo);
for (final ValuePack pack : this.prop.redstoneOutputs) {
if (pack.predicate.test(properties)) {
return 15;
for (final List<ValuePack> valuePacks : ImmutableList.of(this.prop.redstoneOutputPacks,
this.prop.redstoneOutputs)) {
for (final ValuePack pack : valuePacks) {
if (properties.containsKey(pack.property) && pack.predicate.test(properties)
&& !properties.get(pack.property)
.equalsIgnoreCase(pack.property.getDefault())) {
return 15;
}
}
}
return 0;
Expand All @@ -452,7 +451,7 @@ public void getUpdate(final World world, final BlockPos pos) {
return;

if (sound.duration == 1) {
world.playSound(null, pos, sound.sound, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.playSound(null, pos, sound.state, SoundCategory.BLOCKS, 1.0F, 1.0F);
} else {
if (world.getBlockTicks().hasScheduledTick(pos, this)) {
return;
Expand Down Expand Up @@ -485,7 +484,7 @@ public void tick(final BlockState state, final ServerWorld world, final BlockPos
if (sound.duration <= 1) {
return;
}
world.playSound(null, pos, sound.sound, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.playSound(null, pos, sound.state, SoundCategory.BLOCKS, 1.0F, 1.0F);
world.getBlockTicks().scheduleTick(pos, this, sound.duration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import java.util.Map;
import java.util.function.Predicate;

import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.troblecodings.signals.OpenSignalsMain;
import com.troblecodings.signals.SEProperty;
import com.troblecodings.signals.blocks.Signal;
import com.troblecodings.signals.parser.FunctionParsingInfo;
import com.troblecodings.signals.parser.LogicParser;
import com.troblecodings.signals.parser.LogicalParserException;
import com.troblecodings.signals.properties.ConfigProperty;
import com.troblecodings.signals.properties.SignalPair;
import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty;

public class ChangeConfigParser {

Expand All @@ -23,11 +23,10 @@ public class ChangeConfigParser {
private Map<String, String> savedPredicates;
private Map<String, List<String>> values;

public static final Map<SignalPair, List<ConfigProperty>> CHANGECONFIGS = new HashMap<>();
public static final Map<Map.Entry<Signal, Signal>, List<ConfigProperty>> CHANGECONFIGS = new HashMap<>();

private static final Gson GSON = new Gson();

@SuppressWarnings("rawtypes")
public static void loadChangeConfigs() {

for (final Map.Entry<String, String> files : OpenSignalsMain.contentPacks
Expand All @@ -43,7 +42,7 @@ public static void loadChangeConfigs() {
+ "This config with filename '" + files.getKey() + "' will be skiped!");
continue;
}
final SignalPair pair = new SignalPair(start, end);
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()
Expand All @@ -60,7 +59,7 @@ public static void loadChangeConfigs() {
for (final Map.Entry<String, List<String>> entry : parser.values.entrySet()) {

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

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public ContentPackException(final Throwable err) {
public ContentPackException(final String message, final Throwable err) {
super(message, err);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.troblecodings.signals.parser.FunctionParsingInfo;
import com.troblecodings.signals.parser.LogicParser;
import com.troblecodings.signals.parser.LogicalParserException;
import com.troblecodings.signals.properties.ConfigProperty;
import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty;

public class DefaultConfigParser {

Expand All @@ -25,7 +25,6 @@ public class DefaultConfigParser {

private static final Gson GSON = new Gson();

@SuppressWarnings("rawtypes")
public static void loadDefaultConfigs() {

for (final Map.Entry<String, String> files : OpenSignalsMain.contentPacks
Expand Down Expand Up @@ -55,7 +54,7 @@ public static void loadDefaultConfigs() {
for (final Map.Entry<String, List<String>> entry : parser.values.entrySet()) {

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

if (valueToParse.contains("map(") && savedPredicates != null
&& !savedPredicates.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import java.util.List;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.troblecodings.signals.OpenSignalsMain;
import com.troblecodings.signals.SEProperty;
import com.troblecodings.signals.blocks.Signal;
import com.troblecodings.signals.parser.FunctionParsingInfo;
import com.troblecodings.signals.parser.LogicalParserException;
import com.troblecodings.signals.properties.ConfigProperty;
import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty;

public class OneSignalConfigParser {

Expand All @@ -29,7 +30,7 @@ public static void loadOneSignalConfigs() {
loadResetConfigs();
}

public static void loadShuntigConfigs() {
private static void loadShuntigConfigs() {
for (final Map.Entry<String, String> files : OpenSignalsMain.contentPacks
.getFiles("signalconfigs/shunting")) {
final OneSignalConfigParser parser = GSON.fromJson(files.getValue(),
Expand All @@ -48,14 +49,14 @@ public static void loadShuntigConfigs() {
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : parser.values) {
final String[] value = property.split("\\.");
propertes
.add(new ConfigProperty((SEProperty) info.getProperty(value[0]), value[1]));
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
}
SHUNTINGCONFIGS.put(signal, propertes);
}
}

public static void loadResetConfigs() {
private static void loadResetConfigs() {
for (final Map.Entry<String, String> files : OpenSignalsMain.contentPacks
.getFiles("signalconfigs/reset")) {
final OneSignalConfigParser parser = GSON.fromJson(files.getValue(),
Expand All @@ -75,8 +76,8 @@ public static void loadResetConfigs() {
final List<ConfigProperty> propertes = new ArrayList<>();
for (final String property : parser.values) {
final String[] value = property.split("\\.");
propertes
.add(new ConfigProperty((SEProperty) info.getProperty(value[0]), value[1]));
propertes.add(new ConfigProperty(t -> true,
ImmutableMap.of((SEProperty) info.getProperty(value[0]), value[1])));
}
RESETCONFIGS.put(signal, propertes);
}
Expand All @@ -85,8 +86,9 @@ public static void loadResetConfigs() {
private static Signal checkSignal(final String signalName, final String filename) {
final Signal signal = Signal.SIGNALS.get(signalName.toLowerCase());
if (signal == null) {
throw new ContentPackException("The signal '" + signalName + "' doesn't exists! "
+ "Please check " + filename + " where to problem is!");
throw new ContentPackException(
"The signal '" + signalName + "' doesn't exists! " + "Please check " + filename
+ " where to problem is! Valid Signals: " + Signal.SIGNALS.keySet());
}
return signal;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class SEPropertyParser {
private int itemDamage = 1;
private transient JsonEnum parent;

@SuppressWarnings("unchecked")
public SEProperty createSEProperty(final FunctionParsingInfo info) {
if (defaultState instanceof Boolean) {
parent = JsonEnum.BOOLEAN;
Expand All @@ -34,7 +33,8 @@ public SEProperty createSEProperty(final FunctionParsingInfo info) {

if (parent == null)
throw new ContentPackException(String.format("Property[%s], with class %s not found!",
name, enumClass.toLowerCase()));
name, enumClass.toLowerCase()) + " Valid EnumClasses: "
+ JsonEnumHolder.PROPERTIES.keySet());

ChangeableStage stage = ChangeableStage.APISTAGE;
if (changeableStage != null && !changeableStage.isEmpty()) {
Expand Down
Loading

0 comments on commit e4a4c4d

Please sign in to comment.