Compare commits

..
1 Commits
Author SHA1 Message Date
Martin Robertz cf0743435e update gradle
update deps
sa
remove not use action scripts
2023-12-09 17:08:47 +01:00
33 changed files with 2091 additions and 808 deletions

No files matched your search

+5 -6
View File
@@ -4,7 +4,7 @@ This API provides a suite of tools for transforming blocks and items in the game
## Features
1. **Tile Entity Transformation**: Replace or modify tile entities.
1. **Tile Entity Transformation**: Replace or modify Tile Entities in the game.
2. **Block Replacement**: Replace normal blocks with another normal block.
3. **ItemStack Replacement**: Modify or replace items.
@@ -12,7 +12,7 @@ This API provides a suite of tools for transforming blocks and items in the game
### 1. Tile Entity Transformation
#### a. We provide the registered TE ID "GT_TileEntity_Ores" and a lambda function that takes in the NBTTagCompound for any matching tile entity in world and a World and returns a BlockInfo. This will replace all TE's with the ID "GT_TileEntity_Ores" with the block specified in the BlockInfo. The secondary parameter determines the damage value of the block. Returning null instead of a BlockInfo will leave the existing tile and block totally unchanged.
#### a. We provide the registered TE ID "GT_TileEntity_Ores" and a lambda function that takes in the NBTTagCompound for any matching tile entity in world and a World and returns a BlockInfo. This will replace all TE's with the ID "GT_TileEntity_Ores" with the block specified in the BlockInfo. The secondary parameter determines the damage value of the block.
```java
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> {
@@ -29,7 +29,7 @@ TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, w
#### b. We do the same here, but now we convert a Furnace TE to a chest TE. We also need to convert the underlying block to a chest. In addtion to this we can provide a transformer that can edit the NBTTagCompound of the TE. This is useful for converting NBT data from one format to another. Here we simply edit the NBT to place stone in the middle slot.
```java
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world) -> {
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
});
@@ -58,7 +58,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
#### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks.
```java
BiFunction<BlockConversionInfo, World, BlockConversionInfo> blockTransformer = (blockConversionInfoOld, world) -> {
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
@@ -83,8 +83,7 @@ BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer)
```java
Function<NBTTagCompound, NBTTagCompound> itemTransformer = (tag) -> {
// Use the utility method for compatibility with NEID/EndlessIDs
IDExtenderCompat.setItemStackID(tag, Item.getIdFromItem(Items.gold_ingot));
tag.setShort("id", (short) Item.getIdFromItem(Items.gold_ingot));
return tag;
};
+1606 -3
View File
File diff suppressed because it is too large. Load diff
+38 -5
View File
@@ -1,7 +1,40 @@
/*
* Add your dependencies here. Supported configurations:
* - api("group:name:version:classifier"): if you use the types from this dependency in the public API of this mod
* Available at runtime and compiletime for mods depending on this mod
* - implementation("g:n:v:c"): if you need this for internal implementation details of the mod, but none of it is visible via the public API
* Available at runtime but not compiletime for mods depending on this mod
* - compileOnly("g:n:v:c"): if the mod you're building doesn't need this dependency during runtime at all, e.g. for optional mods
* Not available at all for mods depending on this mod, only visible at compiletime for this mod
* - compileOnlyApi("g:n:v:c"): like compileOnly, but also visible at compiletime for mods depending on this mod
* Available at compiletime but not runtime for mods depending on this mod
* - runtimeOnlyNonPublishable("g:n:v:c"): if you want to include a mod in this mod's runClient/runServer runs, but not publish it as a dependency
* Not available at all for mods depending on this mod, only visible at runtime for this mod
* - devOnlyNonPublishable("g:n:v:c"): a combination of runtimeOnlyNonPublishable and compileOnly for dependencies present at both compiletime and runtime,
* but not published as Maven dependencies - useful for RFG-deobfuscated dependencies or local testing
* - runtimeOnly("g:n:v:c"): if you don't need this at compile time, but want it to be present at runtime
* Available at runtime for mods depending on this mod
* - annotationProcessor("g:n:v:c"): mostly for java compiler plugins, if you know you need this, use it, otherwise don't worry
* - testCONFIG("g:n:v:c") - replace CONFIG by one of the above (except api), same as above but for the test sources instead of main
*
* - shadowImplementation("g:n:v:c"): effectively the same as API, but the dependency is included in your jar under a renamed package name
* Requires you to enable usesShadowedDependencies in gradle.properties
*
* - compile("g:n:v:c"): deprecated, replace with "api" (works like the old "compile") or "implementation" (can be more efficient)
*
* You can exclude transitive dependencies (dependencies of the chosen dependency) by appending { transitive = false } if needed,
* but use this sparingly as it can break using your mod as another mod's dependency if you're not careful.
*
* To depend on obfuscated jars you can use `devOnlyNonPublishable(rfg.deobf("dep:spec:1.2.3"))` to fetch an obfuscated jar from maven,
* or `devOnlyNonPublishable(rfg.deobf(project.files("libs/my-mod-jar.jar")))` to use a file.
*
* Gradle names for some of the configuration can be misleading, compileOnlyApi and runtimeOnly both get published as dependencies in Maven, but compileOnly does not.
* The buildscript adds runtimeOnlyNonPublishable to also have a runtime dependency that's not published.
*
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.7:dev')
compileOnly('com.falsepattern:chunkapi-mc1.7.10:0.6.0:dev')
compileOnly('com.falsepattern:endlessids-mc1.7.10:1.6.0:dev')
// api("net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev")
// api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.104:dev')
api('com.github.GTNewHorizons:NotEnoughIds:1.5.3:dev')
}
+48 -99
View File
@@ -1,109 +1,77 @@
# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable.
# LOCAL to test local config updates.
gtnh.settings.blowdryerTag = 0.2.2
# Human-readable mod name, available for mcmod.info population.
modName = Postea
# Case-sensitive identifier string, available for mcmod.info population and used for automatic mixin JSON generation.
# Conventionally lowercase.
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
modId = postea
# Root package of the mod, used to find various classes in other properties,
# mcmod.info substitution, enabling assertions in run tasks, etc.
modGroup = com.gtnewhorizons.postea
modGroup = com.colen.postea
# Whether to use modGroup as the maven publishing group.
# When false, com.github.GTNewHorizons is used.
useModGroupForPublishing = false
# WHY is there no version field?
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
# Will update your build.gradle automatically whenever an update is available
autoUpdateBuildScript = false
# Version of Minecraft to target
minecraftVersion = 1.7.10
# Version of Minecraft Forge to target
forgeVersion = 10.13.4.1614
# Specify an MCP channel for dependency deobfuscation and the deobfParams task.
# Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task.
channel = stable
# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task.
mappingsVersion = 12
# Defines other MCP mappings for dependency deobfuscation.
remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
# Define other MCP mappings for dependency deobfuscation
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
# Select a default username for testing your mod. You can always override this per-run by running
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
# restart Minecraft in development. Choose this dependent on your mod:
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
developmentEnvironmentUserName = Developer
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# Enables using modern java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = true
# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
# Enables injecting missing generics into the decompiled source code for a better coding experience
# Turns most publicly visible List, Map, etc. into proper List<Type>, Map<K, V> types
enableGenericInjection = false
# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass = com.gtnewhorizons.postea.Tags
# Name of the token containing the project's current version to generate/replace.
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
generateGradleTokenClass = com.colen.postea.Tags
gradleTokenModId = MODID
gradleTokenModName = MODNAME
gradleTokenVersion = VERSION
# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
# [DEPRECATED] Mod name replacement token.
gradleTokenModName =
# [DEPRECATED] Mod Group replacement token.
gradleTokenGroupName =
gradleTokenGroupName = GROUPNAME
# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
# version in @Mod([...], version = VERSION, [...])
# Leave these properties empty to skip individual token replacements
replaceGradleTokenInFile =
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
# There can be multiple files in a comma-separated list.
# Example value: mymodid_at.cfg,nei_at.cfg
accessTransformersFile =
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = true
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =
# Adds some debug arguments like verbose output and class export.
# Adds some debug arguments like verbose output and export
usesMixinDebug = true
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage = mixins
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
coreModClass = mixins.PosteaLoadingPlugin
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
containsMixinsAndOrCoreModOnly = false
@@ -111,38 +79,28 @@ containsMixinsAndOrCoreModOnly = false
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
forceEnableMixins = true
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
# responsibility to check the license and request permission for distribution if required.
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
# responsibility check the licence and request permission for distribution, if required.
usesShadowedDependencies = false
# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
# their own classes, making the minimization unreliable.
minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories
includeWellKnownRepositories = true
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
# list of strings, with the acceptable keys being(case does not matter):
# cursemaven
# modrinth
excludeWellKnownRepositories =
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
# Authenticate with the MAVEN_USERNAME and MAVEN_PASSWORD environment variables.
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
usesMavenPublishing = true
# mavenPublishUrl = http://jenkins.usrv.eu:8081/nexus/content/repositories/releases
# Maven repository to publish the mod to.
# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/
# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.
# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
#
# The project's ID on Modrinth. Can be either the slug or the ID.
# Leave this empty if you don't want to publish to Modrinth.
# Leave this empty if you don't want to publish on Modrinth.
modrinthProjectId =
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
@@ -154,8 +112,9 @@ modrinthProjectId =
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
modrinthRelations =
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
#
# The project's numeric ID on CurseForge. You can find this in the About Project box.
# Leave this empty if you don't want to publish on CurseForge.
curseForgeProjectId =
@@ -165,39 +124,29 @@ curseForgeProjectId =
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
# and the name is the CurseForge project slug of the other mod.
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
curseForgeRelations =
# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older
# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
# projects. New projects should not use this parameter.
# customArchiveBaseName =
# Optional parameter to have the build automatically fail if an illegal version is used.
# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'.
# The check is ONLY performed if the version is a git tag.
# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+
# versionPattern =
# Optional parameter to prevent the source code from being published
# noPublishedSources =
# Uncomment to prevent the source code from being published.
# noPublishedSources = true
# Uncomment this to disable Spotless checks.
# Uncomment this to disable spotless checks
# This should only be uncommented to keep it easier to sync with upstream/other forks.
# That is, if there is no other active fork/upstream, NEVER change this.
# disableSpotless = true
# Uncomment this to disable Checkstyle checks (currently wildcard import check).
# Uncomment this to disable checkstyle checks (currently wildcard import check).
# disableCheckstyle = true
# Override the IDEA build type. Valid values are: "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
# Override the IDEA build type. Valid value is "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
# (force use delegated build).
# This is meant to be set in $HOME/.gradle/gradle.properties.
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be native build.
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be always native build.
# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want!
# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you.
# ideaOverrideBuildType = idea
# Whether IDEA should run spotless checks when pressing the Build button.
# This is meant to be set in $HOME/.gradle/gradle.properties.
# ideaCheckSpotlessOnBuild = true
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Vendored
+9 -12
View File
@@ -15,8 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -57,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -85,8 +83,7 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# 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\n' "$PWD" ) || exit
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -147,7 +144,7 @@ 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=SC2039,SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@@ -155,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -204,11 +201,11 @@ fi
# 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, 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.
# 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.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Vendored
+10 -12
View File
@@ -13,8 +13,6 @@
@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 ##########################################################################
@@ -45,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
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
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.
goto fail
@@ -59,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
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
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.
goto fail
+1 -8
View File
@@ -1,12 +1,5 @@
// Add any additional repositories for your dependencies here
repositories {
maven {
name = "mavenpattern"
url = "https://mvn.falsepattern.com/releases"
content {
group("com.falsepattern")
}
}
mavenLocal()
}
+10 -5
View File
@@ -4,10 +4,10 @@ pluginManagement {
maven {
// RetroFuturaGradle
name "GTNH Maven"
url "https://nexus.gtnewhorizons.com/repository/public/"
url "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
allowInsecureProtocol = true
mavenContent {
includeGroup("com.gtnewhorizons")
includeGroupByRegex("com\\.gtnewhorizons\\..+")
includeGroup("com.gtnewhorizons.retrofuturagradle")
}
}
gradlePluginPortal()
@@ -17,7 +17,12 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
id 'com.diffplug.blowdryerSetup' version '1.6.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' // Provides java toolchains
}
blowdryerSetup {
repoSubfolder 'gtnhShared'
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.2.2')
//devLocal '.' // Use this when testing config updates locally
}
@@ -0,0 +1,32 @@
package com.colen.postea.API;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import com.colen.postea.Utility.BlockConversionInfo;
public class BlockReplacementManager {
private static final Map<String, Function<BlockConversionInfo, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
@SuppressWarnings("unused")
public static void addBlockReplacement(String blockNameIn,
Function<BlockConversionInfo, BlockConversionInfo> transformer) {
blockReplacementMap.put(blockNameIn, transformer);
}
@SuppressWarnings("unused")
public static BlockConversionInfo getBlockReplacement(BlockConversionInfo blockConversionInfo) {
Function<BlockConversionInfo, BlockConversionInfo> transformer = blockReplacementMap
.getOrDefault(blockConversionInfo.blocKName, null);
if (transformer == null) {
return null;
} else {
return transformer.apply(blockConversionInfo);
}
}
}
@@ -1,4 +1,4 @@
package com.gtnewhorizons.postea.api;
package com.colen.postea.API;
import java.util.HashMap;
import java.util.Map;
@@ -1,4 +1,4 @@
package com.gtnewhorizons.postea.api;
package com.colen.postea.API;
import java.util.HashMap;
import java.util.function.BiFunction;
@@ -6,7 +6,7 @@ import java.util.function.BiFunction;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.gtnewhorizons.postea.utility.BlockInfo;
import com.colen.postea.Utility.BlockInfo;
public class TileEntityReplacementManager {
@@ -0,0 +1,68 @@
package com.colen.postea;
import java.util.function.Function;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import com.colen.postea.API.BlockReplacementManager;
import com.colen.postea.Utility.BlockConversionInfo;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
@SuppressWarnings("unused")
public class Postea {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
ModContainer activeMod = Loader.instance()
.activeModContainer();
String modID = activeMod.getModId();
String v = activeMod.getVersion();
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
if ((blockConversionInfoOld.x == -1) && (blockConversionInfoOld.y == 3)
&& (blockConversionInfoOld.z == -1)) {
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
blockConversionInfoNew.metadata = 1;
return blockConversionInfoNew;
}
if ((blockConversionInfoOld.x == -1) && (blockConversionInfoOld.y == 3)
&& (blockConversionInfoOld.z == 1)) {
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
blockConversionInfoNew.metadata = 1;
return blockConversionInfoNew;
}
if ((blockConversionInfoOld.x == 1) && (blockConversionInfoOld.y == 3) && (blockConversionInfoOld.z == 1)) {
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
blockConversionInfoNew.metadata = 1;
return blockConversionInfoNew;
}
if ((blockConversionInfoOld.x == 1) && (blockConversionInfoOld.y == 3)
&& (blockConversionInfoOld.z == -1)) {
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
blockConversionInfoNew.metadata = 1;
return blockConversionInfoNew;
}
blockConversionInfoNew.blockID = blockConversionInfoOld.blockID;
blockConversionInfoNew.metadata = blockConversionInfoOld.metadata;
return blockConversionInfoNew;
};
BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer);
}
}
@@ -1,4 +1,4 @@
package com.gtnewhorizons.postea.utility;
package com.colen.postea.Utility;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@@ -15,5 +15,5 @@ public final class BlockConversionInfo {
public World world;
public NBTTagCompound tileEntityNBT;
public String blockName;
public String blocKName;
}
@@ -1,4 +1,4 @@
package com.gtnewhorizons.postea.utility;
package com.colen.postea.Utility;
import java.util.function.Function;
@@ -0,0 +1,202 @@
package com.colen.postea.Utility;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import com.colen.postea.API.BlockReplacementManager;
import com.colen.postea.API.TileEntityReplacementManager;
import akka.japi.Pair;
import cpw.mods.fml.common.registry.GameRegistry;
public class ChunkFixerUtility {
public static void processChunkNBT(NBTTagCompound compound, World world) {
transformTileEntities(compound, world);
transformNormalBlocks(compound, world);
}
private static void transformNormalBlocks(NBTTagCompound compound, World world) {
NBTTagCompound level = compound.getCompoundTag("Level");
NBTTagList sections = level.getTagList("Sections", 10);
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
for (int i = 0; i < sections.tagCount(); i++) {
NBTTagCompound section = sections.getCompoundTagAt(i);
byte[] blockArray = section.getByteArray("Blocks16");
byte[] metadataArray = section.getByteArray("Data");
byte sectionY = section.getByte("Y");
for (int index = 0; index < blockArray.length / 2; index++) {
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
byte metadata = (byte) ((index & 1) == 0 ? (metadataArray[index / 2] & 0x0F)
: ((metadataArray[index / 2] & 0xF0) >> 4));
Block block = Block.getBlockById(blockId);
String blockName = GameRegistry.findUniqueIdentifierFor(block)
.toString();
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
blockConversionInfo.blocKName = blockName;
blockConversionInfo.blockID = blockId;
blockConversionInfo.metadata = metadata;
blockConversionInfo.world = world;
int x = index % 16;
int y = (index / 256) + (sectionY * 16); // Add the offset of the current section in Y direction
int z = (index / 16) % 16;
blockConversionInfo.x = x + chunkXPos + 1;
blockConversionInfo.y = y; // Y remains unchanged as it's already global
blockConversionInfo.z = z + chunkZPos + 1;
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo);
if (output != null) {
int newBlockId = output.blockID;
int newMetadata = output.metadata;
blockArray[index * 2] = (byte) ((newBlockId >> 8) & 0xFF);
blockArray[index * 2 + 1] = (byte) (newBlockId & 0xFF);
if ((index & 1) == 0) { // Even
metadataArray[index / 2] &= 0xF0;
metadataArray[index / 2] |= (newMetadata & 0x0F);
} else { // Odd
metadataArray[index / 2] &= 0x0F;
metadataArray[index / 2] |= ((newMetadata << 4) & 0xF0);
}
}
}
}
}
public static void transformTileEntities(NBTTagCompound chunkNBT, World world) {
NBTTagCompound level = chunkNBT.getCompoundTag("Level");
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(level.getTagList("TileEntities", 10), world);
List<ConversionInfo> conversionInfoList = output.first();
NBTTagList tileEntities = output.second();
if (tileEntities.tagCount() > 0) {
level.setTag("TileEntities", tileEntities);
}
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
NBTTagList sections = level.getTagList("Sections", 10);
for (int i = 0; i < sections.tagCount(); i++) {
NBTTagCompound section = sections.getCompoundTagAt(i);
processSection(section, conversionInfoList, chunkXPos, chunkZPos);
}
}
private static void processSection(NBTTagCompound section, List<ConversionInfo> conversionInfoList, int chunkXPos,
int chunkZPos) {
byte[] blockArray = section.getByteArray("Blocks16");
byte[] metadataArray = section.getByteArray("Data");
byte y = section.getByte("Y");
List<ConversionInfo> filteredList = filterConversionInfosByY(conversionInfoList, y);
for (ConversionInfo info : filteredList) {
int[] localCoords = convertToChunkLocalCoordinates(info, y, chunkXPos, chunkZPos);
int index = computeBlockIndex(localCoords);
setBlockInfo(info.blockInfo.block, index, blockArray);
setMetadata(info.blockInfo.metadata, index, metadataArray);
}
}
private static List<ConversionInfo> filterConversionInfosByY(List<ConversionInfo> conversionInfoList, byte y) {
return conversionInfoList.stream()
.filter(info -> info.y >= y * 16 && info.y < (y + 1) * 16)
.collect(Collectors.toList());
}
private static int[] convertToChunkLocalCoordinates(ConversionInfo info, byte y, int chunkXPos, int chunkZPos) {
int tileX = info.x - chunkXPos;
int tileY = info.y - y * 16;
int tileZ = info.z - chunkZPos;
return new int[] { tileX, tileY, tileZ };
}
private static int computeBlockIndex(int[] localCoords) {
return localCoords[1] * 256 + localCoords[2] * 16 + localCoords[0];
}
private static void setBlockInfo(Block block, int index, byte[] blockArray) {
int blockID = Block.getIdFromBlock(block);
blockArray[index * 2] = (byte) ((blockID >> 8) & 0xFF);
blockArray[index * 2 + 1] = (byte) (blockID & 0xFF);
}
private static void setMetadata(int metadata, int index, byte[] metadataArray) {
int metadataIndex = index / 2;
byte currentMetadataByte = metadataArray[metadataIndex];
if ((index & 1) == 0) { // Even
currentMetadataByte &= 0xF0;
currentMetadataByte |= (metadata & 0x0F);
} else { // Odd
currentMetadataByte &= 0x0F;
currentMetadataByte |= ((metadata << 4) & 0xF0);
}
metadataArray[metadataIndex] = currentMetadataByte;
}
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
List<ConversionInfo> conversionInfo = new ArrayList<>();
NBTTagList tileEntitiesCopy = new NBTTagList();
for (int i = 0; i < tileEntities.tagCount(); i++) {
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
String tileEntityId = tileEntity.getString("id");
// Check if we have a transformer registered for this tile entity ID
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
if (transformationFunction != null) {
int x = tileEntity.getInteger("x");
int y = tileEntity.getInteger("y");
int z = tileEntity.getInteger("z");
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
if (blockInfo.tileTransformer != null) {
tileEntitiesCopy.appendTag(blockInfo.tileTransformer.apply(tileEntity));
} // Otherwise they are removed, therefore not appended.
conversionInfo.add(new ConversionInfo(x, y, z, blockInfo));
}
}
return new Pair<>(conversionInfo, tileEntitiesCopy);
}
public static class ConversionInfo {
public final int x;
public final int y;
public final int z;
public final BlockInfo blockInfo;
public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) {
this.x = x;
this.y = y;
this.z = z;
this.blockInfo = blockInfo;
}
}
}
@@ -1,12 +1,11 @@
package com.gtnewhorizons.postea.utility;
package com.colen.postea.Utility;
import java.util.function.Function;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import com.gtnewhorizons.postea.api.IDExtenderCompat;
import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
import com.colen.postea.API.ItemStackReplacementManager;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -17,9 +16,8 @@ public abstract class ItemFixerUtility {
if (tag.hasNoTags()) return;
if (tag.hasKey("id")) {
int id = IDExtenderCompat.getItemStackID(tag);
short id = tag.getShort("id");
Item item = Item.getItemById(id);
if (item == null) return;
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
+ GameRegistry.findUniqueIdentifierFor(item).name;
@@ -0,0 +1,24 @@
package com.colen.postea.Utility;
import net.minecraft.nbt.NBTTagCompound;
public abstract class PosteaUtilities {
@SuppressWarnings("unused")
public static NBTTagCompound cleanseNBT(String newTileEntityID, NBTTagCompound tag) {
// Cleans the NBT, so that it replaces the ID and adds the x, y, z coordinates.
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setString("id", newTileEntityID);
// This part is for tile entities only.
if (tag.hasKey("x") && tag.hasKey("y") && tag.hasKey("z")) {
tagCompound.setInteger("x", tag.getInteger("x"));
tagCompound.setInteger("y", tag.getInteger("y"));
tagCompound.setInteger("z", tag.getInteger("z"));
}
return tagCompound;
}
}
@@ -1,4 +1,4 @@
package com.gtnewhorizons.postea.mixins;
package com.colen.postea.mixins;
import java.util.ArrayList;
import java.util.List;
@@ -44,7 +44,6 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
public List<String> getMixins(Set<String> loadedCoreMods) {
final List<String> mixins = new ArrayList<>();
mixins.add("MixinItemStack");
mixins.add("MixinChunk");
mixins.add("MixinAnvilChunkLoader");
return mixins;
}
@@ -0,0 +1,24 @@
package com.colen.postea.mixins.early;
import static com.colen.postea.Utility.ChunkFixerUtility.processChunkNBT;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(AnvilChunkLoader.class)
@SuppressWarnings("unused")
public abstract class MixinAnvilChunkLoader {
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
CallbackInfoReturnable<Object[]> cir) {
processChunkNBT(compound, world);
}
}
@@ -1,6 +1,6 @@
package com.gtnewhorizons.postea.mixins.early;
package com.colen.postea.mixins.early;
import static com.gtnewhorizons.postea.utility.ItemFixerUtility.fixItemStack;
import static com.colen.postea.Utility.ItemFixerUtility.fixItemStack;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -1,44 +0,0 @@
package com.gtnewhorizons.postea;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.blockReplacementMap;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.posteaMarkedIDs;
import net.minecraft.block.Block;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
@Mod(
modid = Postea.MODID,
version = Tags.VERSION,
name = Postea.MODNAME,
acceptedMinecraftVersions = "[1.7.10]",
dependencies = " required-after:gtnhlib@[0.6.21,);")
@SuppressWarnings("unused")
public class Postea {
public static final String MODID = "postea";
public static final String MODNAME = "Postea";
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {}
@Mod.EventHandler
public void onServerStarting(FMLServerAboutToStartEvent event) {
for (String name : blockReplacementMap.keySet()) {
Block block = Block.getBlockFromName(name);
if (block != null) {
int id = Block.getIdFromBlock(block);
posteaMarkedIDs.add(id);
}
}
}
@Mod.EventHandler
public void onServerStopping(FMLServerStoppingEvent event) {
posteaMarkedIDs.clear();
}
}
@@ -1,41 +0,0 @@
package com.gtnewhorizons.postea.api;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import net.minecraft.world.World;
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
public class BlockReplacementManager {
public static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
public static final IntOpenHashSet posteaMarkedIDs = new IntOpenHashSet();
@SuppressWarnings("unused")
public static void addBlockReplacement(String blockNameIn,
BiFunction<BlockConversionInfo, World, BlockConversionInfo> transformer) {
blockReplacementMap.put(blockNameIn, transformer);
}
public static BlockConversionInfo getBlockReplacement(BlockConversionInfo blockConversionInfo, World world) {
BiFunction<BlockConversionInfo, World, BlockConversionInfo> transformer = blockReplacementMap
.getOrDefault(blockConversionInfo.blockName, null);
if (transformer == null) {
return null;
} else {
return transformer.apply(blockConversionInfo, world);
}
}
// We need this to save reprocessing blocks.
public static boolean blockNotConvertible(int blockID) {
return !posteaMarkedIDs.contains(blockID);
}
}
@@ -1,25 +0,0 @@
package com.gtnewhorizons.postea.api;
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
import static net.minecraftforge.common.util.Constants.NBT.TAG_SHORT;
import net.minecraft.nbt.NBTTagCompound;
public class IDExtenderCompat {
public static int getItemStackID(NBTTagCompound tag) {
if (tag.hasKey("idExt", TAG_INT)) return tag.getInteger("idExt");
else if (tag.hasKey("id", TAG_INT)) return tag.getInteger("id");
else if (tag.hasKey("id", TAG_SHORT)) return tag.getShort("id");
else return 0;
}
public static void setItemStackID(NBTTagCompound tag, int id) {
if (id < 32000) {
tag.setShort("id", (short) id);
} else {
tag.setShort("id", (short) 0);
tag.setInteger("idExt", id);
}
}
}
@@ -1,168 +0,0 @@
package com.gtnewhorizons.postea.compat;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import com.falsepattern.endlessids.mixin.helpers.SubChunkBlockHook;
import com.gtnewhorizons.neid.mixins.interfaces.IExtendedBlockStorageMixin;
public class Compat {
private static Boolean chunkapi = null;
private static Boolean endlessids = null;
private static Boolean neid = null;
public static boolean chunkapiPresent() {
if (chunkapi == null) {
boolean present = false;
try {
present = Launch.classLoader.getClassBytes("com.falsepattern.chunk.internal.core.CoreLoadingPlugin")
!= null;
} catch (Throwable ignored) {}
chunkapi = present;
}
return chunkapi;
}
public static boolean endlessidsPresent() {
if (endlessids == null) {
boolean present = false;
try {
present = Launch.classLoader.getClassBytes("com.falsepattern.endlessids.asm.EndlessIDsCore") != null;
} catch (Throwable ignored) {}
endlessids = present;
}
return endlessids;
}
public static boolean neidPresent() {
if (neid == null) {
boolean present = false;
try {
present = Launch.classLoader.getClassBytes("com.gtnewhorizons.neid.core.NEIDCore") != null;
} catch (Throwable ignored) {}
neid = present;
}
return neid;
}
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
if (endlessidsPresent()) {
return EndlessIDSCompat.getSubChunkAccess(subChunk);
} else if (neidPresent()) {
return NEIDCompat.getSubChunkAccess(subChunk);
} else {
return VanillaCompat.getSubChunkAccess(subChunk);
}
}
private static class VanillaCompat {
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
final byte[] lsb = subChunk.getBlockLSBArray();
return new SubChunkAccess() {
private NibbleArray msb = subChunk.getBlockMSBArray();
@Override
public int getBlockId(int x, int y, int z) {
int i = toIndex(x, y, z);
int id = lsb[i] & 0xFF;
if (msb != null) {
id |= msb.get(x, y, z) << 8;
}
return id;
}
@Override
public void setBlockId(int x, int y, int z, int id) {
int i = toIndex(x, y, z);
int l = id & 0xFF;
int h = (id >>> 8) & 0xF;
lsb[i] = (byte) l;
if (h == 0 && msb == null) return;
if (msb == null) {
msb = new NibbleArray(lsb.length, 4);
subChunk.setBlockMSBArray(msb);
}
msb.set(x, y, z, h);
}
@Override
public int getMeta(int x, int y, int z) {
return subChunk.getExtBlockMetadata(x, y, z);
}
@Override
public void setMeta(int x, int y, int z, int meta) {
subChunk.setExtBlockMetadata(x, y, z, meta);
}
};
}
}
private static class EndlessIDSCompat {
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
final SubChunkBlockHook bh = (SubChunkBlockHook) subChunk;
return new SubChunkAccess() {
@Override
public int getBlockId(int x, int y, int z) {
return bh.eid$getID(x, y, z);
}
@Override
public void setBlockId(int x, int y, int z, int id) {
bh.eid$setID(x, y, z, id);
}
@Override
public int getMeta(int x, int y, int z) {
return bh.eid$getMetadata(x, y, z);
}
@Override
public void setMeta(int x, int y, int z, int meta) {
bh.eid$setMetadata(x, y, z, meta);
}
};
}
}
private static class NEIDCompat {
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
final IExtendedBlockStorageMixin bh = (IExtendedBlockStorageMixin) subChunk;
final short[] blockArray = bh.getBlock16BArray();
final short[] metaArray = bh.getBlock16BMetaArray();
return new SubChunkAccess() {
@Override
public int getBlockId(int x, int y, int z) {
return blockArray[toIndex(x, y, z)];
}
@Override
public void setBlockId(int x, int y, int z, int id) {
blockArray[toIndex(x, y, z)] = (short) id;
}
@Override
public int getMeta(int x, int y, int z) {
return metaArray[toIndex(x, y, z)];
}
@Override
public void setMeta(int x, int y, int z, int meta) {
metaArray[toIndex(x, y, z)] = (short) meta;
}
};
}
}
private static int toIndex(int x, int y, int z) {
return y << 8 | z << 4 | x;
}
}
@@ -1,12 +0,0 @@
package com.gtnewhorizons.postea.compat;
public interface SubChunkAccess {
int getBlockId(int x, int y, int z);
void setBlockId(int x, int y, int z, int id);
int getMeta(int x, int y, int z);
void setMeta(int x, int y, int z, int meta);
}
@@ -1,75 +0,0 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
import com.llamalad7.mixinextras.sugar.Local;
@Mixin(value = AnvilChunkLoader.class, priority = 1100)
public abstract class MixinAnvilChunkLoader {
// This hook is compatible with Vanilla/NEID/EIDs
@Inject(method = "readChunkFromNBT", at = @At("RETURN"), require = 1)
private void postea$chunkHook(CallbackInfoReturnable<Chunk> cir, @Local Chunk chunk,
@Local(argsOnly = true) World world, @Local(ordinal = 0, argsOnly = true) NBTTagCompound tag) {
IChunkMixin chunkMixin = (IChunkMixin) chunk;
chunkMixin.Postea$setPosteaCode(-1);
if (tag.hasKey("POSTEA")) {
chunkMixin.Postea$setPosteaCode(tag.getLong("POSTEA"));
}
// This checks if the chunk has been run with the current POSTEA_UPDATE_CODE and skips it if so.
if (chunkMixin.Postea$getPosteaCode() == ChunkFixerUtility.POSTEA_UPDATE_CODE) return;
for (ExtendedBlockStorage ebs : chunk.getBlockStorageArray()) {
if (ebs == null) {
continue;
}
ChunkFixerUtility.transformNormalBlocks(chunk, ebs, world);
}
}
@Inject(
method = "loadEntities",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;getTagList(Ljava/lang/String;I)Lnet/minecraft/nbt/NBTTagList;",
ordinal = 1),
require = 1)
private void postea$transformTileEntities(CallbackInfo ci, @Local(ordinal = 0) NBTTagCompound tag,
@Local World world, @Local Chunk chunk) {
IChunkMixin chunkMixin = (IChunkMixin) chunk;
// This checks if the chunk has been run with the current POSTEA_UPDATE_CODE and skips it if so.
if (chunkMixin.Postea$getPosteaCode() == ChunkFixerUtility.POSTEA_UPDATE_CODE) return;
ChunkFixerUtility.transformTileEntities(tag, chunk, world);
}
@Inject(method = "loadChunk", at = @At("RETURN"))
private void postea$updatePosteaChunkCode(World world, int i, int j, CallbackInfoReturnable<Chunk> cir) {
Chunk chunk = cir.getReturnValue();
if (chunk instanceof IChunkMixin iChunkMixin) {
if (iChunkMixin.Postea$getPosteaCode() != ChunkFixerUtility.POSTEA_UPDATE_CODE) {
iChunkMixin.Postea$setPosteaCode(ChunkFixerUtility.POSTEA_UPDATE_CODE);
chunk.setChunkModified();
}
}
}
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
if (chunk instanceof IChunkMixin iChunkMixin) {
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
}
}
}
@@ -1,27 +0,0 @@
package com.gtnewhorizons.postea.mixins.early;
import net.minecraft.world.chunk.Chunk;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
@Mixin(Chunk.class)
public class MixinChunk implements IChunkMixin {
// This new field will store the hash of mod name + versions. We use this to check
// if we need to reprocess this chunk.
@Unique
private long postea_GTNH$posteaID;
@Unique
public long Postea$getPosteaCode() {
return postea_GTNH$posteaID;
}
@Unique
public void Postea$setPosteaCode(long POSTEA_ID) {
this.postea_GTNH$posteaID = POSTEA_ID;
}
}
@@ -1,8 +0,0 @@
package com.gtnewhorizons.postea.mixins.interfaces;
public interface IChunkMixin {
long Postea$getPosteaCode();
void Postea$setPosteaCode(long posteaID);
}
@@ -1,172 +0,0 @@
package com.gtnewhorizons.postea.utility;
import static com.gtnewhorizons.postea.api.BlockReplacementManager.blockNotConvertible;
import static com.gtnewhorizons.postea.utility.PosteaUtilities.getModListHash;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import com.gtnewhorizons.postea.api.BlockReplacementManager;
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
import com.gtnewhorizons.postea.compat.Compat;
import com.gtnewhorizons.postea.compat.SubChunkAccess;
import akka.japi.Pair;
import cpw.mods.fml.common.registry.GameRegistry;
public class ChunkFixerUtility {
// This will not change between runs, unless a mod is updated or added.
public static final int POSTEA_UPDATE_CODE = getModListHash();
private static final int AIR_ID = 0;
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
public static void transformNormalBlocks(Chunk chunk, ExtendedBlockStorage ebs, World world) {
int chunkXPos = chunk.xPosition * 16;
int chunkZPos = chunk.zPosition * 16;
int sectionY = ebs.getYLocation();
SubChunkAccess access = Compat.getSubChunkAccess(ebs);
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int blockId = access.getBlockId(x, y, z);
int metadata = access.getMeta(x, y, z);
// Skip air.
if (blockId == AIR_ID) continue;
// If this block has no registered Postea conversion, skip it.
if (blockNotConvertible(blockId)) continue;
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
Block block = Block.getBlockById(blockId);
String blockName = loadedBlocks.computeIfAbsent(
block,
b -> GameRegistry.findUniqueIdentifierFor(b)
.toString());
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
blockConversionInfo.blockName = blockName;
blockConversionInfo.blockID = blockId;
blockConversionInfo.metadata = (byte) metadata; // Updated
blockConversionInfo.world = world;
blockConversionInfo.x = x + chunkXPos + 1;
blockConversionInfo.y = y + sectionY;
blockConversionInfo.z = z + chunkZPos + 1;
BlockConversionInfo output = BlockReplacementManager
.getBlockReplacement(blockConversionInfo, world);
if (output != null) {
access.setBlockId(x, y, z, output.blockID);
access.setMeta(x, y, z, output.metadata);
}
}
}
}
}
public static void transformTileEntities(NBTTagCompound levelCompoundTag, Chunk chunk, World world) {
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
levelCompoundTag.getTagList("TileEntities", 10),
world);
List<ConversionInfo> conversionInfoList = output.first();
NBTTagList tileEntities = output.second();
if (tileEntities.tagCount() > 0) {
levelCompoundTag.setTag("TileEntities", tileEntities);
}
for (ExtendedBlockStorage ebs : chunk.getBlockStorageArray()) {
if (ebs == null) continue;
processSection(ebs, conversionInfoList);
}
}
private static void processSection(ExtendedBlockStorage ebs, List<ConversionInfo> conversionInfoList) {
int sectionY = ebs.getYLocation();
List<ConversionInfo> filteredList = conversionInfoList.stream()
.filter(info -> info.y >= sectionY && info.y < (sectionY + 16))
.collect(Collectors.toList());
for (ConversionInfo info : filteredList) {
int localX = info.x & 15;
int localY = info.y & 15;
int localZ = info.z & 15;
ebs.func_150818_a(localX, localY, localZ, info.blockInfo.block);
ebs.setExtBlockMetadata(localX, localY, localZ, info.blockInfo.metadata);
}
}
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
List<ConversionInfo> conversionInfo = new ArrayList<>();
NBTTagList tileEntitiesCopy = new NBTTagList();
for (int i = 0; i < tileEntities.tagCount(); i++) {
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
String tileEntityId = tileEntity.getString("id");
// Check if we have a transformer registered for this tile entity ID
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
if (transformationFunction != null) {
int x = tileEntity.getInteger("x");
int y = tileEntity.getInteger("y");
int z = tileEntity.getInteger("z");
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
if (blockInfo == null) {
// Do nothing.
tileEntitiesCopy.appendTag(tileEntity);
continue;
}
if (blockInfo.tileTransformer != null) {
tileEntitiesCopy.appendTag(blockInfo.tileTransformer.apply(tileEntity));
} // Otherwise they are removed, therefore not appended.
conversionInfo.add(new ConversionInfo(x, y, z, blockInfo));
} else {
// Do nothing.
tileEntitiesCopy.appendTag(tileEntity);
}
}
return new Pair<>(conversionInfo, tileEntitiesCopy);
}
private static class ConversionInfo {
public final int x;
public final int y;
public final int z;
public final BlockInfo blockInfo;
public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) {
this.x = x;
this.y = y;
this.z = z;
this.blockInfo = blockInfo;
}
}
}
@@ -1,68 +0,0 @@
package com.gtnewhorizons.postea.utility;
import java.util.ArrayList;
import java.util.Collections;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public abstract class PosteaUtilities {
@SuppressWarnings("unused")
public static NBTTagCompound cleanseNBT(String newTileEntityID, NBTTagCompound tag) {
// Cleans the NBT, so that it replaces the ID and adds the x, y, z coordinates.
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setString("id", newTileEntityID);
// This part is for tile entities only.
if (tag.hasKey("x") && tag.hasKey("y") && tag.hasKey("z")) {
tagCompound.setInteger("x", tag.getInteger("x"));
tagCompound.setInteger("y", tag.getInteger("y"));
tagCompound.setInteger("z", tag.getInteger("z"));
}
return tagCompound;
}
public static int getModListHash() {
// We iterate over every mod, get its version and put it into a giant list.
// This is done so we can see if our mods have actually changed, if so, we
// will recheck every chunk for Postea adjustments.
ArrayList<String> modList = new ArrayList<>();
for (ModContainer mod : Loader.instance()
.getActiveModList()) {
modList.add(mod.getModId() + ":" + mod.getVersion());
}
// Sort this first.
Collections.sort(modList);
// Step 2: Append all elements into one string
StringBuilder combinedModStringSortedBuilder = new StringBuilder();
for (String element : modList) {
combinedModStringSortedBuilder.append(element);
}
String combinedModStringSorted = combinedModStringSortedBuilder.toString();
return combinedModStringSorted.hashCode();
}
public static void markChunkAsDirty(World world, int chunkX, int chunkZ) {
if (!world.isRemote) { // Check to make sure we're on the server side.
Chunk chunk = world.getChunkFromChunkCoords(chunkX, chunkZ);
if (chunk == null) return;
chunk.setChunkModified();
}
}
}
+1 -2
View File
@@ -1,13 +1,12 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "com.gtnewhorizons.postea.mixins.early",
"package": "com.colen.postea.mixins.early",
"refmap": "mixins.postea.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinAnvilChunkLoader",
"MixinChunk",
"MixinItemStack"
],
"client": [],