mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdd8977182 | ||
|
|
e590bbfb61 | ||
|
|
82349735e4 | ||
|
|
42b5e4d38c | ||
|
|
a803845017 | ||
|
|
7ad4145c0a | ||
|
|
b0df1a2444 | ||
|
|
2067bd1ab0 |
No files matched your search
@@ -3,9 +3,9 @@ name: Build and test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
push:
|
||||
branches: [ master, main ]
|
||||
branches: [ master, main, release/** ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
|
||||
dependencies {
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.31:dev")
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.9.39: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')
|
||||
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.8.71-GTNH:dev") { transitive = false }
|
||||
compileOnly('com.falsepattern:chunkapi-mc1.7.10:0.8.2:dev')
|
||||
compileOnly('com.falsepattern:endlessids-mc1.7.10:1.7.1:dev')
|
||||
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.8.75-GTNH:dev") { transitive = false }
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
#This file is generated by updateDaemonJvm
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/4945f00643ec68e7c7a6b66f90124f89/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/93aeea858331bd6bb00ba94759830234/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/4945f00643ec68e7c7a6b66f90124f89/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/46949723aaa20c7b64d7ecfed7207034/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d6690dfd71c4c91e08577437b5b2beb0/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/4945f00643ec68e7c7a6b66f90124f89/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1e91f45234d88a64dafb961c93ddc75a/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/552c7bffe0370c66410a51c55985b511/redirect
|
||||
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d4fd992c9557644e637ebe98263e0ae7/redirect
|
||||
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/59a9771cad43219260d9aac9a8ec4d6a/redirect
|
||||
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a4c09dd2e2d7079373d30e524bbc2829/redirect
|
||||
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
||||
toolchainVersion=25
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -57,7 +57,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/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.20'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.24'
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gtnewhorizons.postea;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||
@@ -14,6 +15,7 @@ import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||
import cpw.mods.fml.common.event.FMLModIdMappingEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
@Mod(
|
||||
modid = Postea.MODID,
|
||||
@@ -28,14 +30,16 @@ public class Postea {
|
||||
public static final String MODNAME = "Postea";
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {}
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postsLoad(FMLPostInitializationEvent event) {
|
||||
// TestUIEMigrator.postLoad();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@SubscribeEvent
|
||||
public void chunkLoaded(ChunkEvent.Load event) {
|
||||
ChunkFixerUtility.onChunkLoaded(event.getChunk());
|
||||
}
|
||||
@@ -56,5 +60,4 @@ public class Postea {
|
||||
public void onLoadCompleted(FMLLoadCompleteEvent event) {
|
||||
SimpleTransformationRegistry.onLoadCompleted();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
/**
|
||||
* A block referenced by its namespaced id, together with a meta value. Returned by
|
||||
* {@link BlockReplacementManager#transformBlock(String, int)}.
|
||||
*/
|
||||
public final class BlockNameAndMeta {
|
||||
|
||||
/**
|
||||
* The namespaced id of the block.
|
||||
*/
|
||||
public final String name;
|
||||
/**
|
||||
* The meta value of the block.
|
||||
*/
|
||||
public final int metadata;
|
||||
|
||||
public BlockNameAndMeta(String name, int metadata) {
|
||||
this.name = name;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||
import com.gtnewhorizons.postea.utility.MissingMappingHandler;
|
||||
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
|
||||
@@ -48,7 +47,7 @@ public abstract class BlockReplacementManager {
|
||||
* @param transformer The transformer to apply.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void addTransformationHandler(String originalId, Function<BlockConversionInfo, Boolean> transformer) {
|
||||
public static void addTransformationHandler(String originalId, IBlockTransformationHandler transformer) {
|
||||
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||
if (transformer == null) throw new IllegalArgumentException("transformer is null");
|
||||
TransformerRegistry.addBlockTransformer(originalId, transformer);
|
||||
@@ -56,6 +55,32 @@ public abstract class BlockReplacementManager {
|
||||
|
||||
// endregion custom transformer registration
|
||||
|
||||
// region lookup
|
||||
|
||||
/**
|
||||
* Runs the block transformers registered for the given id on a block that isn't placed in the world, and returns
|
||||
* what it would be transformed into.<br>
|
||||
* <br>
|
||||
* This is meant for mods that store blocks by their namespaced id inside their own NBT (e.g.: blocks that are
|
||||
* made out of other blocks), which Postea can't reach while converting chunks. Calling this when such a block is
|
||||
* loaded applies every migration registered to Postea to it.
|
||||
*
|
||||
* @apiNote Only call this while a world is loaded, transformers rely on the numeric ids resolved for that world.
|
||||
* The transformers are given a {@link com.gtnewhorizons.postea.utility.BlockConversionInfo} without a
|
||||
* world, and with all coordinates set to 0. Tile entity transformers are not run.
|
||||
*
|
||||
* @param name The namespaced id of the block.
|
||||
* @param metadata The meta value of the block.
|
||||
* @return The namespaced id and meta value of the block to use instead, or null if no transformer applies.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static @Nullable BlockNameAndMeta transformBlock(@Nonnull String name, int metadata) {
|
||||
if (name == null) throw new NullPointerException("name cannot be null");
|
||||
return TransformerRegistry.transformBlock(name, metadata);
|
||||
}
|
||||
|
||||
// endregion lookup
|
||||
|
||||
// region id resolving
|
||||
|
||||
// spotless:off
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IBlockTransformationHandler {
|
||||
|
||||
boolean apply(BlockConversionInfo info);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface IItemStackTransformationHandler {
|
||||
|
||||
boolean apply(String originalId, NBTTagCompound stack);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -8,7 +7,6 @@ import javax.annotation.Nonnull;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||
@@ -52,8 +50,7 @@ public abstract class ItemStackReplacementManager {
|
||||
* @param transformer The transformer to apply.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public static void addTransformationHandler(String originalId,
|
||||
BiFunction<String, NBTTagCompound, Boolean> transformer) {
|
||||
public static void addTransformationHandler(String originalId, IItemStackTransformationHandler transformer) {
|
||||
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||
if (transformer == null) throw new IllegalArgumentException("transformer is null");
|
||||
TransformerRegistry.addStackTransformer(originalId, transformer);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.gtnewhorizons.postea.mixins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
|
||||
import com.gtnewhorizon.gtnhmixins.LateMixin;
|
||||
|
||||
@LateMixin
|
||||
public final class PosteaLateLoadingPlugin implements ILateMixinLoader {
|
||||
|
||||
@Override
|
||||
public String getMixinConfig() {
|
||||
return "mixins.postea.late.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins(Set<String> loadedMods) {
|
||||
final List<String> mixins = new ArrayList<>();
|
||||
if (loadedMods.contains("chunkapi")) {
|
||||
mixins.add("MixinDataRegistryImpl");
|
||||
}
|
||||
return mixins;
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
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) {
|
||||
ChunkFixerUtility.onChunkRead(chunk, world, tag);
|
||||
private void postea$chunkHook(World world, NBTTagCompound tag, CallbackInfoReturnable<Chunk> cir) {
|
||||
ChunkFixerUtility.onChunkRead(cir.getReturnValue(), world, tag);
|
||||
}
|
||||
|
||||
@Inject(method = "loadChunk", at = @At("RETURN"))
|
||||
@@ -29,7 +27,7 @@ public abstract class MixinAnvilChunkLoader {
|
||||
ChunkFixerUtility.onChunkLoaded(cir.getReturnValue());
|
||||
}
|
||||
|
||||
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
|
||||
@Inject(method = "writeChunkToNBT", at = @At("HEAD"), order = 900)
|
||||
private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
||||
ChunkFixerUtility.onChunkWrite(chunk, nbtTagCompound);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.gtnewhorizons.postea.mixins.late;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
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 com.falsepattern.chunk.internal.DataRegistryImpl;
|
||||
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||
|
||||
@Mixin(value = DataRegistryImpl.class, remap = false)
|
||||
public abstract class MixinDataRegistryImpl {
|
||||
|
||||
@Inject(
|
||||
method = "readChunkFromNBT(Lnet/minecraft/world/chunk/Chunk;Lnet/minecraft/nbt/NBTTagCompound;)V",
|
||||
at = @At("RETURN"),
|
||||
require = 1)
|
||||
private static void Postea$chunkReadHook(Chunk chunk, NBTTagCompound chunkNBT, CallbackInfo ci) {
|
||||
ChunkFixerUtility.onChunkRead(chunk, chunk.worldObj, chunkNBT);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class ChunkFixerUtility {
|
||||
|
||||
BlockConversionInfo output = getBlockReplacement(
|
||||
blockId,
|
||||
(byte) metadata,
|
||||
metadata,
|
||||
world,
|
||||
x + chunkXPos + 1,
|
||||
y + sectionY,
|
||||
|
||||
@@ -49,13 +49,13 @@ class SimpleTransformationMap<T> {
|
||||
* The target meta/damage value for the transformation.
|
||||
* If the value is {@link OreDictionary#WILDCARD_VALUE}, It maintains the old meta/damage value.
|
||||
*/
|
||||
public final short targetMeta;
|
||||
public final int targetMeta;
|
||||
/**
|
||||
* The numeric id of the target block, updated during the FMLMappingUpdate event
|
||||
*/
|
||||
public int targetRuntimeId;
|
||||
|
||||
public Value(T target, short targetMeta) {
|
||||
public Value(T target, int targetMeta) {
|
||||
this.target = target;
|
||||
this.targetMeta = targetMeta;
|
||||
this.targetRuntimeId = -1;
|
||||
@@ -73,7 +73,7 @@ class SimpleTransformationMap<T> {
|
||||
* When querying, the value will be replaced, which will
|
||||
* be used when ever no other specific meta match is found.
|
||||
*/
|
||||
public void put(String originalId, int originalMeta, T target, short targetMeta) {
|
||||
public void put(String originalId, int originalMeta, T target, int targetMeta) {
|
||||
if (originalMeta == -1) originalMeta = OreDictionary.WILDCARD_VALUE;
|
||||
this.registry.computeIfAbsent(originalId, k -> new Int2ObjectOpenHashMap<>())
|
||||
.put(originalMeta, new Value<>(target, targetMeta));
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -10,7 +8,9 @@ import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
|
||||
import com.gtnewhorizons.postea.api.IDExtenderCompat;
|
||||
import com.gtnewhorizons.postea.api.IItemStackTransformationHandler;
|
||||
|
||||
/**
|
||||
* A registry for simple item and block transformations. A common use case is mod removal, replacements or deprecations.
|
||||
@@ -100,11 +100,11 @@ public class SimpleTransformationRegistry {
|
||||
public static void addSimpleTransformer(String originalId, int originalMeta, Block newBlock, int newMeta,
|
||||
boolean skipStackRemap) {
|
||||
if (newMeta == -1) newMeta = OreDictionary.WILDCARD_VALUE;
|
||||
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, newBlock, (short) newMeta);
|
||||
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, newBlock, newMeta);
|
||||
if (!skipStackRemap) {
|
||||
Item item = Item.getItemFromBlock(newBlock);
|
||||
if (item != null) {
|
||||
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, item, (short) newMeta);
|
||||
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, item, newMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class SimpleTransformationRegistry {
|
||||
*
|
||||
* @implNote This implementation has constant-time runtime.
|
||||
*/
|
||||
private static class SimpleBlockTransformationHandler implements Function<BlockConversionInfo, Boolean> {
|
||||
private static class SimpleBlockTransformationHandler implements IBlockTransformationHandler {
|
||||
|
||||
private final Map<Integer, SimpleTransformationMap.Value<Block>> metaMap;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class SimpleTransformationRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(BlockConversionInfo info) {
|
||||
public boolean apply(BlockConversionInfo info) {
|
||||
SimpleTransformationMap.Value<Block> mapping = SimpleTransformationMap
|
||||
.getFromSubMap(metaMap, info.metadata);
|
||||
if (mapping == null || mapping.targetRuntimeId <= -1) return false;
|
||||
@@ -166,9 +166,9 @@ public class SimpleTransformationRegistry {
|
||||
boolean skipBlockRemap) {
|
||||
if (newMeta == -1) newMeta = OreDictionary.WILDCARD_VALUE;
|
||||
if (!skipBlockRemap && newItem instanceof ItemBlock ib) {
|
||||
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, ib.field_150939_a, (short) newMeta);
|
||||
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, ib.field_150939_a, newMeta);
|
||||
}
|
||||
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, newItem, (short) newMeta);
|
||||
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, newItem, newMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +176,7 @@ public class SimpleTransformationRegistry {
|
||||
*
|
||||
* @implNote This implementation has constant-time runtime.
|
||||
*/
|
||||
private static class SimpleItemTransformationHandler implements BiFunction<String, NBTTagCompound, Boolean> {
|
||||
private static class SimpleItemTransformationHandler implements IItemStackTransformationHandler {
|
||||
|
||||
private final Map<Integer, SimpleTransformationMap.Value<Item>> metaMap;
|
||||
|
||||
@@ -185,13 +185,14 @@ public class SimpleTransformationRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean apply(String originalId, NBTTagCompound tag) {
|
||||
public boolean apply(String originalId, NBTTagCompound tag) {
|
||||
short meta = tag.getShort("Damage");
|
||||
SimpleTransformationMap.Value<Item> mapping = SimpleTransformationMap.getFromSubMap(metaMap, meta);
|
||||
if (mapping == null || mapping.targetRuntimeId <= -1) return false;
|
||||
IDExtenderCompat.setItemStackID(tag, mapping.targetRuntimeId);
|
||||
if (mapping.targetMeta != OreDictionary.WILDCARD_VALUE) {
|
||||
tag.setShort("Damage", mapping.targetMeta);
|
||||
// Damage is a vanilla short NBT field, unrelated to EndlessIDs block metadata width.
|
||||
tag.setShort("Damage", (short) mapping.targetMeta);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
@@ -15,11 +14,15 @@ import net.minecraft.world.chunk.Chunk;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.gtnewhorizons.postea.api.BlockNameAndMeta;
|
||||
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
|
||||
import com.gtnewhorizons.postea.api.IDExtenderCompat;
|
||||
import com.gtnewhorizons.postea.api.IItemStackTransformationHandler;
|
||||
import com.gtnewhorizons.postea.api.TriFunction;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
|
||||
/**
|
||||
@@ -27,9 +30,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
*/
|
||||
public class TransformerRegistry {
|
||||
|
||||
private static final LinkedListMultimap<String, BiFunction<String, NBTTagCompound, Boolean>> ITEM_REPLACEMENT_MAP = LinkedListMultimap
|
||||
private static final LinkedListMultimap<String, IItemStackTransformationHandler> ITEM_REPLACEMENT_MAP = LinkedListMultimap
|
||||
.create();
|
||||
public static final LinkedListMultimap<String, Function<BlockConversionInfo, Boolean>> BLOCK_REPLACEMENT_MAP = LinkedListMultimap
|
||||
public static final LinkedListMultimap<String, IBlockTransformationHandler> BLOCK_REPLACEMENT_MAP = LinkedListMultimap
|
||||
.create();
|
||||
private static final LinkedListMultimap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> TILE_ENTITY_REPLACEMENT_MAP = LinkedListMultimap
|
||||
.create();
|
||||
@@ -38,13 +41,13 @@ public class TransformerRegistry {
|
||||
* Pivoting on the id is faster than pivoting on the strings so this should help with perf a bit.
|
||||
* Generated during the mapping update event whilst entering/loading a world.
|
||||
*/
|
||||
private static final Int2ObjectOpenHashMap<Pair<String, List<BiFunction<String, NBTTagCompound, Boolean>>>> RUNTIME_ITEM_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectOpenHashMap<Pair<String, List<IItemStackTransformationHandler>>> RUNTIME_ITEM_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||
/**
|
||||
* Map of blockIO -> originalName+transformationHandler.
|
||||
* Pivoting on the id is faster than pivoting on the strings so this should help with perf a bit.
|
||||
* Generated during the mapping update event whilst entering/loading a world.
|
||||
*/
|
||||
private static final Int2ObjectOpenHashMap<Pair<String, List<Function<BlockConversionInfo, Boolean>>>> RUNTIME_BLOCK_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectOpenHashMap<Pair<String, List<IBlockTransformationHandler>>> RUNTIME_BLOCK_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
// region FML Life Cycle handlers
|
||||
/**
|
||||
@@ -94,7 +97,7 @@ public class TransformerRegistry {
|
||||
* @param transformer The transformation handler that will execute a transformation on the block.
|
||||
*/
|
||||
public static void addBlockTransformer(@Nonnull String originalId,
|
||||
@Nonnull Function<BlockConversionInfo, Boolean> transformer) {
|
||||
@Nonnull IBlockTransformationHandler transformer) {
|
||||
BLOCK_REPLACEMENT_MAP.put(originalId, transformer);
|
||||
}
|
||||
|
||||
@@ -112,7 +115,7 @@ public class TransformerRegistry {
|
||||
* @param transformer The transformation handler that will execute a transformation on the block.
|
||||
*/
|
||||
public static void addStackTransformer(@Nonnull String originalId,
|
||||
@Nonnull BiFunction<String, NBTTagCompound, Boolean> transformer) {
|
||||
@Nonnull IItemStackTransformationHandler transformer) {
|
||||
ITEM_REPLACEMENT_MAP.put(originalId, transformer);
|
||||
}
|
||||
|
||||
@@ -135,9 +138,9 @@ public class TransformerRegistry {
|
||||
}
|
||||
|
||||
// region transformation handlers
|
||||
public static @Nullable BlockConversionInfo getBlockReplacement(int blockId, byte metadata, World world, int x,
|
||||
public static @Nullable BlockConversionInfo getBlockReplacement(int blockId, int metadata, World world, int x,
|
||||
int y, int z) {
|
||||
Pair<String, List<Function<BlockConversionInfo, Boolean>>> data = RUNTIME_BLOCK_REPLACEMENT_MAP.get(blockId);
|
||||
Pair<String, List<IBlockTransformationHandler>> data = RUNTIME_BLOCK_REPLACEMENT_MAP.get(blockId);
|
||||
if (data == null) return null;
|
||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo(
|
||||
// transparently maps the id to the original id if it's a dummy id
|
||||
@@ -148,7 +151,7 @@ public class TransformerRegistry {
|
||||
y,
|
||||
z,
|
||||
world);
|
||||
for (Function<BlockConversionInfo, Boolean> transformer : data.getValue()) {
|
||||
for (IBlockTransformationHandler transformer : data.getValue()) {
|
||||
if (transformer.apply(blockConversionInfo)) {
|
||||
return blockConversionInfo;
|
||||
}
|
||||
@@ -156,17 +159,43 @@ public class TransformerRegistry {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static @Nullable BlockNameAndMeta transformBlock(@Nonnull String name, int metadata) {
|
||||
List<IBlockTransformationHandler> handlers = BLOCK_REPLACEMENT_MAP.get(name);
|
||||
if (handlers.isEmpty()) return null;
|
||||
// there is no position nor world, the block isn't placed anywhere
|
||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo(
|
||||
name,
|
||||
IDRegistry.getBlockId(name),
|
||||
metadata,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
null);
|
||||
for (IBlockTransformationHandler transformer : handlers) {
|
||||
if (transformer.apply(blockConversionInfo)) {
|
||||
Block block = GameData.getBlockRegistry()
|
||||
.getRaw(blockConversionInfo.blockID);
|
||||
if (block == null) return null;
|
||||
return new BlockNameAndMeta(
|
||||
GameData.getBlockRegistry()
|
||||
.getNameForObject(block),
|
||||
blockConversionInfo.metadata);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void transformItem(NBTTagCompound tag) {
|
||||
// abort early if tag is bad.
|
||||
if (tag.hasNoTags() || !tag.hasKey("id")) return;
|
||||
// get handler
|
||||
int id = IDExtenderCompat.getItemStackID(tag);
|
||||
Pair<String, List<BiFunction<String, NBTTagCompound, Boolean>>> data = RUNTIME_ITEM_REPLACEMENT_MAP.get(id);
|
||||
Pair<String, List<IItemStackTransformationHandler>> data = RUNTIME_ITEM_REPLACEMENT_MAP.get(id);
|
||||
// abort early if handler not found
|
||||
if (data != null && !data.getValue()
|
||||
.isEmpty()) {
|
||||
// apply handlers
|
||||
for (BiFunction<String, NBTTagCompound, Boolean> transformer : data.getValue()) {
|
||||
for (IItemStackTransformationHandler transformer : data.getValue()) {
|
||||
if (transformer.apply(data.getKey(), tag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8.5-GTNH",
|
||||
"package": "com.gtnewhorizons.postea.mixins.late",
|
||||
"refmap": "mixins.postea.refmap.json",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8"
|
||||
}
|
||||
Reference in new issue
Block a user