Skip to content

Commit

Permalink
actually fix servers and commands finally
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Feb 12, 2024
1 parent 537e606 commit e9b678d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 87 deletions.
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/PlatformPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public void apply(@NotNull Project project) {
String memoryArgs = "-Xmx4G -Xms4G";
String gcArgs = "-XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGuaranteedGCInterval=1000000 -XX:AllocatePrefetchStyle=1";
settings.vmArgs(String.join(" ", baseArgs, memoryArgs, gcArgs).split(" "));
if("true".equals(project.findProperty("mixin.debug"))) {
settings.vmArgs("-Dmixin.debug.export=true", "-Dmixin.debug.verbose=true");
}
};
clientConfig.accept(container.findByName("client"));
});
Expand Down
36 changes: 26 additions & 10 deletions common/src/main/java/dev/rdh/createunlimited/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.google.common.collect.Multimap;
import com.mojang.brigadier.arguments.ArgumentType;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.architectury.injectables.annotations.ExpectPlatform;

import dev.rdh.createunlimited.config.CUConfigs;
import net.minecraft.commands.CommandSourceStack;

import com.simibubi.create.foundation.config.ConfigBase.CValue;
import com.simibubi.create.foundation.config.ConfigBase.ConfigBool;

import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Direction.Axis;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;

import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
import net.minecraftforge.fml.config.IConfigSpec;
import net.minecraftforge.fml.config.ModConfig;

Expand All @@ -43,11 +45,6 @@ public static String platformName() {
throw new AssertionError();
}

@ExpectPlatform
public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> command) {
throw new AssertionError();
}

@ExpectPlatform
public static void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
throw new AssertionError();
Expand All @@ -66,13 +63,13 @@ public static Attribute getReachAttribute() {

public static Supplier<Multimap<Attribute, AttributeModifier>> singleRange() {
AttributeModifier am = new AttributeModifier(UUID.fromString("7f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier",
CUConfigs.server.singleExtendoGripRange.get(), AttributeModifier.Operation.ADDITION);
orElse(CUConfigs.server.singleExtendoGripRange, 3), AttributeModifier.Operation.ADDITION);
return Suppliers.memoize(() -> ImmutableMultimap.of(getReachAttribute(), am));
}

public static Supplier<Multimap<Attribute, AttributeModifier>> doubleRange() {
AttributeModifier am = new AttributeModifier(UUID.fromString("8f7dbdb2-0d0d-458a-aa40-ac7633691f66"), "Range modifier",
CUConfigs.server.doubleExtendoGripRange.get(), AttributeModifier.Operation.ADDITION);
orElse(CUConfigs.server.doubleExtendoGripRange, 5), AttributeModifier.Operation.ADDITION);
return Suppliers.memoize(() -> ImmutableMultimap.of(getReachAttribute(), am));
}

Expand Down Expand Up @@ -107,4 +104,23 @@ public static ItemStack copyStackWithSize(ItemStack stack, int size) {
copy.setCount(size);
return copy;
}

public static <V, T extends ConfigValue<V>> V orElse(CValue<V, T> value, V orElse) {
try {
return value.get();
} catch (IllegalStateException e) {
if(e.message.contains("config")) {
return orElse;
}
throw e;
}
}

public static boolean orFalse(ConfigBool config) {
return orElse(config, false);
}

