mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-12 16:37:38 +00:00
Add support for multiple mods remapping the same item/block/tile entity.
This commit is contained in:
1 parent
2641e10174
commit
4d2c1ba3fc
5 files changed
+31
-33
No files matched your search
@@ -1,18 +1,18 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
|
||||
public class BlockReplacementManager {
|
||||
|
||||
public static final Map<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
|
||||
public static final LinkedListMultimap<String, BiFunction<BlockConversionInfo, World, BlockConversionInfo>> blockReplacementMap = LinkedListMultimap
|
||||
.create();
|
||||
public static final IntOpenHashSet posteaMarkedIDs = new IntOpenHashSet();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -22,15 +22,12 @@ public class BlockReplacementManager {
|
||||
}
|
||||
|
||||
public static BlockConversionInfo getBlockReplacement(BlockConversionInfo blockConversionInfo, World world) {
|
||||
|
||||
BiFunction<BlockConversionInfo, World, BlockConversionInfo> transformer = blockReplacementMap
|
||||
.getOrDefault(blockConversionInfo.blockName, null);
|
||||
|
||||
if (transformer == null) {
|
||||
return null;
|
||||
} else {
|
||||
return transformer.apply(blockConversionInfo, world);
|
||||
for (BiFunction<BlockConversionInfo, World, BlockConversionInfo> transformer : blockReplacementMap
|
||||
.get(blockConversionInfo.blockName)) {
|
||||
BlockConversionInfo result = transformer.apply(blockConversionInfo, world);
|
||||
if (result != null) return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// We need this to save reprocessing blocks.
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
|
||||
public class ItemStackReplacementManager {
|
||||
|
||||
private static final Map<String, Function<NBTTagCompound, NBTTagCompound>> replacementMap = new HashMap<>();
|
||||
private static final LinkedListMultimap<String, Function<NBTTagCompound, NBTTagCompound>> replacementMap = LinkedListMultimap
|
||||
.create();
|
||||
|
||||
// Public API for converting ItemStacks.
|
||||
|
||||
@@ -18,7 +20,7 @@ public class ItemStackReplacementManager {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static Function<NBTTagCompound, NBTTagCompound> getItemReplacement(String itemNameInternal) {
|
||||
public static Collection<Function<NBTTagCompound, NBTTagCompound>> getItemReplacement(String itemNameInternal) {
|
||||
return replacementMap.get(itemNameInternal);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TileEntityReplacementManager {
|
||||
|
||||
private static final HashMap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
|
||||
private static final LinkedListMultimap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> tileEntityToNormalBlockTransformer = LinkedListMultimap
|
||||
.create();
|
||||
|
||||
/**
|
||||
* @deprecated Superseded by {@link #tileEntityTransformer(String, TriFunction)}.
|
||||
@@ -38,8 +40,8 @@ public class TileEntityReplacementManager {
|
||||
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
||||
}
|
||||
|
||||
public static TriFunction<NBTTagCompound, World, Chunk, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
||||
public static Collection<TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> getTileEntityToNormalBlockTransformerFunction(
|
||||
String tileEntityId) {
|
||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
||||
return tileEntityToNormalBlockTransformer.get(tileEntityId);
|
||||
}
|
||||
}
|
||||
@@ -128,27 +128,26 @@ public class ChunkFixerUtility {
|
||||
String tileEntityId = tileEntity.getString("id");
|
||||
|
||||
// Check if we have a transformer registered for this tile entity ID
|
||||
TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformationFunction = TileEntityReplacementManager
|
||||
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||
boolean found = false;
|
||||
for (TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformationFunction : TileEntityReplacementManager
|
||||
.getTileEntityToNormalBlockTransformerFunction(tileEntityId)) {
|
||||
|
||||
if (transformationFunction != null) {
|
||||
int x = tileEntity.getInteger("x");
|
||||
int y = tileEntity.getInteger("y");
|
||||
int z = tileEntity.getInteger("z");
|
||||
|
||||
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world, chunk);
|
||||
if (blockInfo == null) {
|
||||
// Do nothing.
|
||||
tileEntitiesCopy.appendTag(tileEntity);
|
||||
continue;
|
||||
}
|
||||
if (blockInfo == null) continue;
|
||||
|
||||
if (blockInfo.tileTransformer != null) {
|
||||
tileEntitiesCopy.appendTag(blockInfo.tileTransformer.apply(tileEntity));
|
||||
} // Otherwise they are removed, therefore not appended.
|
||||
|
||||
conversionInfo.add(new ConversionInfo(x, y, z, blockInfo));
|
||||
} else {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found) {
|
||||
// Do nothing.
|
||||
tileEntitiesCopy.appendTag(tileEntity);
|
||||
}
|
||||
|
||||
@@ -23,11 +23,9 @@ public abstract class ItemFixerUtility {
|
||||
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
|
||||
+ GameRegistry.findUniqueIdentifierFor(item).name;
|
||||
|
||||
Function<NBTTagCompound, NBTTagCompound> transformer = ItemStackReplacementManager
|
||||
.getItemReplacement(itemNameInternal);
|
||||
|
||||
if (transformer != null) {
|
||||
transformer.apply(tag);
|
||||
for (Function<NBTTagCompound, NBTTagCompound> transformer : ItemStackReplacementManager
|
||||
.getItemReplacement(itemNameInternal)) {
|
||||
if (transformer.apply(tag) != null) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user