Compare commits

...
6 Commits
Author SHA1 Message Date
SuperSoupr 2641e10174 Provide chunk to tile entity transformers (#17) 2025-12-06 19:20:09 +02:00
SuperSoupr 85cacc679c Use FMLModIdMappingEvent for numeric id mapping (#15) 2025-12-05 11:41:36 +02:00
Dream Master 727348ecad update 2025-07-16 15:06:51 +07:00
Alexdoru 0a612fec9c update deps (#14) 2025-07-15 19:40:22 +02:00
Darren Eberly 4cebca9e16 Fix falsepattern maven repo inclusion (#12) 2025-07-06 14:48:12 -04:00
Martin Robertz 6eff77d785 update 2025-05-04 12:49:35 +02:00
12 changed files with 51 additions and 20 deletions

No files matched your search

+2 -1
View File
@@ -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, chunk) -> {
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
});
@@ -52,6 +52,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
return newTag;
}
```
Remember that unlike items, tile entities manually store every tag of their nbt data individually, meaning that any additional tags will be discarded and cannot be used to store additional data unless it is already a part of the new tile entity.
### 2. Normal Block Transformation
+2 -2
View File
@@ -1,7 +1,7 @@
dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.6:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.38:dev")
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.10:dev')
compileOnly('com.falsepattern:chunkapi-mc1.7.10:0.6.0:dev')
compileOnly('com.falsepattern:endlessids-mc1.7.10:1.6.0:dev')
}
+2 -2
View File
@@ -14,7 +14,7 @@ modId = postea
modGroup = com.gtnewhorizons.postea
# Whether to use modGroup as the maven publishing group.
# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods.
# When false, com.github.GTNewHorizons is used.
useModGroupForPublishing = false
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
@@ -151,7 +151,7 @@ modrinthProjectId =
# type can be one of [project, version],
# and the name is the Modrinth project or version slug/id of the other mod.
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
# Note: UniMixins 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.
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.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Vendored
+2 -3
View File
@@ -86,8 +86,7 @@ done
# 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
' "$PWD" ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -206,7 +205,7 @@ fi
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,
# * 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.
+1 -1
View File
@@ -5,7 +5,7 @@ repositories {
name = "mavenpattern"
url = "https://mvn.falsepattern.com/releases"
content {
group("com.falsepattern")
includeGroup("com.falsepattern")
}
}
mavenLocal()
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
}
@@ -6,8 +6,8 @@ import static com.gtnewhorizons.postea.api.BlockReplacementManager.posteaMarkedI
import net.minecraft.block.Block;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLModIdMappingEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
@Mod(
@@ -26,7 +26,8 @@ public class Postea {
public void preInit(FMLPreInitializationEvent event) {}
@Mod.EventHandler
public void onServerStarting(FMLServerAboutToStartEvent event) {
public void onIdMappingsChanged(FMLModIdMappingEvent event) {
posteaMarkedIDs.clear();
for (String name : blockReplacementMap.keySet()) {
Block block = Block.getBlockFromName(name);
if (block != null) {
@@ -5,19 +5,40 @@ import java.util.function.BiFunction;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import com.gtnewhorizons.postea.utility.BlockInfo;
@SuppressWarnings("unused")
public class TileEntityReplacementManager {
private static final HashMap<String, BiFunction<NBTTagCompound, World, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
private static final HashMap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
/**
* @deprecated Superseded by {@link #tileEntityTransformer(String, TriFunction)}.
*/
@Deprecated
public static void tileEntityTransformer(String tileEntityId,
BiFunction<NBTTagCompound, World, BlockInfo> transformerFunction) {
tileEntityToNormalBlockTransformer
.put(tileEntityId, (tag, world, chunk) -> transformerFunction.apply(tag, world));
}
/**
* Register a callback function to transform a tile entity before it's loaded.
* Callback returns a {@link BlockInfo} which the tile entity will be transformed into.</br>
* Note that the callback will be called before the world is fully loaded, and world.getBlock will throw an error.
* Use chunk.getBlock(x & 15, y, z & 15) instead.
*
* @param tileEntityId ID of the tile entity to be transformed
* @param transformerFunction Callback function to transforms the tile entity
*/
public static void tileEntityTransformer(String tileEntityId,
TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformerFunction) {
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
}
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
public static TriFunction<NBTTagCompound, World, Chunk, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
String tileEntityId) {
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
}
@@ -0,0 +1,7 @@
package com.gtnewhorizons.postea.api;
@FunctionalInterface
public interface TriFunction<T, U, O, R> {
R apply(T t, U u, O o);
}
@@ -6,7 +6,6 @@ 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;
@@ -18,6 +17,7 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import com.gtnewhorizons.postea.api.BlockReplacementManager;
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
import com.gtnewhorizons.postea.api.TriFunction;
import com.gtnewhorizons.postea.compat.Compat;
import com.gtnewhorizons.postea.compat.SubChunkAccess;
@@ -86,7 +86,8 @@ public class ChunkFixerUtility {
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
levelCompoundTag.getTagList("TileEntities", 10),
world);
world,
chunk);
List<ConversionInfo> conversionInfoList = output.first();
NBTTagList tileEntities = output.second();
@@ -116,7 +117,8 @@ public class ChunkFixerUtility {
}
}
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world,
Chunk chunk) {
List<ConversionInfo> conversionInfo = new ArrayList<>();
NBTTagList tileEntitiesCopy = new NBTTagList();
@@ -126,7 +128,7 @@ public class ChunkFixerUtility {
String tileEntityId = tileEntity.getString("id");
// Check if we have a transformer registered for this tile entity ID
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager
TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformationFunction = TileEntityReplacementManager
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
if (transformationFunction != null) {
@@ -134,7 +136,7 @@ public class ChunkFixerUtility {
int y = tileEntity.getInteger("y");
int z = tileEntity.getInteger("z");
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world, chunk);
if (blockInfo == null) {
// Do nothing.
tileEntitiesCopy.appendTag(tileEntity);