Compare commits

..
2 Commits
11 changed files with 99 additions and 28 deletions

No files matched your search

+2 -2
View File
@@ -2,7 +2,7 @@
dependencies { dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.9.31:dev") api("com.github.GTNewHorizons:GTNHLib:0.9.31:dev")
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.10:dev') compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.10:dev')
compileOnly('com.falsepattern:chunkapi-mc1.7.10:0.6.0:dev') compileOnly('com.falsepattern:chunkapi-mc1.7.10:0.8.2:dev')
compileOnly('com.falsepattern:endlessids-mc1.7.10:1.6.0:dev') compileOnly('com.falsepattern:endlessids-mc1.7.10:1.7.1:dev')
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.8.71-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.8.71-GTNH:dev") { transitive = false }
} }
@@ -1,14 +1,12 @@
package com.gtnewhorizons.postea.api; package com.gtnewhorizons.postea.api;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
import com.gtnewhorizons.postea.utility.IDRegistry; import com.gtnewhorizons.postea.utility.IDRegistry;
import com.gtnewhorizons.postea.utility.MissingMappingHandler; import com.gtnewhorizons.postea.utility.MissingMappingHandler;
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry; import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
@@ -48,7 +46,7 @@ public abstract class BlockReplacementManager {
* @param transformer The transformer to apply. * @param transformer The transformer to apply.
*/ */
@SuppressWarnings("unused") @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 (originalId == null) throw new IllegalArgumentException("original id is null");
if (transformer == null) throw new IllegalArgumentException("transformer is null"); if (transformer == null) throw new IllegalArgumentException("transformer is null");
TransformerRegistry.addBlockTransformer(originalId, transformer); TransformerRegistry.addBlockTransformer(originalId, transformer);
@@ -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; package com.gtnewhorizons.postea.api;
import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@@ -8,7 +7,6 @@ import javax.annotation.Nonnull;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.gtnewhorizons.postea.utility.IDRegistry; import com.gtnewhorizons.postea.utility.IDRegistry;
@@ -52,8 +50,7 @@ public abstract class ItemStackReplacementManager {
* @param transformer The transformer to apply. * @param transformer The transformer to apply.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void addTransformationHandler(String originalId, public static void addTransformationHandler(String originalId, IItemStackTransformationHandler transformer) {
BiFunction<String, NBTTagCompound, Boolean> transformer) {
if (originalId == null) throw new IllegalArgumentException("original id is null"); if (originalId == null) throw new IllegalArgumentException("original id is null");
if (transformer == null) throw new IllegalArgumentException("transformer is null"); if (transformer == null) throw new IllegalArgumentException("transformer is null");
TransformerRegistry.addStackTransformer(originalId, transformer); 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;
}
}
@@ -29,7 +29,7 @@ public abstract class MixinAnvilChunkLoader {
ChunkFixerUtility.onChunkLoaded(cir.getReturnValue()); 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) { private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
ChunkFixerUtility.onChunkWrite(chunk, nbtTagCompound); 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);
}
}
@@ -1,8 +1,6 @@
package com.gtnewhorizons.postea.utility; package com.gtnewhorizons.postea.utility;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@@ -10,7 +8,9 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
import com.gtnewhorizons.postea.api.IDExtenderCompat; 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. * A registry for simple item and block transformations. A common use case is mod removal, replacements or deprecations.
@@ -114,7 +114,7 @@ public class SimpleTransformationRegistry {
* *
* @implNote This implementation has constant-time runtime. * @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; private final Map<Integer, SimpleTransformationMap.Value<Block>> metaMap;
@@ -123,7 +123,7 @@ public class SimpleTransformationRegistry {
} }
@Override @Override
public Boolean apply(BlockConversionInfo info) { public boolean apply(BlockConversionInfo info) {
SimpleTransformationMap.Value<Block> mapping = SimpleTransformationMap SimpleTransformationMap.Value<Block> mapping = SimpleTransformationMap
.getFromSubMap(metaMap, info.metadata); .getFromSubMap(metaMap, info.metadata);
if (mapping == null || mapping.targetRuntimeId <= -1) return false; if (mapping == null || mapping.targetRuntimeId <= -1) return false;
@@ -176,7 +176,7 @@ public class SimpleTransformationRegistry {
* *
* @implNote This implementation has constant-time runtime. * @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; private final Map<Integer, SimpleTransformationMap.Value<Item>> metaMap;
@@ -185,7 +185,7 @@ public class SimpleTransformationRegistry {
} }
@Override @Override
public Boolean apply(String originalId, NBTTagCompound tag) { public boolean apply(String originalId, NBTTagCompound tag) {
short meta = tag.getShort("Damage"); short meta = tag.getShort("Damage");
SimpleTransformationMap.Value<Item> mapping = SimpleTransformationMap.getFromSubMap(metaMap, meta); SimpleTransformationMap.Value<Item> mapping = SimpleTransformationMap.getFromSubMap(metaMap, meta);
if (mapping == null || mapping.targetRuntimeId <= -1) return false; if (mapping == null || mapping.targetRuntimeId <= -1) return false;
@@ -2,8 +2,6 @@ package com.gtnewhorizons.postea.utility;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -15,7 +13,9 @@ import net.minecraft.world.chunk.Chunk;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.LinkedListMultimap;
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
import com.gtnewhorizons.postea.api.IDExtenderCompat; import com.gtnewhorizons.postea.api.IDExtenderCompat;
import com.gtnewhorizons.postea.api.IItemStackTransformationHandler;
import com.gtnewhorizons.postea.api.TriFunction; import com.gtnewhorizons.postea.api.TriFunction;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
@@ -27,9 +27,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
*/ */
public class TransformerRegistry { 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(); .create();
public static final LinkedListMultimap<String, Function<BlockConversionInfo, Boolean>> BLOCK_REPLACEMENT_MAP = LinkedListMultimap public static final LinkedListMultimap<String, IBlockTransformationHandler> BLOCK_REPLACEMENT_MAP = LinkedListMultimap
.create(); .create();
private static final LinkedListMultimap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> TILE_ENTITY_REPLACEMENT_MAP = LinkedListMultimap private static final LinkedListMultimap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> TILE_ENTITY_REPLACEMENT_MAP = LinkedListMultimap
.create(); .create();
@@ -38,13 +38,13 @@ public class TransformerRegistry {
* Pivoting on the id is faster than pivoting on the strings so this should help with perf a bit. * 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. * 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. * Map of blockIO -> originalName+transformationHandler.
* Pivoting on the id is faster than pivoting on the strings so this should help with perf a bit. * 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. * 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 // region FML Life Cycle handlers
/** /**
@@ -94,7 +94,7 @@ public class TransformerRegistry {
* @param transformer The transformation handler that will execute a transformation on the block. * @param transformer The transformation handler that will execute a transformation on the block.
*/ */
public static void addBlockTransformer(@Nonnull String originalId, public static void addBlockTransformer(@Nonnull String originalId,
@Nonnull Function<BlockConversionInfo, Boolean> transformer) { @Nonnull IBlockTransformationHandler transformer) {
BLOCK_REPLACEMENT_MAP.put(originalId, transformer); BLOCK_REPLACEMENT_MAP.put(originalId, transformer);
} }
@@ -112,7 +112,7 @@ public class TransformerRegistry {
* @param transformer The transformation handler that will execute a transformation on the block. * @param transformer The transformation handler that will execute a transformation on the block.
*/ */
public static void addStackTransformer(@Nonnull String originalId, public static void addStackTransformer(@Nonnull String originalId,
@Nonnull BiFunction<String, NBTTagCompound, Boolean> transformer) { @Nonnull IItemStackTransformationHandler transformer) {
ITEM_REPLACEMENT_MAP.put(originalId, transformer); ITEM_REPLACEMENT_MAP.put(originalId, transformer);
} }
@@ -137,7 +137,7 @@ public class TransformerRegistry {
// region transformation handlers // region transformation handlers
public static @Nullable BlockConversionInfo getBlockReplacement(int blockId, byte metadata, World world, int x, public static @Nullable BlockConversionInfo getBlockReplacement(int blockId, byte metadata, World world, int x,
int y, int z) { 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; if (data == null) return null;
BlockConversionInfo blockConversionInfo = new BlockConversionInfo( BlockConversionInfo blockConversionInfo = new BlockConversionInfo(
// transparently maps the id to the original id if it's a dummy id // transparently maps the id to the original id if it's a dummy id
@@ -148,7 +148,7 @@ public class TransformerRegistry {
y, y,
z, z,
world); world);
for (Function<BlockConversionInfo, Boolean> transformer : data.getValue()) { for (IBlockTransformationHandler transformer : data.getValue()) {
if (transformer.apply(blockConversionInfo)) { if (transformer.apply(blockConversionInfo)) {
return blockConversionInfo; return blockConversionInfo;
} }
@@ -161,12 +161,12 @@ public class TransformerRegistry {
if (tag.hasNoTags() || !tag.hasKey("id")) return; if (tag.hasNoTags() || !tag.hasKey("id")) return;
// get handler // get handler
int id = IDExtenderCompat.getItemStackID(tag); 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 // abort early if handler not found
if (data != null && !data.getValue() if (data != null && !data.getValue()
.isEmpty()) { .isEmpty()) {
// apply handlers // apply handlers
for (BiFunction<String, NBTTagCompound, Boolean> transformer : data.getValue()) { for (IItemStackTransformationHandler transformer : data.getValue()) {
if (transformer.apply(data.getKey(), tag)) { if (transformer.apply(data.getKey(), tag)) {
return; 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"
}