Skip to content

Commit

Permalink
Fixes and config screen improvements
Browse files Browse the repository at this point in the history
- Fix sprite paths starting with "assets/minecraft/" not being parsed correctly; fix #246
- Fix custom block layers not being applied to moving blocks; fix #237
- Update config screen
  - Option values are now saved only when the screen is closed
  - Formatting of changed option values is now different
  - Fix world renderer reload even when no options were changed
  - Add a cancel button to allow discarding changes
- Disallow relative and non-standard sprite paths when namespace is defined
- Use unsigned left bit shift operator instead of signed version when appropriate
- Add pack icon for glass pane culling fix pack
- Slightly improve pack icon for default pack
- Improve built-in pack descriptions
- Update to 1.19.2
- Update Gradle and build dependencies
- Add Loom Vineflower
- Bump version
  • Loading branch information
PepperCode1 committed Jul 20, 2023
1 parent 3fe7a74 commit e1fd483
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 83 deletions.
28 changes: 15 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'fabric-loom' version "${loom_version}"
id 'io.github.juuxel.loom-vineflower' version "${loom_vineflower_version}"
id 'maven-publish'
}

Expand All @@ -10,6 +11,14 @@ archivesBaseName = project.archives_base_name
version = project.mod_version + '+' + project.mod_minecraft_version + getExtraBuildMetadata()
group = project.maven_group

String getExtraBuildMetadata() {
String buildNumber = System.getenv('GITHUB_RUN_NUMBER')
if (buildNumber != null) {
return ".build.${buildNumber}"
}
return ''
}

