Skip to content

Commit

Permalink
Initial ObserverLib update
Browse files Browse the repository at this point in the history
Signed-off-by: HellFirePvP <[email protected]>
  • Loading branch information
HellFirePvP committed Dec 10, 2024
1 parent b3f021c commit 484d8eb
Show file tree
Hide file tree
Showing 49 changed files with 628 additions and 1,556 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- '1.20.4'
- '1.21.3'

#echo "$(${{github.workspace}}/gradlew printVersion -q | awk -F "version:" '{printf $2}')"
jobs:
Expand Down
43 changes: 32 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.80'
id 'net.neoforged.gradle.userdev' version '7.0.145'
}

tasks.named('wrapper', Wrapper).configure {
distributionType = Wrapper.DistributionType.BIN
}

version = mod_version + getGHActionVersionSuffix()
Expand All @@ -17,8 +21,7 @@ base {
archivesName = mod_id
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))

minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')
Expand Down Expand Up @@ -51,25 +54,36 @@ runs {

sourceSets.main.resources { srcDir 'src/generated/resources' }

configurations {
runtimeClasspath.extendsFrom localRuntime
}

dependencies {
implementation "net.neoforged:neoforge:${neo_version}"
}

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,
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']) {
expand replaceProperties + [project: project]
filesMatching(['META-INF/neoforge.mods.toml']) {
expand replaceProperties
}
}

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
register('mavenJava', MavenPublication) {
Expand Down Expand Up @@ -103,4 +117,11 @@ tasks.register('printVersion') {
doLast {
println("version:" + project.version)
}
}
}

idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
21 changes: 10 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ org.gradle.jvmargs=-Xmx4G
org.gradle.daemon=false
org.gradle.debug=false

neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
neogradle.subsystems.parchment.minecraftVersion=1.21
neogradle.subsystems.parchment.mappingsVersion=2024.11.10

minecraft_version=1.20.4
minecraft_version_range=[1.20.4,1.21)
neo_version=20.4.80-beta
neo_version_range=[20.4,)
loader_version_range=[2,)
minecraft_version=1.21
minecraft_version_range=[1.21,1.21.1)
neo_version=21.0.167
neo_version_range=[21.0.0-beta,)
loader_version_range=[4,)

## Mod Properties
mod_id=observerlib
mod_name=ObserverLib
mod_license=GNU Lesser General Public License v3.0
mod_version=1.8.0
mod_license=All Rights Reserved
mod_version=1.9.0
mod_group_id=hellfirepvp.observerlib
mod_authors=HellFirePvP
mod_description=Cached world structure and change monitoring library.
mod_description=Cached world structure and change monitoring library.
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.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
34 changes: 21 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,10 +85,9 @@ 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +134,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 +201,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
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,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 +59,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'
}
2 changes: 1 addition & 1 deletion src/main/java/hellfirepvp/observerlib/ObserverLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public static ObserverLib getInstance() {
}

public static ResourceLocation key(String path) {
return new ResourceLocation(ObserverLib.MODID, path);
return ResourceLocation.fromNamespaceAndPath(MODID, path);
}
}
41 changes: 11 additions & 30 deletions src/main/java/hellfirepvp/observerlib/api/ChangeObserver.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package hellfirepvp.observerlib.api;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import hellfirepvp.observerlib.api.block.BlockChangeSet;
import hellfirepvp.observerlib.common.registry.RegistryProviders;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.Level;
Expand All @@ -22,24 +24,18 @@
* Created by HellFirePvP
* Date: 23.04.2019 / 22:15
*/
public abstract class ChangeObserver {
public abstract class ChangeObserver<T extends ChangeObserver<T>> {

private final ResourceLocation providerRegistryName;

public ChangeObserver(ResourceLocation providerRegistryName) {
this.providerRegistryName = providerRegistryName;
}
public static final Codec<ChangeObserver<?>> CODEC = RegistryProviders.getRegistry().byNameCodec()
.flatXmap(provider -> DataResult.<ChangeObserver<?>>success(provider.newObserver()),
observer -> DataResult.success(observer.getProvider()));

/**
* Returns the registry name of the owning {@link ObserverProvider}.
* Used for serialization/deserialization so the observer can be saved persistently.
* Get the provider for this change observer
*
* @return the changeprovider's registry name
* @return the provider
*/
@Nonnull
public final ResourceLocation getProviderRegistryName() {
return providerRegistryName;
}
public abstract ObserverProvider<T> getProvider();

/**
* Called once after the observer is newly set on a position to observe it.
Expand Down Expand Up @@ -78,19 +74,4 @@ public final ResourceLocation getProviderRegistryName() {
*/
public abstract boolean notifyChange(Level world, BlockPos center, BlockChangeSet changeSet);

/**
* Read persistent information back into this observer.
*
* @param tag the tag holding persistent information about this observer
*/
public abstract void readFromNBT(CompoundTag tag);

/**
* Write information of this observer for persistence.
* The tag passed here is empty and will not be further modified after this method before being saved.
*
* @param tag an empty TagCompound to write information into
*/
public abstract void writeToNBT(CompoundTag tag);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Created by HellFirePvP
* Date: 26.04.2019 / 22:31
*/
public interface ChangeSubscriber<T extends ChangeObserver> {
public interface ChangeSubscriber<T extends ChangeObserver<T>> {

/**
* The current observer this subscriber is forwarding relevant changes to.
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/hellfirepvp/observerlib/api/ObserverHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.registries.DeferredBlock;
import net.neoforged.neoforge.registries.DeferredHolder;

import javax.annotation.Nonnull;
Expand All @@ -26,7 +27,7 @@ public abstract class ObserverHelper {
*
* Does not have a corresponding BlockItem and tries to remove itself when placed in world.
*/
public static DeferredHolder<Block, Block> blockAirRequirement;
public static DeferredBlock<Block> blockAirRequirement;

/**
* Retrieve the current API instance using this getter.
Expand Down Expand Up @@ -58,7 +59,7 @@ public static void setHelper(ObserverHelper helperInstance) {
* offset already exists in that world at that position
*/
@Nonnull
public abstract <T extends ChangeObserver> ChangeSubscriber<T> observeArea(Level world, BlockPos center, ObserverProvider provider);
public abstract <T extends ChangeObserver<T>> ChangeSubscriber<T> observeArea(Level world, BlockPos center, ObserverProvider<T> provider);

/**
* Removes an observer at the given world + position combination.
Expand All @@ -79,6 +80,6 @@ public static void setHelper(ObserverHelper helperInstance) {
* @return the observation subscriber at that position or null if none is found there
*/
@Nullable
public abstract ChangeSubscriber<? extends ChangeObserver> getSubscriber(Level world, BlockPos pos);
public abstract ChangeSubscriber<? extends ChangeObserver<?>> getSubscriber(Level world, BlockPos pos);

}
Loading

0 comments on commit 484d8eb

Please sign in to comment.