Skip to content

Commit

Permalink
Initial Port
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Jul 11, 2024
1 parent c28943d commit b16cd09
Show file tree
Hide file tree
Showing 31 changed files with 380 additions and 285 deletions.
63 changes: 31 additions & 32 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ val githubUser: String by project
val githubRepo: String by project

plugins {
id("net.neoforged.gradle.userdev") version "7.0.97"
id("net.neoforged.moddev") version "1.0.1"
id("com.github.gmazzo.buildconfig") version "4.0.4"
java
}
Expand All @@ -32,7 +32,7 @@ base {
archivesName.set("$modId-neoforge")
}

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

val commonSystemProperties = mapOf(
"forge.logging.console.level" to logLevel,
Expand All @@ -41,22 +41,36 @@ val commonSystemProperties = mapOf(
"guideDev.ae2guide.sourcesNamespace" to modId
)

runs {
configureEach {
workingDirectory = project.file("run")
systemProperties = commonSystemProperties
modSource(sourceSets.main.get())
jvmArguments("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition")
neoForge {
version = neoVersion
mods {
create("merequester") {
modSourceSets.add(sourceSets.main)
}
}
runs {
configureEach {
gameDirectory = project.file("run")
systemProperties = commonSystemProperties
jvmArguments = listOf("-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AllowEnhancedClassRedefinition")
}

create("client") {
programArguments("--quickPlaySingleplayer", "New World")
create("client") {
client()
programArguments.addAll("--quickPlaySingleplayer", "New World")
}
create("guide") {
client()
systemProperty("guideDev.ae2guide.startupPage", "$modId:$modId.md")
}
create("server") {
server()
}
}
create("guide") {
configure("client")
systemProperty("guideDev.ae2guide.startupPage", "$modId:$modId.md")
parchment {
mappingsVersion = parchmentVersion
minecraftVersion = mcVersion
}
create("server")
}

repositories {
Expand All @@ -69,29 +83,20 @@ repositories {
}

dependencies {
// NeoForge
implementation("net.neoforged:neoforge:$neoVersion")

// Compile
compileOnly("appeng:appliedenergistics2-neoforge:$aeVersion")
implementation("appeng:appliedenergistics2:$aeVersion")

// Runtime
runtimeOnly("appeng:appliedenergistics2-neoforge:$aeVersion")
when (recipeViewer) {
"jei" -> runtimeOnly("mezz.jei:jei-$mcVersion-neoforge:$jeiVersion") { isTransitive = false }
"rei" -> {
runtimeOnly("me.shedaniel:RoughlyEnoughItems-neoforge:$reiVersion")
runtimeOnly("dev.architectury:architectury-neoforge:11.1.17") // TODO: Remove on new REI version
}

"rei" -> runtimeOnly("me.shedaniel:RoughlyEnoughItems-neoforge:$reiVersion")
"emi" -> runtimeOnly("dev.emi:emi-neoforge:$emiVersion+$mcVersion")
else -> throw GradleException("Invalid recipeViewer value: $recipeViewer")
}
}

tasks {
processResources {
val resourceTargets = listOf("META-INF/mods.toml", "pack.mcmeta")
val resourceTargets = listOf("META-INF/neoforge.mods.toml", "pack.mcmeta")

val replaceProperties = mapOf(
"license" to license,
Expand All @@ -118,7 +123,6 @@ tasks {

withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(17)
}

withType<Jar> {
Expand All @@ -132,11 +136,6 @@ tasks {
}
}

subsystems.parchment {
minecraftVersion(mcVersion)
mappingsVersion(parchmentVersion)
}

buildConfig {
buildConfigField("String", "MOD_ID", "\"$modId\"")
buildConfigField("String", "MOD_NAME", "\"$modName\"")
Expand Down
18 changes: 7 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mixinDebugExport = false
recipeViewer = jei

# Minecraft
mcVersion = 1.20.4
mcVersion = 1.21

# Mod
modVersion = 1.1.4
Expand All @@ -19,19 +19,15 @@ modAuthor = Almost Reliable
modDescription = Keep items and fluids in your ME-System in stock.

# Project Dependencies
neoVersion = 20.4.196
parchmentVersion = 2024.02.25
neoVersion = 21.0.86-beta
parchmentVersion = 2024.07.07

# Mod Dependencies
aeVersion = 17.10.4-beta
jeiVersion = 17.3.0.49
reiVersion = 14.0.688
emiVersion = 1.1.2
aeVersion = 19.0.8-alpha
jeiVersion = 19.5.0.30
reiVersion = 16.0.729
emiVersion = 1.1.7

# Github
githubUser = AlmostReliable
githubRepo = merequester

# Gradle
org.gradle.jvmargs = -Xmx3G
org.gradle.daemon = false
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.5-bin.zip
distributionUrl = https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase = GRADLE_USER_HOME
zipStorePath = wrapper/dists
6 changes: 3 additions & 3 deletions guidebook/merequester.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ navigation:
title: ME Requester
icon: requester
position: 100
item_ids:
- merequester:requester
- merequester:requester_terminal
item_ids:
- merequester:requester
- merequester:requester_terminal
---

# ME Requester
Expand Down
7 changes: 2 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
pluginManagement {
repositories {
maven("https://maven.neoforged.net/releases")
gradlePluginPortal()
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

val modName = extra.get("modName").toString().replace(" ", "-")
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/almostreliable/merequester/MERequester.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.almostreliable.merequester;

import com.almostreliable.merequester.data.MERequesterData;
import com.almostreliable.merequester.network.PacketHandler;
import com.mojang.logging.LogUtils;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
Expand All @@ -17,12 +19,13 @@ public final class MERequester {
public static final String REQUESTER_ID = "requester";
public static final String TERMINAL_ID = "requester_terminal";

public MERequester(IEventBus modEventBus) {
public MERequester(IEventBus modEventBus, ModContainer modContainer) {
modEventBus.addListener(MERequester::onRegistryEvent);
modEventBus.addListener(MERequester::onCreativeTabContents);
modEventBus.addListener(PacketHandler::onPacketRegistration);
MERequesterData.DR.register(modEventBus);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.COMMON_SPEC);
modContainer.registerConfig(ModConfig.Type.COMMON, Config.COMMON_SPEC);
}

private static void onRegistryEvent(RegisterEvent event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.almostreliable.merequester;

import appeng.init.client.InitScreens;
import com.almostreliable.merequester.client.RequesterScreen;
import com.almostreliable.merequester.client.RequesterTerminalScreen;
import com.almostreliable.merequester.requester.RequesterMenu;
import com.almostreliable.merequester.terminal.RequesterTerminalMenu;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;

@Mod(value = BuildConfig.MOD_ID, dist = Dist.CLIENT)
public final class MERequesterClient {

public MERequesterClient(IEventBus modEventBus) {
modEventBus.addListener(this::registerScreens);
}

private void registerScreens(RegisterMenuScreensEvent event) {
InitScreens.register(event, RequesterMenu.TYPE, RequesterScreen::new, String.format("/screens/%s.json", MERequester.REQUESTER_ID));
InitScreens.<RequesterTerminalMenu, RequesterTerminalScreen<RequesterTerminalMenu>> register(
event,
RequesterTerminalMenu.TYPE,
RequesterTerminalScreen::new,
String.format("/screens/%s.json", MERequester.TERMINAL_ID)
);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/almostreliable/merequester/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class Utils {
private Utils() {}

public static ResourceLocation getRL(String path) {
return new ResourceLocation(BuildConfig.MOD_ID, path);
return ResourceLocation.fromNamespaceAndPath(BuildConfig.MOD_ID, path);
}

public static int fillColorAlpha(ChatFormatting color) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public void setLocked(boolean locked) {

@Override
public void setFilterTo(ItemStack itemStack) {
PacketDistributor.SERVER.noArg().send(new DragAndDropPacket(getRequesterReference().getRequesterId(), getSlot(), itemStack));
PacketDistributor.sendToServer(new DragAndDropPacket(getRequesterReference().getRequesterId(), getSlot(), itemStack));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import appeng.client.gui.widgets.Scrollbar;
import appeng.core.localization.ButtonToolTips;
import appeng.core.localization.Tooltips;
import appeng.core.network.NetworkHandler;
import appeng.core.network.serverbound.InventoryActionPacket;
import appeng.helpers.InventoryAction;
import com.almostreliable.merequester.MERequester;
Expand All @@ -31,6 +30,7 @@
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.PacketDistributor;

import javax.annotation.Nullable;
import javax.annotation.OverridingMethodsMustInvokeSuper;
Expand Down Expand Up @@ -121,7 +121,7 @@ public void updateFromMenu(boolean clearData, long requesterId, CompoundTag data
for (var i = 0; i < requests.size(); i++) {
var requestIndex = String.valueOf(i);
if (data.contains(requestIndex)) {
requests.get(i).deserializeNBT(data.getCompound(requestIndex));
requests.get(i).deserializeNBT(menu.getPlayer().registryAccess(), data.getCompound(requestIndex));
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ protected void slotClicked(@Nullable Slot slot, int slotIndex, int mouseButton,
requestSlot.getSlot(),
requestSlot.getRequesterReference().getRequesterId()
);
NetworkHandler.instance().sendToServer(packet);
PacketDistributor.sendToServer(packet);
return;
}

Expand All @@ -254,7 +254,7 @@ protected void slotClicked(@Nullable Slot slot, int slotIndex, int mouseButton,
requestSlot.getSlot(),
requestSlot.getRequesterReference().getRequesterId()
);
NetworkHandler.instance().sendToServer(packet);
PacketDistributor.sendToServer(packet);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void stateBoxChanged(@Nullable Request request) {
var newState = stateBox.isSelected();
request.updateState(newState); // prevent jittery animation before server information is received
var requesterId = ((RequesterReference) request.getRequesterReference()).getRequesterId();
PacketDistributor.SERVER.noArg().send(new RequestUpdatePacket(requesterId, request.getIndex(), newState));
PacketDistributor.sendToServer(new RequestUpdatePacket(requesterId, request.getIndex(), newState));
}

private void amountFieldSubmitted(@Nullable Request request, long amount) {
Expand Down Expand Up @@ -134,7 +134,7 @@ private void submitButtonClicked(@Nullable Request request) {
long amount = amountField.getLongValue().orElse(0);
long batch = batchField.getLongValue().orElse(1);
var requesterId = ((RequesterReference) request.getRequesterReference()).getRequesterId();
PacketDistributor.SERVER.noArg().send(new RequestUpdatePacket(requesterId, request.getIndex(), amount, batch));
PacketDistributor.sendToServer(new RequestUpdatePacket(requesterId, request.getIndex(), amount, batch));
}

private boolean isInactive(@Nullable Request request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.almostreliable.merequester.data;

import com.almostreliable.merequester.BuildConfig;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.codec.ByteBufCodecs;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.List;
import java.util.function.Consumer;

public final class MERequesterData {

private MERequesterData() {}

public static final DeferredRegister<DataComponentType<?>> DR = DeferredRegister
.create(Registries.DATA_COMPONENT_TYPE, BuildConfig.MOD_ID);

public static final DataComponentType<List<MERequesterRequest>> EXPORTED_REQUESTER_REQUESTS = register("exported_requests", builder -> {
builder.persistent(MERequesterRequest.CODEC.listOf())
.networkSynchronized(MERequesterRequest.STREAM_CODEC.apply(ByteBufCodecs.list()));
});

private static <T> DataComponentType<T> register(String name, Consumer<DataComponentType.Builder<T>> customizer) {
var builder = DataComponentType.<T> builder();
customizer.accept(builder);
var componentType = builder.build();
DR.register(name, () -> componentType);
return componentType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.almostreliable.merequester.data;

import appeng.api.stacks.AEKey;
import com.almostreliable.merequester.requester.status.RequestStatus;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

import java.util.Optional;

public record MERequesterRequest(
boolean state,
Optional<AEKey> key,
long amount,
long batch,
RequestStatus clientStatus
) {

public static final Codec<MERequesterRequest> CODEC = RecordCodecBuilder.create(builder -> builder.group(
Codec.BOOL.fieldOf("state").forGetter(MERequesterRequest::state),
Codec.optionalField("key", AEKey.CODEC, false).forGetter(MERequesterRequest::key),
Codec.LONG.fieldOf("amount").forGetter(MERequesterRequest::amount),
Codec.LONG.fieldOf("batch").forGetter(MERequesterRequest::batch),
RequestStatus.CODEC.fieldOf("client_status").forGetter(MERequesterRequest::clientStatus)
).apply(builder, MERequesterRequest::new));

public static final StreamCodec<RegistryFriendlyByteBuf, MERequesterRequest> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.BOOL, MERequesterRequest::state,
ByteBufCodecs.optional(AEKey.STREAM_CODEC), MERequesterRequest::key,
ByteBufCodecs.VAR_LONG, MERequesterRequest::amount,
ByteBufCodecs.VAR_LONG, MERequesterRequest::batch,
RequestStatus.STREAM_CODEC, MERequesterRequest::clientStatus,
MERequesterRequest::new
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
package com.almostreliable.merequester.data;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Loading

0 comments on commit b16cd09

Please sign in to comment.