repositories {
maven {
name 'TerraformersMC'
Expand All @@ -20,6 +29,7 @@ repositories {
url 'https://api.modrinth.com/maven'
}
maven {
name "VRAM"
url 'https://maven.vram.io'
}
maven {
Expand All @@ -37,22 +47,14 @@ dependencies {
// Fabric API
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation('com.terraformersmc:modmenu:4.0.4') {
modImplementation("com.terraformersmc:modmenu:${modmenu_version}") {
exclude group: 'net.fabricmc.fabric-api'
}

modCompileOnly 'maven.modrinth:sodium:mc1.19-0.4.2'
modCompileOnly 'maven.modrinth:indium:1.0.7+mc1.19'
modCompileOnly 'io.vram:frex-fabric-mc119:6.0.278'
modCompileOnly 'io.vram:canvas-fabric-mc119:1.0.2453'
}

String getExtraBuildMetadata() {
String buildNumber = System.getenv('GITHUB_RUN_NUMBER')
if (buildNumber != null) {
return "-build.${buildNumber}"
}
return ''
modCompileOnly "maven.modrinth:sodium:${sodium_version}"
modCompileOnly "maven.modrinth:indium:${indium_version}"
modCompileOnly "io.vram:frex-fabric:${frex_version}"
modCompileOnly "io.vram:canvas-fabric:${canvas_version}"
}

processResources {
Expand Down
24 changes: 15 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
org.gradle.jvmargs = -Xmx1G

# Fabric Properties
loom_version = 1.1-SNAPSHOT
minecraft_version = 1.19
yarn_mappings = 1.19+build.4
loader_version = 0.14.13
loom_version = 1.3.8
loom_vineflower_version = 1.11.0
minecraft_version = 1.19.2
yarn_mappings = 1.19.2+build.28
loader_version = 0.14.21

# Mod Properties
mod_version = 2.0.2
mod_minecraft_version = 1.19
maven_group = me.pepperbell
archives_base_name = continuity
mod_version = 2.0.3
mod_minecraft_version = 1.19.2
maven_group = me.pepperbell
archives_base_name = continuity

# Dependencies
fabric_version = 0.58.0+1.19
fabric_version = 0.76.0+1.19.2
modmenu_version = 4.1.2
sodium_version = mc1.19.2-0.4.4
indium_version = 1.0.9+mc1.19.2
frex_version = 19.2.307
canvas_version = 19.2.2614
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 10 additions & 6 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,26 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.ObjectBidirectionalIterator;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;

public class ContinuityConfig {
protected static final Logger LOGGER = LoggerFactory.getLogger("Continuity Config");
Expand Down Expand Up @@ -64,10 +63,6 @@ public void save() {
}
}

public void onChange() {
MinecraftClient.getInstance().worldRenderer.reload();
}

protected void fromJson(JsonElement json) throws JsonParseException {
if (json.isJsonObject()) {
JsonObject object = json.getAsJsonObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package me.pepperbell.continuity.client.config;

import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -11,6 +17,8 @@ public class ContinuityConfigScreen extends Screen {
private final Screen parent;
private final ContinuityConfig config;

private List<Value<?>> values;

public ContinuityConfigScreen(Screen parent, ContinuityConfig config) {
super(Text.translatable(getTranslationKey("title")));
this.parent = parent;
Expand All @@ -19,11 +27,24 @@ public ContinuityConfigScreen(Screen parent, ContinuityConfig config) {

@Override
protected void init() {
addDrawableChild(createBooleanOptionButton(width / 2 - 100 - 110, height / 2 - 10 - 12, 200, 20, config.connectedTextures));
addDrawableChild(createBooleanOptionButton(width / 2 - 100 + 110, height / 2 - 10 - 12, 200, 20, config.emissiveTextures));
addDrawableChild(createBooleanOptionButton(width / 2 - 100 - 110, height / 2 - 10 + 12, 200, 20, config.customBlockLayers));
Value<Boolean> connectedTextures = Value.of(config.connectedTextures, Value.Flag.RELOAD_WORLD_RENDERER);
Value<Boolean> emissiveTextures = Value.of(config.emissiveTextures, Value.Flag.RELOAD_WORLD_RENDERER);
Value<Boolean> customBlockLayers = Value.of(config.customBlockLayers, Value.Flag.RELOAD_WORLD_RENDERER);

values = List.of(connectedTextures, emissiveTextures, customBlockLayers);

addDrawableChild(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, ScreenTexts.DONE, button -> close()));
addDrawableChild(createBooleanValueButton(connectedTextures,
width / 2 - 100 - 110, height / 2 - 10 - 12, 200, 20));
addDrawableChild(createBooleanValueButton(emissiveTextures,
width / 2 - 100 + 110, height / 2 - 10 - 12, 200, 20));
addDrawableChild(createBooleanValueButton(customBlockLayers,
width / 2 - 100 - 110, height / 2 - 10 + 12, 200, 20));

addDrawableChild(new ButtonWidget(width / 2 - 75 - 79, height - 40, 150, 20, ScreenTexts.DONE, button -> {
saveValues();
close();
}));
addDrawableChild(new ButtonWidget(width / 2 - 75 + 79, height - 40, 150, 20, ScreenTexts.CANCEL, button -> close()));
}

@Override
Expand All @@ -38,10 +59,21 @@ public void close() {
client.setScreen(parent);
}

@Override
public void removed() {
private void saveValues() {
EnumSet<Value.Flag> flags = EnumSet.noneOf(Value.Flag.class);

for (Value<?> value : values) {
if (value.isChanged()) {
value.saveToOption();
flags.addAll(value.getFlags());
}
}

config.save();
config.onChange();

for (Value.Flag flag : flags) {
flag.onSave();
}
}

private static String getTranslationKey(String optionKey) {
Expand All @@ -58,17 +90,77 @@ private ButtonWidget.TooltipSupplier createDefaultTooltipSupplier(StringVisitabl
};
}

private ButtonWidget createBooleanOptionButton(int x, int y, int width, int height, Option<Boolean> option) {
String translationKey = getTranslationKey(option.getKey());
private ButtonWidget createBooleanValueButton(Value<Boolean> value, int x, int y, int width, int height) {
String translationKey = getTranslationKey(value.getOption().getKey());
Text text = Text.translatable(translationKey);
Text tooltipText = Text.translatable(getTooltipKey(translationKey));
return new ButtonWidget(x, y, width, height, ScreenTexts.composeToggleText(text, option.get()),

return new ButtonWidget(x, y, width, height, ScreenTexts.composeGenericOptionText(text, ScreenTexts.onOrOff(value.get())),
button -> {
boolean newValue = !option.get();
button.setMessage(ScreenTexts.composeToggleText(text, newValue));
option.set(newValue);
boolean newValue = !value.get();
value.set(newValue);
Text valueText = ScreenTexts.onOrOff(newValue);
if (value.isChanged()) {
valueText = valueText.copy().styled(style -> style.withBold(true));
}
button.setMessage(ScreenTexts.composeGenericOptionText(text, valueText));
},
createDefaultTooltipSupplier(tooltipText)
);
}

private static class Value<T> {
private final Option<T> option;
private final Set<Flag> flags;
private final T originalValue;
private T value;

public Value(Option<T> option, Set<Flag> flags) {
this.option = option;
this.flags = flags;
originalValue = this.option.get();
value = originalValue;
}

public static <T> Value<T> of(Option<T> option, Flag... flags) {
EnumSet<Flag> flagSet = EnumSet.noneOf(Flag.class);
Collections.addAll(flagSet, flags);
return new Value<>(option, flagSet);
}

public Option<T> getOption() {
return option;
}

public Set<Flag> getFlags() {
return flags;
}

public T get() {
return value;
}

public void set(T value) {
this.value = value;
}

public boolean isChanged() {
return !value.equals(originalValue);
}

public void saveToOption() {
option.set(value);
}

public enum Flag {
RELOAD_WORLD_RENDERER {
@Override
public void onSave() {
MinecraftClient.getInstance().worldRenderer.reload();
}
};

public abstract void onSave();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,14 @@ public class RenderLayersMixin {
}
}
}

@Inject(method = "getMovingBlockLayer(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/RenderLayer;", at = @At("HEAD"), cancellable = true)
private static void continuity$onHeadGetMovingBlockLayer(BlockState state, CallbackInfoReturnable<RenderLayer> cir) {
if (ContinuityConfig.INSTANCE.customBlockLayers.get()) {
RenderLayer layer = CustomBlockLayers.getLayer(state);
if (layer != null) {
cir.setReturnValue(layer == RenderLayer.getTranslucent() ? RenderLayer.getTranslucentMovingBlock() : layer);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ protected static boolean shouldSplitUV(int signumA, int signumB) {
protected int getSpriteIndex(int quadrantIndex, int connections) {
int index1 = quadrantIndex;
int index2 = (quadrantIndex + 3) % 4;
boolean connected1 = ((connections >> index1 * 2) & 1) == 1;
boolean connected2 = ((connections >> index2 * 2) & 1) == 1;
boolean connected1 = ((connections >>> index1 * 2) & 1) == 1;
boolean connected2 = ((connections >>> index2 * 2) & 1) == 1;
if (connected1 && connected2) {
if (((connections >> (index2 * 2 + 1)) & 1) == 1) {
if (((connections >>> (index2 * 2 + 1)) & 1) == 1) {
return 1;
}
return 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static int getConnections(ConnectionPredicate connectionPredicate, boolea
for (int i = 0; i < 4; i++) {
int index1 = i;
int index2 = (i + 1) % 4;
if (((connections >> index1 * 2) & 1) == 1 && ((connections >> index2 * 2) & 1) == 1) {
if (((connections >>> index1 * 2) & 1) == 1 && ((connections >>> index2 * 2) & 1) == 1) {
mutablePos.set(pos, directions[index1]).move(directions[index2]);
if (connectionPredicate.shouldConnect(blockView, state, pos, mutablePos, face, quadSprite, innerSeams)) {
connections |= 1 << (i * 2 + 1);
Expand Down
Loading

0 comments on commit e1fd483

Please sign in to comment.