Skip to content

Commit

Permalink
remove duplicate classes or something
Browse files Browse the repository at this point in the history
doesnt work on forge yet
  • Loading branch information
rhysdh540 committed Oct 13, 2023
1 parent 56cf270 commit 82e50c6
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 64 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ setup()
def modVersion = mod_version + (build_number != null ? "-build.${build_number}" : "")

forgix {
group = maven_group
mergedJarName = "createunlimited-${modVersion}+mc${minecraft_version}.jar"
group = maven_group
mergedJarName = "createunlimited-${modVersion}+mc${minecraft_version}.jar"
outputDir = 'build/libs/merged'

removeDuplicate 'dev.rdh.createunlimited'
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
public class CreateUnlimited {
public static final String ID = "createunlimited";
public static final String NAME = "Create Unlimited";
public static final String VERSION = Util.getVersion().split("-")[0];
public static final String VERSION = Utils.getVersion().split("-")[0];
public static final Logger LOGGER = LoggerFactory.getLogger(NAME);

public static void init() {
LOGGER.info("{} v{} initializing! Create version: {} on platform: {}",
NAME, VERSION, Create.VERSION, Util.platformName());
NAME, VERSION, Create.VERSION, Utils.platformName());

EnumArgument.init();
CUConfigs.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import dev.architectury.injectables.annotations.ExpectPlatform;

import dev.rdh.createunlimited.config.CUConfigs;

import net.minecraft.commands.CommandSourceStack;
Expand All @@ -30,62 +28,47 @@

import manifold.rt.api.NoBootstrap;

/**
* A word about {@code @ExpectPlatform}:<p>
* When using Forgix's {@code removeDuplicate} configuration, any ExpectPlatform-ed methods will <i>always</i> call theyr fabric implementation. To solve this, we have to overwrite these methods at runtime depending on the loader we are on.
*/
@NoBootstrap
public class Util {
@SuppressWarnings("unused")
public class Utils {

@ExpectPlatform
public static String getVersion() {
throw new AssertionError();
}

@ExpectPlatform
public static boolean isDevEnv() {
throw new AssertionError();
}

@ExpectPlatform
public static String platformName() {
throw new AssertionError();
}

@ExpectPlatform
public static Path getConfigDirectory() {
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();
}

@ExpectPlatform
public static <A extends ArgumentType<?>, T extends ArgumentTypeInfo.Template<A>, I extends ArgumentTypeInfo<A, T>>
void registerArgument(String name, Class<A> clazz, I info, ResourceLocation id) {
void registerArgument(Class<A> clazz, I info, ResourceLocation id) {
throw new AssertionError();
}

@ExpectPlatform
public static Attribute getReachAttribute() {
throw new AssertionError();
}

public static boolean isFabric() {
return platformName().equals("Fabric") || isQuilt();
}

public static boolean isForge() {
return platformName().equals("Forge");
}

public static boolean isQuilt() {
return platformName().equals("Quilt");
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.simibubi.create.foundation.config.ConfigBase;
import com.simibubi.create.foundation.config.ui.BaseConfigScreen;

import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.Utils;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void register() {
register(CUServer::new, SERVER);

for(var pair : CONFIGS.entrySet())
Util.registerConfig(pair.getKey(), pair.getValue().specification);
Utils.registerConfig(pair.getKey(), pair.getValue().specification);
}

public static void onLoad(ModConfig modConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.simibubi.create.foundation.config.ConfigBase.*;
import com.simibubi.create.foundation.utility.Components;

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

Expand Down Expand Up @@ -112,15 +112,14 @@ else if (value instanceof DoubleValue dValue)

}

if(Util.isDevEnv()) {
if(Utils.isDevEnv()) {
base.then(literal("disableEverything").requires(CUCommands::perms).executes(context -> {
CUConfigs.server().placementChecks.set(CUServer.PlacementCheck.OFF);
CUConfigs.server().extendedDriving.set(0.01);
CUConfigs.server().maxTrainRelocationDistance.set(128d);
CUConfigs.server().maxAllowedStress.set(-1d);
CUConfigs.server().trainAssemblyChecks.set(false);
CUConfigs.server().maxGlueConnectionRange.set(128d);
//CUConfigs.server().physicalBlockConnection.set(false);
CUConfigs.server().singleExtendoGripRange.set(128);
CUConfigs.server().doubleExtendoGripRange.set(128);
CUConfigs.server().allowAllCopycatBlocks.set(true);
Expand All @@ -132,7 +131,7 @@ else if (value instanceof DoubleValue dValue)

if (category != null)
base.then(category);
Util.registerCommand(base);
Utils.registerCommand(base);
}

private static boolean perms(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.mojang.brigadier.suggestion.SuggestionsBuilder;

import dev.rdh.createunlimited.CreateUnlimited;
import dev.rdh.createunlimited.Util;
import dev.rdh.createunlimited.Utils;

import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.SharedSuggestionProvider;
Expand Down Expand Up @@ -46,7 +46,7 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
private final boolean lowercase;

public static void init() {
Util.registerArgument("enumargument", EnumArgument.class, new EnumArgument.Info(), CreateUnlimited.asResource("enumargument"));
Utils.registerArgument(EnumArgument.class, new EnumArgument.Info(), CreateUnlimited.asResource("enumargument"));
}

public static <R extends Enum<R>> EnumArgument<R> enumArg(Class<R> enumClass, boolean lowercase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import manifold.rt.api.NoBootstrap;

import static dev.rdh.createunlimited.Util.doubleRange;
import static dev.rdh.createunlimited.Util.singleRange;
import static dev.rdh.createunlimited.Utils.doubleRange;
import static dev.rdh.createunlimited.Utils.singleRange;

@NoBootstrap
@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.simibubi.create.content.trains.track.TrackPlacement.PlacementInfo;
import com.simibubi.create.infrastructure.config.AllConfigs;

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

import dev.rdh.createunlimited.duck.PlacementInfoDuck;
Expand Down Expand Up @@ -216,7 +216,7 @@ public static PlacementInfo tryConnect(Level level, Player player, BlockPos pos2
info.end2Extent = 0;

Direction.Axis plane = Mth.equal(axis1.x, 0) ? Direction.Axis.X : Direction.Axis.Z;
intersect = Util.intersect(end1, end2, normedAxis1, normedAxis2, plane);
intersect = Utils.intersect(end1, end2, normedAxis1, normedAxis2, plane);
double dist1 = Math.abs(intersect[0] / axis1.length());
double dist2 = Math.abs(intersect[1] / axis2.length());

Expand Down Expand Up @@ -276,7 +276,7 @@ public static PlacementInfo tryConnect(Level level, Player player, BlockPos pos2
return info.withMessage("turn_90")
.tooJumbly();

intersect = Util.intersect(end1, end2, normedAxis1, normedAxis2, Direction.Axis.Y);
intersect = Utils.intersect(end1, end2, normedAxis1, normedAxis2, Direction.Axis.Y);
double dist1 = Math.abs(intersect[0]);
double dist2 = Math.abs(intersect[1]);
float ex1 = 0;
Expand Down Expand Up @@ -388,7 +388,7 @@ else if (j == inv.selected)
count - Math.min(isTrack ? tracks - foundTracks : pavement - foundPavement, count);
if (i == inv.selected)
stackInSlot.setTag(null);
ItemStack newItem = Util.copyStackWithSize(stackInSlot, remainingItems);
ItemStack newItem = Utils.copyStackWithSize(stackInSlot, remainingItems);
if (offhand)
player.setItemInHand(InteractionHand.OFF_HAND, newItem);
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.rdh.createunlimited.fabric;
package dev.rdh.createunlimited.fabric.mixin;

import com.jamieswhiteshirt.reachentityattributes.ReachEntityAttributes;

Expand All @@ -8,6 +8,8 @@

import dev.rdh.createunlimited.CreateUnlimited;

import dev.rdh.createunlimited.*;

import manifold.rt.api.NoBootstrap;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
Expand All @@ -31,17 +33,25 @@

import java.nio.file.Path;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

@SuppressWarnings("OverwriteAuthorRequired")
@NoBootstrap
public class UtilImpl {
@Mixin(Utils.class)
public class UtilsFabricImpl {

@Overwrite
public static Path getConfigDirectory() {
return FabricLoader.getInstance().getConfigDir();
}

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

@Overwrite
public static void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
#if PRE_CURRENT_MC_1_19_2
ModLoadingContext.registerConfig(CreateUnlimited.ID, type, spec);
Expand All @@ -50,28 +60,33 @@ public static void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
#endif
}

@Overwrite
public static <A extends ArgumentType<?>, T extends ArgumentTypeInfo.Template<A>, I extends ArgumentTypeInfo<A, T>>
void registerArgument(String name, Class<A> clazz, I info, ResourceLocation id) {
void registerArgument(Class<A> clazz, I info, ResourceLocation id) {
ArgumentTypeRegistry.registerArgumentType(id, clazz, info);
}

@Overwrite
public static String getVersion() {
return FabricLoader.getInstance()
.getModContainer(CreateUnlimited.ID)
.orElseThrow()
.getMetadata()
.getVersion()
.getFriendlyString();
.getModContainer(CreateUnlimited.ID)
.orElseThrow()
.getMetadata()
.getVersion()
.getFriendlyString();
}

@Overwrite
public static boolean isDevEnv() {
return FabricLoader.getInstance().isDevelopmentEnvironment();
}

@Overwrite
public static Attribute getReachAttribute() {
return ReachEntityAttributes.REACH;
}

@Overwrite
public static String platformName() {
return FabricLoader.getInstance().isModLoaded("quilt_loader") ? "Quilt" : "Fabric";
}
Expand Down
1 change: 1 addition & 0 deletions fabric/src/main/resources/createunlimited.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_17",
"client": [],
"mixins": [
"UtilsFabricImpl"
],
"injectors": {
"defaultRequire": 1
Expand Down
20 changes: 17 additions & 3 deletions forge/src/main/java/dev/rdh/createunlimited/forge/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

import dev.rdh.createunlimited.config.CUConfigs;

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

import manifold.rt.api.NoBootstrap;

import net.minecraft.commands.CommandSourceStack;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;

import com.mojang.brigadier.builder.LiteralArgumentBuilder;

import org.jetbrains.annotations.ApiStatus;

@NoBootstrap
public abstract class Events {

@ApiStatus.Internal
public static Set<LiteralArgumentBuilder<CommandSourceStack>> commands = new HashSet<>();

@NoBootstrap
@Mod.EventBusSubscriber(modid = CreateUnlimited.ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
@EventBusSubscriber(modid = CreateUnlimited.ID, bus = Bus.MOD, value = Dist.CLIENT)
public static abstract class ClientModBusEvents {
@SubscribeEvent
static void onLoadComplete(FMLLoadCompleteEvent event) {
Expand All @@ -33,7 +47,7 @@ static void onLoadComplete(FMLLoadCompleteEvent event) {

@SubscribeEvent
static void registerCommands(RegisterCommandsEvent event) {
for(var command : UtilImpl.commands)
for(var command : commands)
event.getDispatcher().register(command);
}
}
Loading

0 comments on commit 82e50c6

Please sign in to comment.