mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2641e10174 | ||
|
|
85cacc679c | ||
|
|
727348ecad | ||
|
|
0a612fec9c | ||
|
|
4cebca9e16 | ||
|
|
6eff77d785 | ||
|
|
46877823aa | ||
|
|
0999b44caf | ||
|
|
ff224e4b1f | ||
|
|
3c29e17434 | ||
|
|
6c3668c405 | ||
|
|
ef42dfc91f | ||
|
|
361c851706 | ||
|
|
ebb2517488 | ||
|
|
ff97e8841c | ||
|
|
b60e19b434 |
No files matched your search
@@ -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.
|
#### 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
|
```java
|
||||||
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
|
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world, chunk) -> {
|
||||||
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,6 +52,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
|
|||||||
return newTag;
|
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. Normal Block Transformation
|
||||||
|
|
||||||
@@ -83,7 +84,8 @@ BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer)
|
|||||||
|
|
||||||
```java
|
```java
|
||||||
Function<NBTTagCompound, NBTTagCompound> itemTransformer = (tag) -> {
|
Function<NBTTagCompound, NBTTagCompound> itemTransformer = (tag) -> {
|
||||||
tag.setShort("id", (short) Item.getIdFromItem(Items.gold_ingot));
|
// Use the utility method for compatibility with NEID/EndlessIDs
|
||||||
|
IDExtenderCompat.setItemStackID(tag, Item.getIdFromItem(Items.gold_ingot));
|
||||||
return tag;
|
return tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api('com.github.GTNewHorizons:NotEnoughIds:2.1.0: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')
|
||||||
}
|
}
|
||||||
+5
-5
@@ -14,7 +14,7 @@ modId = postea
|
|||||||
modGroup = com.gtnewhorizons.postea
|
modGroup = com.gtnewhorizons.postea
|
||||||
|
|
||||||
# Whether to use modGroup as the maven publishing group.
|
# 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
|
useModGroupForPublishing = false
|
||||||
|
|
||||||
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
|
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
|
||||||
@@ -56,13 +56,13 @@ generateGradleTokenClass = com.gtnewhorizons.postea.Tags
|
|||||||
gradleTokenVersion = VERSION
|
gradleTokenVersion = VERSION
|
||||||
|
|
||||||
# [DEPRECATED] Mod ID replacement token.
|
# [DEPRECATED] Mod ID replacement token.
|
||||||
gradleTokenModId = MODID
|
gradleTokenModId =
|
||||||
|
|
||||||
# [DEPRECATED] Mod name replacement token.
|
# [DEPRECATED] Mod name replacement token.
|
||||||
gradleTokenModName = MODNAME
|
gradleTokenModName =
|
||||||
|
|
||||||
# [DEPRECATED] Mod Group replacement token.
|
# [DEPRECATED] Mod Group replacement token.
|
||||||
gradleTokenGroupName = GROUPNAME
|
gradleTokenGroupName =
|
||||||
|
|
||||||
# [DEPRECATED]
|
# [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-separated list: Class1.java,Class2.java,Class3.java
|
||||||
@@ -151,7 +151,7 @@ modrinthProjectId =
|
|||||||
# type can be one of [project, version],
|
# type can be one of [project, version],
|
||||||
# and the name is the Modrinth project or version slug/id of the other mod.
|
# 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
|
# 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 =
|
modrinthRelations =
|
||||||
|
|
||||||
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# 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
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
' "$PWD" ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -206,7 +205,7 @@ fi
|
|||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# 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.
|
# 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
|
# * 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.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
// Add any additional repositories for your dependencies here
|
// Add any additional repositories for your dependencies here
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = "mavenpattern"
|
||||||
|
url = "https://mvn.falsepattern.com/releases"
|
||||||
|
content {
|
||||||
|
includeGroup("com.falsepattern")
|
||||||
|
}
|
||||||
|
}
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26'
|
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -6,19 +6,28 @@ import static com.gtnewhorizons.postea.api.BlockReplacementManager.posteaMarkedI
|
|||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
import cpw.mods.fml.common.Mod;
|
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.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
|
||||||
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||||
|
|
||||||
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
@Mod(
|
||||||
|
modid = Postea.MODID,
|
||||||
|
version = Tags.VERSION,
|
||||||
|
name = Postea.MODNAME,
|
||||||
|
acceptedMinecraftVersions = "[1.7.10]",
|
||||||
|
dependencies = " required-after:gtnhlib@[0.6.21,);")
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Postea {
|
public class Postea {
|
||||||
|
|
||||||
|
public static final String MODID = "postea";
|
||||||
|
public static final String MODNAME = "Postea";
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {}
|
public void preInit(FMLPreInitializationEvent event) {}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void onServerStarting(FMLServerAboutToStartEvent event) {
|
public void onIdMappingsChanged(FMLModIdMappingEvent event) {
|
||||||
|
posteaMarkedIDs.clear();
|
||||||
for (String name : blockReplacementMap.keySet()) {
|
for (String name : blockReplacementMap.keySet()) {
|
||||||
Block block = Block.getBlockFromName(name);
|
Block block = Block.getBlockFromName(name);
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.gtnewhorizons.postea.api;
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@@ -9,10 +8,12 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
|
||||||
public class BlockReplacementManager {
|
public class BlockReplacementManager {
|
||||||
|
|
||||||
public static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
|
public static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
|
||||||
public static final HashSet<Integer> posteaMarkedIDs = new HashSet<>();
|
public static final IntOpenHashSet posteaMarkedIDs = new IntOpenHashSet();
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void addBlockReplacement(String blockNameIn,
|
public static void addBlockReplacement(String blockNameIn,
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,19 +5,40 @@ import java.util.function.BiFunction;
|
|||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
import com.gtnewhorizons.postea.utility.BlockInfo;
|
import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class TileEntityReplacementManager {
|
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,
|
public static void tileEntityTransformer(String tileEntityId,
|
||||||
BiFunction<NBTTagCompound, World, BlockInfo> transformerFunction) {
|
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);
|
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
public static TriFunction<NBTTagCompound, World, Chunk, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
||||||
String tileEntityId) {
|
String tileEntityId) {
|
||||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
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.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@@ -13,34 +14,59 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
|
|
||||||
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
||||||
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
|
||||||
@Mixin(AnvilChunkLoader.class)
|
@Mixin(value = AnvilChunkLoader.class, priority = 1100)
|
||||||
public abstract class MixinAnvilChunkLoader {
|
public abstract class MixinAnvilChunkLoader {
|
||||||
|
|
||||||
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
|
// This hook is compatible with Vanilla/NEID/EIDs
|
||||||
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
|
@Inject(method = "readChunkFromNBT", at = @At("RETURN"), require = 1)
|
||||||
CallbackInfoReturnable<Object[]> cir) {
|
private void postea$chunkHook(CallbackInfoReturnable<Chunk> cir, @Local Chunk chunk,
|
||||||
ChunkFixerUtility.processChunkNBT(compound, world);
|
@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 = "readChunkFromNBT", at = @At("RETURN"))
|
@Inject(
|
||||||
private Chunk onReadChunkFromNBT(World world, NBTTagCompound nbtTagCompound, CallbackInfoReturnable<Chunk> cir) {
|
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();
|
Chunk chunk = cir.getReturnValue();
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
if (nbtTagCompound.hasKey("POSTEA")) {
|
if (iChunkMixin.Postea$getPosteaCode() != ChunkFixerUtility.POSTEA_UPDATE_CODE) {
|
||||||
long posteaCode = nbtTagCompound.getLong("POSTEA");
|
iChunkMixin.Postea$setPosteaCode(ChunkFixerUtility.POSTEA_UPDATE_CODE);
|
||||||
iChunkMixin.Postea$setPosteaCode(posteaCode);
|
chunk.setChunkModified();
|
||||||
|
|
||||||
// Chunk has been updated with Postea, so we will mark it to save later.
|
|
||||||
if (posteaCode != ChunkFixerUtility.POSTEA_UPDATE_CODE) chunk.setChunkModified();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
|
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
|
||||||
private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,135 +6,88 @@ import static com.gtnewhorizons.postea.utility.PosteaUtilities.getModListHash;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.world.World;
|
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.BlockReplacementManager;
|
||||||
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.api.TriFunction;
|
||||||
|
import com.gtnewhorizons.postea.compat.Compat;
|
||||||
|
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||||
|
|
||||||
import akka.japi.Pair;
|
import akka.japi.Pair;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
public class ChunkFixerUtility {
|
public class ChunkFixerUtility {
|
||||||
|
|
||||||
public static void processChunkNBT(NBTTagCompound compound, World world) {
|
|
||||||
NBTTagCompound levelCompoundTag = compound.getCompoundTag("Level");
|
|
||||||
|
|
||||||
if (processChunk(levelCompoundTag)) {
|
|
||||||
transformTileEntities(levelCompoundTag, world);
|
|
||||||
transformNormalBlocks(levelCompoundTag, world);
|
|
||||||
levelCompoundTag.setInteger("POSTEA", POSTEA_UPDATE_CODE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will not change between runs, unless a mod is updated or added.
|
// This will not change between runs, unless a mod is updated or added.
|
||||||
public static final int POSTEA_UPDATE_CODE = getModListHash();
|
public static final int POSTEA_UPDATE_CODE = getModListHash();
|
||||||
|
|
||||||
// If a chunk has the same postea code, then do not update it. Return false.
|
|
||||||
private static boolean processChunk(NBTTagCompound compound) {
|
|
||||||
// I'm minimising the string length here since this
|
|
||||||
// will be on every single chunk in every world... Rather not duplicate too much.
|
|
||||||
if (compound.hasKey("POSTEA")) {
|
|
||||||
return compound.getInteger("POSTEA") != POSTEA_UPDATE_CODE;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int AIR_ID = 0;
|
private static final int AIR_ID = 0;
|
||||||
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
|
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
|
||||||
|
|
||||||
private static void transformNormalBlocks(NBTTagCompound levelCompoundTag, World world) {
|
public static void transformNormalBlocks(Chunk chunk, ExtendedBlockStorage ebs, World world) {
|
||||||
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16;
|
int chunkXPos = chunk.xPosition * 16;
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16;
|
int chunkZPos = chunk.zPosition * 16;
|
||||||
|
|
||||||
for (int i = 0; i < sections.tagCount(); i++) {
|
int sectionY = ebs.getYLocation();
|
||||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
// Blocks16 and Data16 exist only because of NEID.
|
SubChunkAccess access = Compat.getSubChunkAccess(ebs);
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
|
||||||
byte[] metadataArray = section.getByteArray("Data16");
|
|
||||||
// If metadata array is empty, it was all zeroes. We create a new array to write our new values to,
|
|
||||||
// and only save this when a nonzero value was written
|
|
||||||
boolean wasAllZero = false;
|
|
||||||
if (metadataArray.length == 0) {
|
|
||||||
wasAllZero = true;
|
|
||||||
metadataArray = new byte[8192];
|
|
||||||
}
|
|
||||||
// Keep track of if we write a nonzero element to the metadata array
|
|
||||||
boolean hasWrittenNonZero = false;
|
|
||||||
|
|
||||||
byte sectionY = section.getByte("Y");
|
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);
|
||||||
|
|
||||||
for (int index = 0; index < blockArray.length / 2; index++) {
|
// Skip air.
|
||||||
// Horrible bit jank to recreate the actual IDs, because the array is just a byte array.
|
if (blockId == AIR_ID) continue;
|
||||||
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
// If this block has no registered Postea conversion, skip it.
|
||||||
int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF);
|
if (blockNotConvertible(blockId)) continue;
|
||||||
|
|
||||||
// Skip air.
|
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
|
||||||
if (blockId == AIR_ID) continue;
|
Block block = Block.getBlockById(blockId);
|
||||||
// If this block has no registered Postea conversion, skip it.
|
String blockName = loadedBlocks.computeIfAbsent(
|
||||||
if (blockNotConvertible(blockId)) continue;
|
block,
|
||||||
|
b -> GameRegistry.findUniqueIdentifierFor(b)
|
||||||
|
.toString());
|
||||||
|
|
||||||
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
|
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
||||||
Block block = Block.getBlockById(blockId);
|
blockConversionInfo.blockName = blockName;
|
||||||
String blockName = loadedBlocks.computeIfAbsent(
|
blockConversionInfo.blockID = blockId;
|
||||||
block,
|
blockConversionInfo.metadata = (byte) metadata; // Updated
|
||||||
b -> GameRegistry.findUniqueIdentifierFor(b)
|
|
||||||
.toString());
|
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
blockConversionInfo.world = world;
|
||||||
blockConversionInfo.blockName = blockName;
|
|
||||||
blockConversionInfo.blockID = blockId;
|
blockConversionInfo.x = x + chunkXPos + 1;
|
||||||
blockConversionInfo.metadata = (byte) metadata; // Updated
|
blockConversionInfo.y = y + sectionY;
|
||||||
// If we wrote a nonzero metadata, keep track of this because it means the
|
blockConversionInfo.z = z + chunkZPos + 1;
|
||||||
// new array needs to be written back to NBT
|
|
||||||
if (metadata != 0) {
|
BlockConversionInfo output = BlockReplacementManager
|
||||||
hasWrittenNonZero = true;
|
.getBlockReplacement(blockConversionInfo, world);
|
||||||
|
|
||||||
|
if (output != null) {
|
||||||
|
access.setBlockId(x, y, z, output.blockID);
|
||||||
|
access.setMeta(x, y, z, output.metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
blockConversionInfo.world = world;
|
|
||||||
|
|
||||||
int x = index % 16;
|
|
||||||
int y = (index / 256) + (sectionY * 16);
|
|
||||||
int z = (index / 16) % 16;
|
|
||||||
|
|
||||||
blockConversionInfo.x = x + chunkXPos + 1;
|
|
||||||
blockConversionInfo.y = y;
|
|
||||||
blockConversionInfo.z = z + chunkZPos + 1;
|
|
||||||
|
|
||||||
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo, world);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
metadataArray[index * 2] = (byte) ((newMetadata >> 8) & 0xFF);
|
|
||||||
metadataArray[index * 2 + 1] = (byte) (newMetadata & 0xFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// After processing all replacements, if we made a new metadata array and wrote a nonzero value to it,
|
|
||||||
// write it back to world NBT to save
|
|
||||||
if (wasAllZero && hasWrittenNonZero) {
|
|
||||||
section.setByteArray("Data16", metadataArray);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void transformTileEntities(NBTTagCompound levelCompoundTag, World world) {
|
public static void transformTileEntities(NBTTagCompound levelCompoundTag, Chunk chunk, World world) {
|
||||||
|
|
||||||
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
||||||
levelCompoundTag.getTagList("TileEntities", 10),
|
levelCompoundTag.getTagList("TileEntities", 10),
|
||||||
world);
|
world,
|
||||||
|
chunk);
|
||||||
List<ConversionInfo> conversionInfoList = output.first();
|
List<ConversionInfo> conversionInfoList = output.first();
|
||||||
NBTTagList tileEntities = output.second();
|
NBTTagList tileEntities = output.second();
|
||||||
|
|
||||||
@@ -142,65 +95,30 @@ public class ChunkFixerUtility {
|
|||||||
levelCompoundTag.setTag("TileEntities", tileEntities);
|
levelCompoundTag.setTag("TileEntities", tileEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
for (ExtendedBlockStorage ebs : chunk.getBlockStorageArray()) {
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
if (ebs == null) continue;
|
||||||
|
processSection(ebs, conversionInfoList);
|
||||||
NBTTagList sections = levelCompoundTag.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,
|
private static void processSection(ExtendedBlockStorage ebs, List<ConversionInfo> conversionInfoList) {
|
||||||
int chunkZPos) {
|
int sectionY = ebs.getYLocation();
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
|
||||||
byte[] metadataArray = section.getByteArray("Data16"); // Updated to use Data16
|
|
||||||
byte y = section.getByte("Y");
|
|
||||||
|
|
||||||
List<ConversionInfo> filteredList = filterConversionInfosByY(conversionInfoList, y);
|
List<ConversionInfo> filteredList = conversionInfoList.stream()
|
||||||
|
.filter(info -> info.y >= sectionY && info.y < (sectionY + 16))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
for (ConversionInfo info : filteredList) {
|
for (ConversionInfo info : filteredList) {
|
||||||
int[] localCoords = convertToChunkLocalCoordinates(info, y, chunkXPos, chunkZPos);
|
int localX = info.x & 15;
|
||||||
int index = computeBlockIndex(localCoords);
|
int localY = info.y & 15;
|
||||||
setBlockInfo(info.blockInfo.block, index, blockArray);
|
int localZ = info.z & 15;
|
||||||
setMetadata(info.blockInfo.metadata, index, metadataArray); // This uses the updated setMetadata
|
ebs.func_150818_a(localX, localY, localZ, info.blockInfo.block);
|
||||||
|
ebs.setExtBlockMetadata(localX, localY, localZ, info.blockInfo.metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ConversionInfo> filterConversionInfosByY(List<ConversionInfo> conversionInfoList, byte y) {
|
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world,
|
||||||
return conversionInfoList.stream()
|
Chunk chunk) {
|
||||||
.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) {
|
|
||||||
// Since each metadata is now two bytes, multiply the index by 2 to get the correct position.
|
|
||||||
int metadataStartIndex = index * 2;
|
|
||||||
|
|
||||||
// Split the 16-bit metadata into two bytes and store them in the array.
|
|
||||||
metadataArray[metadataStartIndex] = (byte) ((metadata >> 8) & 0xFF); // Higher 8 bits
|
|
||||||
metadataArray[metadataStartIndex + 1] = (byte) (metadata & 0xFF); // Lower 8 bits
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
|
|
||||||
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
||||||
|
|
||||||
NBTTagList tileEntitiesCopy = new NBTTagList();
|
NBTTagList tileEntitiesCopy = new NBTTagList();
|
||||||
@@ -210,7 +128,7 @@ public class ChunkFixerUtility {
|
|||||||
String tileEntityId = tileEntity.getString("id");
|
String tileEntityId = tileEntity.getString("id");
|
||||||
|
|
||||||
// Check if we have a transformer registered for this tile entity 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);
|
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||||
|
|
||||||
if (transformationFunction != null) {
|
if (transformationFunction != null) {
|
||||||
@@ -218,7 +136,7 @@ public class ChunkFixerUtility {
|
|||||||
int y = tileEntity.getInteger("y");
|
int y = tileEntity.getInteger("y");
|
||||||
int z = tileEntity.getInteger("z");
|
int z = tileEntity.getInteger("z");
|
||||||
|
|
||||||
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
|
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world, chunk);
|
||||||
if (blockInfo == null) {
|
if (blockInfo == null) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
tileEntitiesCopy.appendTag(tileEntity);
|
tileEntitiesCopy.appendTag(tileEntity);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.function.Function;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.IDExtenderCompat;
|
||||||
import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
|
import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
@@ -16,7 +17,7 @@ public abstract class ItemFixerUtility {
|
|||||||
if (tag.hasNoTags()) return;
|
if (tag.hasNoTags()) return;
|
||||||
|
|
||||||
if (tag.hasKey("id")) {
|
if (tag.hasKey("id")) {
|
||||||
short id = tag.getShort("id");
|
int id = IDExtenderCompat.getItemStackID(tag);
|
||||||
Item item = Item.getItemById(id);
|
Item item = Item.getItemById(id);
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
|
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
|
||||||
|
|||||||
Reference in new issue
Block a user