Merge pull request 'Refactor' (#7) from Luna/chipmunkmod:1.20.1 into 1.20.1

Reviewed-on: ChipmunkMC/chipmunkmod#7
This commit is contained in:
chipmunk 2023-07-01 18:13:25 -04:00
commit ff5c7cf535
17 changed files with 56 additions and 106 deletions

View file

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'maven-publish'
}
@ -10,16 +10,6 @@ archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
mavenCentral()
}
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
@ -28,17 +18,6 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}
processResources {
@ -54,32 +33,8 @@ tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}

View file

@ -5,7 +5,7 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
# Mod Properties
@ -14,4 +14,4 @@ org.gradle.parallel=true
archives_base_name = chipmunkmod
# Dependencies
fabric_version=0.83.1+1.20.1
fabric_version=0.84.0+1.20.1

Binary file not shown.

View file

@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

16
gradlew vendored
View file

@ -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
@ -133,10 +130,13 @@ 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.
@ -144,7 +144,7 @@ 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
@ -152,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | 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
@ -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

View file

@ -1,2 +0,0 @@
config.stopBubbling = true
lombok.accessors.fluent = true

View file

@ -2,7 +2,6 @@ package land.chipmunk.chipmunkmod;
import land.chipmunk.chipmunkmod.data.BlockArea;
import net.minecraft.util.math.BlockPos;
import lombok.AllArgsConstructor;
public class Configuration {
public CommandManager commands = new CommandManager();
@ -27,9 +26,5 @@ public class Configuration {
public BotInfo kittycorp = new BotInfo("^", null);
}
@AllArgsConstructor
public static class BotInfo {
public String prefix;
public String key;
}
public static record BotInfo(String prefix, String key) {}
}

View file

