Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the mod-base to 1.20.4 #340

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//file:noinspection GroovyAssignabilityCheck

plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '8.+'
}
Expand Down Expand Up @@ -50,7 +50,7 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

// Worldedit API
modImplementation("com.sk89q.worldedit:worldedit-fabric-mc1.18.2:7.2.10")
modImplementation("com.sk89q.worldedit:worldedit-fabric-mc1.20.4:7.2.18-SNAPSHOT")
}

processResources {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.4
loader_version=0.14.6
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.3
loader_version=0.15.3

# Mod Properties
mod_version = 1.18.2-2.0.0
mod_version = 1.20.4-1.0.0
maven_group = tools.redstone
archives_base_name = redstonetools

# Dependencies
fabric_version=0.53.0+1.18.2
fabric_version=0.92.0+1.20.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tools.redstone.redstonetools;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rip.hippo.inject.Doctor;
import rip.hippo.inject.Injector;
import tools.redstone.redstonetools.utils.DependencyLookup;
import tools.redstone.redstonetools.utils.ReflectionUtils;

import java.nio.file.Path;

public class RedstoneToolsClient implements ClientModInitializer {

public static final String MOD_ID = "redstonetools";
public static final String MOD_VERSION = "v" + FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow().getMetadata().getVersion().getFriendlyString();
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir().resolve("redstonetools");
public static final Injector INJECTOR = Doctor.createInjector(ReflectionUtils.getModules());

@Override
public void onInitializeClient() {
LOGGER.info("Initializing Redstone Tools");

// Register game rules
RedstoneToolsGameRules.register();

// Register features
ReflectionUtils.getFeatures().forEach(feature -> {
LOGGER.trace("Registering feature {}", feature.getClass().getName());

if (feature.requiresWorldEdit() && !DependencyLookup.WORLDEDIT_PRESENT) {
LOGGER.warn("Feature {} requires WorldEdit, but WorldEdit is not loaded. Skipping registration.", feature.getName());
return;
}
feature.register();
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tools.redstone.redstonetools;

import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory;
import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry;
import net.minecraft.world.GameRules;
import tools.redstone.redstonetools.utils.DependencyLookup;


public class RedstoneToolsGameRules {
private RedstoneToolsGameRules() {
}

public static GameRules.Key<GameRules.BooleanRule> DO_CONTAINER_DROPS;
public static GameRules.Key<GameRules.BooleanRule> DO_BLOCK_UPDATES_AFTER_EDIT;

public static void register() {
DO_CONTAINER_DROPS = GameRuleRegistry.register("doContainerDrops", GameRules.Category.DROPS, GameRuleFactory.createBooleanRule(true));

if (DependencyLookup.WORLDEDIT_PRESENT) {
DO_BLOCK_UPDATES_AFTER_EDIT = GameRuleRegistry.register("doBlockUpdatesAfterEdit", GameRules.Category.UPDATES, GameRuleFactory.createBooleanRule(false));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package tools.redstone.redstonetools.di;

import com.google.auto.service.AutoService;
import rip.hippo.inject.DoctorModule;
import rip.hippo.inject.binding.Binder;
import tools.redstone.redstonetools.utils.ReflectionUtils;

@AutoService(DoctorModule.class)
public class FeatureModule implements DoctorModule {
@SuppressWarnings({"rawtypes", "unchecked"}) // this is probably the only way to make it work
@Override
public void configure(Binder binder) {
for (var feature : ReflectionUtils.getFeatures()) {
Class clazz = feature.getClass();
binder.bind(clazz).toInstance(feature);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tools.redstone.redstonetools.di;

import com.google.auto.service.AutoService;
import rip.hippo.inject.DoctorModule;
import rip.hippo.inject.binding.Binder;
import tools.redstone.redstonetools.features.feedback.AbstractFeedbackSender;
import tools.redstone.redstonetools.features.feedback.FeedbackSender;

@AutoService(DoctorModule.class)
public class UtilityModule implements DoctorModule {
@Override
public void configure(Binder binder) {
binder.bind(AbstractFeedbackSender.class).to(FeedbackSender.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package tools.redstone.redstonetools.features;

import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;

public abstract class AbstractFeature {

private final Feature featureInfo;
private final String id;

{
featureInfo = getClass().getAnnotation(Feature.class);

if (featureInfo == null) {
throw new IllegalStateException("Feature " + getClass() + " is not annotated with @Feature");
}

String id = featureInfo.id();
if (id.isEmpty()) {
// derive id from name
// Air Place -> airplace
id = featureInfo.name()
.toLowerCase()
.replace(" ", "");
}

this.id = id;
}

public String getID() {
return id;
}

public String getName() {
return featureInfo.name();
}

public String getDescription() {
return featureInfo.description();
}

public String getCommand() {
return featureInfo.command();
}

public boolean requiresWorldEdit() {
return featureInfo.worldedit();
}

/**
* Register this feature.
*/
public void register() {
CommandRegistrationCallback.EVENT.register(this::registerCommands);
}

protected abstract void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tools.redstone.redstonetools.features;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Feature {
String id() default "";
String name();
String description();
String command();
boolean worldedit() default false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tools.redstone.redstonetools.features.arguments;

import tools.redstone.redstonetools.features.arguments.serializers.TypeSerializer;
import com.mojang.brigadier.context.CommandContext;

public class Argument<T> {
private String name;
private final TypeSerializer<T, ?> type;
private boolean optional = false;
private volatile T value;
private T defaultValue;

private Argument(TypeSerializer<T, ?> type) {
this.type = type;
}

public static <T> Argument<T> ofType(TypeSerializer<T, ?> type) {
return new Argument<>(type);
}

public Argument<T> withDefault(T defaultValue) {
optional = true;
this.defaultValue = defaultValue;
this.value = defaultValue; // for options, temporary

return this;
}

public T getDefaultValue() {
return defaultValue;
}

public Argument<T> named(String name) {
this.name = name;

return this;
}

public Argument<T> ensureNamed(String fieldName) {
if (name == null) {
name = fieldName;
}

return this;
}

public String getName() {
return name;
}

public TypeSerializer<T, ?> getType() {
return type;
}

public boolean isOptional() {
return optional;
}

@SuppressWarnings("unchecked")
public void updateValue(CommandContext<?> context) {
try {
value = (T) context.getArgument(name, Object.class);
} catch (IllegalArgumentException e) {
if (!optional) {
throw e;
}

value = defaultValue;
}
}

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

public T getValue() {
return value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tools.redstone.redstonetools.features.arguments.serializers;

import java.math.BigInteger;
import java.util.Optional;

public class BigIntegerSerializer extends IntLikeSerializer<BigInteger> {
private static final BigIntegerSerializer INSTANCE = new BigIntegerSerializer(null, null);

public static BigIntegerSerializer bigInteger() {
return INSTANCE;
}

public static BigIntegerSerializer bigInteger(BigInteger min) {
return new BigIntegerSerializer(min, null);
}

public static BigIntegerSerializer bigInteger(BigInteger min, BigInteger max) {
return new BigIntegerSerializer(min, max);
}

private BigIntegerSerializer(BigInteger min, BigInteger max) {
super(BigInteger.class, min, max);
}

@Override
protected Optional<BigInteger> tryParseOptional(String string, int radix) {
try {
return Optional.of(new BigInteger(string, radix));
} catch (NumberFormatException ignored) {
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tools.redstone.redstonetools.features.arguments.serializers;

import tools.redstone.redstonetools.utils.BlockColor;

public class BlockColorSerializer extends EnumSerializer<BlockColor> {
private static final BlockColorSerializer INSTANCE = new BlockColorSerializer();

private BlockColorSerializer() {
super(BlockColor.class);
}

public static BlockColorSerializer blockColor() {
return INSTANCE;
}
}
Loading
Loading