public static boolean orTrue(ConfigBool config) {
return orElse(config, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CUConfigCommand extends CUCommands {
}

// get config as forge config value
ConfigValue<?> value = ((CValueAccessor) cValue).value;
ConfigValue<?> value = ((CValueAccessor) cValue).getValue();

// get, description, reset
gdr(category, name, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.simibubi.create.content.trains.entity.CarriageContraption;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -14,6 +15,6 @@
public abstract class CarriageContraptionMixin {
@ModifyExpressionValue(method = "assemble", at = @At(value = "INVOKE", target = "Ljava/util/Map;size()I", ordinal = 0))
private int modifyMinBlocksOnTrain(int original) {
return !CUConfigs.server.trainAssemblyChecks.get() ? 2 : original;
return !Util.orTrue(CUConfigs.server.trainAssemblyChecks) ? 2 : original;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.simibubi.create.content.decoration.copycat.CopycatBlock;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

Expand All @@ -13,6 +15,6 @@
public abstract class CopycatBlockMixin {
@ModifyExpressionValue(method = "getAcceptedBlockState", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/decoration/copycat/CopycatBlock;isAcceptedRegardless(Lnet/minecraft/world/level/block/state/BlockState;)Z"))
private boolean isAcceptedRegardless(boolean original) {
return CUConfigs.server.allowAllCopycatBlocks.get() || original;
return Util.orFalse(CUConfigs.server.allowAllCopycatBlocks) || original;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.rdh.createunlimited.mixin;

import com.simibubi.create.content.trains.station.StationBlockEntity;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
Expand All @@ -14,7 +16,7 @@
public abstract class StationBlockEntityMixin {
@ModifyExpressionValue(method = "assemble", at = @At(value = "INVOKE", target = "Lcom/simibubi/create/content/trains/bogey/AbstractBogeyBlock;allowsSingleBogeyCarriage()Z", ordinal = 0))
private boolean forceAllowSingleBogeyCarriage(boolean original) {
return !CUConfigs.server.trainAssemblyChecks.get() || original;
return !Util.orTrue(CUConfigs.server.trainAssemblyChecks) || original;
}

@ModifyExpressionValue(method = "assemble", at = @At(value = "CONSTANT", args = "intValue=3", ordinal = 0))
Expand All @@ -24,7 +26,7 @@ private int setMinBogeySpacing(int original) {

@Inject(method = "isValidBogeyOffset", at = @At("HEAD"), cancellable = true)
private void disableBogeyOffsetCheck(CallbackInfoReturnable<Boolean> cir) {
if(!CUConfigs.server.trainAssemblyChecks.get())
if(!Util.orTrue(CUConfigs.server.trainAssemblyChecks))
cir.setReturnValue(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import com.simibubi.create.content.contraptions.glue.SuperGlueSelectionHandler;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

@Mixin(value = SuperGlueSelectionHandler.class, remap = false)
public abstract class SuperGlueSectionHandlerMixin {
// client-side modification
@ModifyConstant(method = "tick", constant = @Constant(doubleValue = 24))
private double modifyMaxSuperGlueDistance(double original) {
return CUConfigs.server.maxGlueConnectionRange.get();
return Util.orElse(CUConfigs.server.maxGlueConnectionRange, original);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import com.simibubi.create.content.contraptions.glue.SuperGlueSelectionPacket;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

@Mixin(value = SuperGlueSelectionPacket.class, remap = false)
public abstract class SuperGlueSelectionPacketMixin {
// server-side modification
@ModifyConstant(method = "lambda$handle$0", constant = @Constant(doubleValue = 25))
private double modifyMaxSuperGlueDistance(double original) {
return CUConfigs.server.maxGlueConnectionRange.get();
return Util.orElse(CUConfigs.server.maxGlueConnectionRange, original);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.simibubi.create.content.trains.graph.TrackEdge;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,6 +12,6 @@
public abstract class TrackEdgeMixin {
@ModifyConstant(method = "canTravelTo", constant = @Constant(doubleValue = 0.875))
private double canTravelTo(double original) {
return CUConfigs.server.extendedDriving.get();
return Util.orElse(CUConfigs.server.extendedDriving, original);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import dev.rdh.createunlimited.config.CUServer.PlacementCheck;
import dev.rdh.createunlimited.mixin.accessor.PlacementInfoAccessor;

import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -44,9 +45,10 @@ public abstract class TrackPlacementMixin {
* @reason yeah
*/
@Overwrite
@SuppressWarnings("all")
public static PlacementInfo tryConnect(Level level, Player player, BlockPos pos2, BlockState state2,
ItemStack stack, boolean girder, boolean maximiseTurn) {
boolean enabled = CUConfigs.server.placementChecks.get().isEnabledFor(player);
boolean enabled = Util.orElse(CUConfigs.server.placementChecks, PlacementCheck.ON).isEnabledFor(player);

Vec3 lookVec = player.getLookAngle();
int lookAngle = (int) (22.5 + AngleHelper.deg(Mth.atan2(lookVec.z, lookVec.x)) % 360) / 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.simibubi.create.content.trains.entity.Train;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.config.CUConfigs;

import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -13,7 +14,7 @@
public abstract class TrainMixin {
@ModifyConstant(method = "tick", constant = @Constant(doubleValue = 4))
private double modifyMaxStress(double original) {
double a = CUConfigs.server.maxAllowedStress.get();
double a = Util.orElse(CUConfigs.server.maxAllowedStress, original);
return a < 0 ? Double.MAX_VALUE : a;
}
}
5 changes: 3 additions & 2 deletions common/src/main/resources/createunlimited.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"mixins": [
"CarriageContraptionMixin",
"CopycatBlockMixin",
"CTrainsMixin",
"ExtendoGripItemMixin",
"StationBlockEntityMixin",
"SuperGlueSectionHandlerMixin",
Expand All @@ -19,9 +18,11 @@
"accessor.PlacementInfoAccessor"
],
"client": [
"ClientHandshakePacketListenerImplMixin",
"TrainRelocatorMixin"
],
"server": [
"CTrainsMixin"
],
"injectors": {
"defaultRequire": 1
}
Expand Down
10 changes: 0 additions & 10 deletions fabric/src/main/java/dev/rdh/createunlimited/fabric/UtilImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,11 @@

import com.mojang.brigadier.arguments.ArgumentType;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.rdh.createunlimited.CreateUnlimited;

import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;

import net.fabricmc.loader.api.FabricLoader;

import net.minecraft.commands.CommandSourceStack;

import net.minecraft.commands.synchronization.ArgumentTypeInfo;

import net.minecraft.resources.ResourceLocation;
Expand All @@ -32,10 +26,6 @@

public class UtilImpl {

public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> command) {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, selection) -> dispatcher.register(command));
}

private static MethodHandle modLoadingContextRegisterConfig;
private static MethodHandle forgeConfigRegistryRegister;
private static Object forgeConfigRegistryInstance;
Expand Down
11 changes: 0 additions & 11 deletions forge/src/main/java/dev/rdh/createunlimited/forge/UtilImpl.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dev.rdh.createunlimited.forge;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.rdh.createunlimited.CreateUnlimited;

import net.minecraft.commands.CommandSourceStack;

import net.minecraft.commands.synchronization.ArgumentTypeInfo;

import net.minecraft.commands.synchronization.ArgumentTypeInfos;
Expand All @@ -23,21 +20,13 @@
import net.minecraftforge.forgespi.language.IModInfo;
import net.minecraftforge.registries.RegistryObject;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static dev.rdh.createunlimited.multiversion.SupportedMinecraftVersion.*;

@SuppressWarnings({"UnstableApiUsage", "RedundantSuppression"})
public class UtilImpl {

static Set<LiteralArgumentBuilder<CommandSourceStack>> commands = new HashSet<>();

public static void registerCommand(LiteralArgumentBuilder<CommandSourceStack> command) {
commands.add(command);
}

public static void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
ModLoadingContext.get().registerConfig(type, spec);
}
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ archives_base_name = createunlimited
# compiler go brrrrr
manifold_version = 2024.1.1
strip_lvts = true
mixin.debug = false

# mixin
mixin_extras = 0.3.5
Expand Down

0 comments on commit e9b678d

Please sign in to comment.