@ -68,7 +68,7 @@ public class CloopCommand {
final CommandLoopManager manager = CommandLoopManager.INSTANCE;
final int id = getInteger(context, "id");
if (id < 0 || id >= manager.commandLoops().size()) throw INVALID_CLOOP_ID_EXCEPTION.create(id);
if (id < 0 || id >= manager.commandLoops.size()) throw INVALID_CLOOP_ID_EXCEPTION.create(id);
manager.removeAndStop(id);
@ -88,11 +88,11 @@ public class CloopCommand {
public static int listCloops (CommandContext<FabricClientCommandSource> context) {
final FabricClientCommandSource source = context.getSource();
final List<CommandLoopManager.CommandLoop> loops = CommandLoopManager.INSTANCE.commandLoops();
final List<CommandLoopManager.CommandLoop> loops = CommandLoopManager.INSTANCE.commandLoops;
int id = 0;
for (CommandLoopManager.CommandLoop loop : loops) {
source.sendFeedback(Text.translatable("%s: %s (%s)", Text.literal(String.valueOf(id)), Text.literal(loop.command()), Text.literal(String.valueOf(loop.interval()))));
source.sendFeedback(Text.translatable("%s: %s (%s)", Text.literal(String.valueOf(id)), Text.literal(loop.command), Text.literal(String.valueOf(loop.getInterval()))));
id++;
}

View file

@ -43,8 +43,8 @@ public class ValidateCommand {
final MinecraftClient client = context.getSource().getClient();
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
final String prefix = info.prefix();
final String key = info.key();
if (key == null) throw UNSPECIFIED_KEY.create();
try {
@ -69,8 +69,8 @@ public class ValidateCommand {
final MinecraftClient client = context.getSource().getClient();
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
final String prefix = info.prefix();
final String key = info.key();
if (key == null) throw UNSPECIFIED_KEY.create();
try {
@ -94,8 +94,8 @@ public class ValidateCommand {
final String command = getString(context, "command");
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
final String prefix = info.prefix();
final String key = info.key();
if (key == null) throw UNSPECIFIED_KEY.create();
try {
@ -119,8 +119,8 @@ public class ValidateCommand {
final String command = getString(context, "command");
final ClientPlayNetworkHandler networkHandler = context.getSource().getClient().getNetworkHandler();
final String prefix = info.prefix;
final String key = info.key;
final String prefix = info.prefix();
final String key = info.key();
if (key == null) throw UNSPECIFIED_KEY.create();
try {

View file

@ -1,13 +1,6 @@
package land.chipmunk.chipmunkmod.data;
import net.minecraft.util.math.BlockPos;
import lombok.AllArgsConstructor;
import lombok.Data;
// ? Am I reinventing the wheel here?
@AllArgsConstructor
@Data
public class BlockArea {
private BlockPos start;
private BlockPos end;
}
public record BlockArea(BlockPos start, BlockPos end) {}

View file

@ -40,7 +40,7 @@ public class ClientPlayNetworkHandlerMixin {
final TextContent content = message.getContent();
if (content instanceof TranslatableTextContent t_content && t_content.getKey().startsWith("advMode.setCommand")) {
final CommandCore.CommandSetMode commandSetMode = CommandCore.INSTANCE.commandSetMode();
final CommandCore.CommandSetMode commandSetMode = CommandCore.INSTANCE.commandSetMode;
if (commandSetMode == CommandCore.CommandSetMode.HIDDEN) {
ci.cancel();

View file

@ -26,7 +26,7 @@ public class ClientPlayerEntityMixin {
final ClientWorld world = CLIENT.getNetworkHandler().getWorld();
final BlockPos origin = CommandCore.INSTANCE.origin();
final BlockPos origin = CommandCore.INSTANCE.origin;
if (origin == null) { CommandCore.INSTANCE.move(position); return; }
final int distance = (int) Math.sqrt(new Vec2f(origin.getX() / 16, origin.getZ() / 16).distanceSquared(new Vec2f((int) position.getX() / 16, (int) position.getZ() / 16)));
if (distance > world.getSimulationDistance()) CommandCore.INSTANCE.move(position);

View file

@ -8,8 +8,6 @@ import net.minecraft.network.packet.c2s.play.UpdateCommandBlockC2SPacket;
import net.minecraft.block.entity.CommandBlockBlockEntity;
import net.minecraft.nbt.NbtCompound;
import com.google.gson.annotations.SerializedName;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.ArrayList;
import java.util.Timer;
@ -21,12 +19,12 @@ import land.chipmunk.chipmunkmod.data.BlockArea;
public class CommandCore {
private MinecraftClient client;
@Getter @Setter private boolean ready = false;
@Getter @Setter private BlockPos origin;
@Getter private final BlockArea relativeArea;
@Getter @Setter private BlockPos currentBlockRelative;
@Getter @Setter private boolean enabled;
@Getter @Setter private CommandSetMode commandSetMode;
public boolean ready = false;
public BlockPos origin;
private final BlockArea relativeArea;
public BlockPos currentBlockRelative;
public boolean enabled;
public CommandSetMode commandSetMode;
public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea, ChipmunkMod.CONFIG.core.enabled, ChipmunkMod.CONFIG.core.commandSet);
@ -164,6 +162,10 @@ public class CommandCore {
ready = false;
}
public BlockArea getRelativeArea() {
return this.relativeArea;
}
public static enum CommandSetMode {
@SerializedName("shown") SHOWN,
@SerializedName("hidden") HIDDEN,

View file

@ -1,7 +1,5 @@
package land.chipmunk.chipmunkmod.modules;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.ArrayList;
import java.util.Timer;
@ -9,7 +7,7 @@ import java.util.TimerTask;
public class CommandLoopManager {
private final CommandCore core;
@Getter @Setter private List<CommandLoop> commandLoops = new ArrayList<>();
public final List<CommandLoop> commandLoops = new ArrayList<>();
public CommandLoopManager (CommandCore core) {
this.core = core;
@ -40,9 +38,9 @@ public class CommandLoopManager {
public void cleanup () { this.clearLoops(); }
public static class CommandLoop {
@Getter @Setter private CommandCore core;
@Getter @Setter private String command;
@Getter private long interval;
public CommandCore core;
public String command;
private long interval;
private Timer timer;
public CommandLoop (CommandCore core, String command, long interval) {
@ -53,7 +51,11 @@ public class CommandLoopManager {
timer.schedule(this.createTimerTask(), interval, interval);
}
private long interval (long interval) {
public long getInterval() {
return this.interval;
}
private long setInterval (long interval) {
if (timer == null) throw new IllegalStateException("Attempted to set the interval of a stopped command loop");
timer.cancel();

View file

@ -5,13 +5,12 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import lombok.Getter;
import java.util.Timer;
import java.util.TimerTask;
public class SelfCare {
private final MinecraftClient client;
@Getter private long interval;
private long interval;
private Timer timer = null;
@ -69,4 +68,8 @@ public class SelfCare {
return false;
}
public long getInterval() {
return this.interval;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

After

Width:  |  Height:  |  Size: 695 B

Before After
Before After

View file

@ -10,7 +10,7 @@
],
"contact": {
"homepage": "https://chipmunk.land/",
"sources": "https://code.chipmunk.land/ChipmunkMC/fabric-mod-mabe"
"sources": "https://code.chipmunk.land/ChipmunkMC/chipmunkmod"
},
"license": "CC0-1.0",
@ -27,12 +27,9 @@
],
"depends": {
"fabricloader": ">=0.14.11",
"fabricloader": ">=0.14.21",
"fabric-api": "*",
"minecraft": "~1.20.1",
"java": ">=17"
},
"suggests": {
"another-mod": "*"
}
}