Skip to content

Commit

Permalink
Update to NeoForge 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCzyr committed May 4, 2024
1 parent dbc56ca commit 34ed69a
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 194 deletions.
44 changes: 33 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.57'
id 'net.neoforged.gradle.userdev' version '7.0.97'
}

version = mod_version
Expand Down Expand Up @@ -72,6 +72,13 @@ runs {
// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

// Sets up a dependency configuration called 'localRuntime'.
// This configuration should be used instead of 'runtimeOnly' to declare
// a dependency that will be present for runtime testing but that is
// "optional", meaning it will not be pulled by dependents of this mod.
configurations {
runtimeClasspath.extendsFrom localRuntime
}

dependencies {
// Specify the version of Minecraft to use.
Expand All @@ -82,11 +89,12 @@ dependencies {
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
implementation "net.neoforged:neoforge:${neo_version}"

// Example mod dependency with JEI
// Example optional mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}"
// runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
Expand All @@ -110,16 +118,22 @@ dependencies {
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
neo_version : neo_version, neo_version_range: neo_version_range,
loader_version_range: loader_version_range,
mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors : mod_authors, mod_description: mod_description, pack_format_number: pack_format_number,
minecraft_version : minecraft_version,
minecraft_version_range: minecraft_version_range,
neo_version : neo_version,
neo_version_range : neo_version_range,
loader_version_range : loader_version_range,
mod_id : mod_id,
mod_name : mod_name,
mod_license : mod_license,
mod_version : mod_version,
mod_authors : mod_authors,
mod_description : mod_description
]
inputs.properties replaceProperties

filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
filesMatching(['META-INF/mods.toml']) {
expand replaceProperties
}
}

Expand All @@ -140,3 +154,11 @@ publishing {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}

// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
26 changes: 15 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
org.gradle.daemon=false
org.gradle.debug=false

## Environment Properties

#read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.20.2
minecraft_version=1.20.4
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.2,1.21)
minecraft_version_range=[1.20.4,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.2.86
# The Neo version range can use any version of Neo as bounds or match the loader version range
neo_version_range=[20.2,)
# The loader version range can only use the major version of Neo/FML as bounds
loader_version_range=[1,)
neo_version=20.4.147-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[20.4,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[2,)

## Mod Properties

Expand All @@ -28,7 +32,7 @@ mod_name=Nature's Compass
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=CC BY-NC-SA 4.0
# The mod version. See https://semver.org/
mod_version=1.20.2-3.0.0-neoforge
mod_version=1.20.4-3.0.0-neoforge
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand All @@ -38,4 +42,4 @@ mod_authors=ChaosTheDude
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Search for a biome and get information about it.
# Pack version - this changes each minecraft release, in general.
pack_format_number=18
pack_format_number=18
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
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"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ 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.
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=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | 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=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# 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
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# 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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pluginManagement {
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
34 changes: 16 additions & 18 deletions src/main/java/com/chaosthedude/naturescompass/NaturesCompass.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.chaosthedude.naturescompass.config.ConfigHandler;
import com.chaosthedude.naturescompass.items.NaturesCompassItem;
import com.chaosthedude.naturescompass.network.CompassSearchPacket;
import com.chaosthedude.naturescompass.network.SearchPacket;
import com.chaosthedude.naturescompass.network.SyncPacket;
import com.chaosthedude.naturescompass.network.TeleportPacket;
import com.google.common.collect.ArrayListMultimap;
Expand All @@ -17,16 +17,17 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.network.NetworkRegistry.ChannelBuilder;
import net.neoforged.neoforge.network.simple.SimpleChannel;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
import net.neoforged.neoforge.server.permission.events.PermissionGatherEvent;
import net.neoforged.neoforge.server.permission.nodes.PermissionNode;
import net.neoforged.neoforge.server.permission.nodes.PermissionTypes;
Expand All @@ -40,7 +41,6 @@ public class NaturesCompass {

public static final Logger LOGGER = LogManager.getLogger(MODID);

public static SimpleChannel network;
public static NaturesCompassItem naturesCompass;

public static boolean canTeleport;
Expand All @@ -49,11 +49,12 @@ public class NaturesCompass {

public static NaturesCompass instance;

public NaturesCompass() {
public NaturesCompass(IEventBus bus, Dist dist) {
instance = this;

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::preInit);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::buildCreativeTabContents);
bus.addListener(this::preInit);
bus.addListener(this::buildCreativeTabContents);
bus.addListener(this::registerPayloads);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigHandler.GENERAL_SPEC);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigHandler.CLIENT_SPEC);
Expand All @@ -62,16 +63,6 @@ public NaturesCompass() {
}

private void preInit(FMLCommonSetupEvent event) {
String networkVersion = "1";
network = ChannelBuilder.named(new ResourceLocation(NaturesCompass.MODID, NaturesCompass.MODID)).networkProtocolVersion(() -> networkVersion).clientAcceptedVersions(networkVersion::equals).serverAcceptedVersions(networkVersion::equals).simpleChannel();

// Server packets
network.messageBuilder(CompassSearchPacket.class, 0).encoder(CompassSearchPacket::toBytes).decoder(CompassSearchPacket::new).consumerMainThread(CompassSearchPacket::handle).add();
network.messageBuilder(TeleportPacket.class, 1).encoder(TeleportPacket::toBytes).decoder(TeleportPacket::new).consumerMainThread(TeleportPacket::handle).add();

// Client packet
network.messageBuilder(SyncPacket.class, 2).encoder(SyncPacket::toBytes).decoder(SyncPacket::new).consumerMainThread(SyncPacket::handle).add();

allowedBiomes = new ArrayList<ResourceLocation>();
dimensionKeysForAllowedBiomeKeys = ArrayListMultimap.create();
}
Expand All @@ -81,6 +72,13 @@ private void buildCreativeTabContents(BuildCreativeModeTabContentsEvent event) {
event.accept(new ItemStack(naturesCompass));
}
}

private void registerPayloads(RegisterPayloadHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(MODID);
registrar.play(SearchPacket.ID, SearchPacket::read, handler -> handler.server(SearchPacket::handle));
registrar.play(TeleportPacket.ID, TeleportPacket::read, handler -> handler.server(TeleportPacket::handle));
registrar.play(SyncPacket.ID, SyncPacket::read, handler -> handler.client(SyncPacket::handle));
}

@SubscribeEvent
public void registerNodes(PermissionGatherEvent.Nodes event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class BiomeSearchList extends ObjectSelectionList<BiomeSearchEntry> {

private final NaturesCompassScreen parentScreen;

public BiomeSearchList(NaturesCompassScreen parentScreen, Minecraft mc, int width, int height, int top, int bottom, int slotHeight) {
super(mc, width, height, top, bottom, slotHeight);
public BiomeSearchList(NaturesCompassScreen parentScreen, Minecraft mc, int width, int height, int y, int itemHeight) {
super(mc, width, height, y, itemHeight);
this.parentScreen = parentScreen;
refreshList();
}
Expand All @@ -37,7 +37,7 @@ protected boolean isSelectedItem(int slotIndex) {
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
renderList(guiGraphics, mouseX, mouseY, partialTicks);
}

Expand All @@ -46,10 +46,10 @@ protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float
for (int i = 0; i < getItemCount(); ++i) {
int top = getRowTop(i);
int bottom = getRowBottom(i);
if (bottom >= y0 && top <= y1) {
if (bottom >= getY() && top <= getBottom()) {
BiomeSearchEntry entry = getEntry(i);
if (isSelectedItem(i)) {
final int insideLeft = x0 + width / 2 - getRowWidth() / 2 + 2;
final int insideLeft = getX() + width / 2 - getRowWidth() / 2 + 2;
guiGraphics.fill(insideLeft - 4, top - 4, insideLeft + getRowWidth() + 4, top + itemHeight, 255 / 2 << 24);
}
entry.render(guiGraphics, i, top, getRowLeft(), getRowWidth(), itemHeight - 4, mouseX, mouseY, isMouseOver((double) mouseX, (double) mouseY) && Objects.equals(getEntryAtPosition((double) mouseX, (double) mouseY), entry), partialTicks);
Expand All @@ -59,14 +59,14 @@ protected void renderList(GuiGraphics guiGraphics, int mouseX, int mouseY, float
if (getMaxScroll() > 0) {
int left = getScrollbarPosition();
int right = left + 6;
int height = (int) ((float) ((y1 - y0) * (y1 - y0)) / (float) getMaxPosition());
height = Mth.clamp(height, 32, y1 - y0 - 8);
int top = (int) getScrollAmount() * (y1 - y0 - height) / getMaxScroll() + y0;
if (top < y0) {
top = y0;
int height = (int) ((float) ((getBottom() - getY()) * (getBottom() - getY())) / (float) getMaxPosition());
height = Mth.clamp(height, 32, getBottom() - getY() - 8);
int top = (int) getScrollAmount() * (getBottom() - getY() - height) / getMaxScroll() + getY();
if (top < getY()) {
top = getY();
}

guiGraphics.fill(left, y0, right, y1, (int) (2.35F * 255.0F) / 2 << 24);
guiGraphics.fill(left, getY(), right, getBottom(), (int) (2.35F * 255.0F) / 2 << 24);
guiGraphics.fill(left, top, right, top + height, (int) (1.9F * 255.0F) / 2 << 24);
}
}
Expand Down
Loading

0 comments on commit 34ed69a

Please sign in to comment.