mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b885b8eda | ||
|
|
318af9da8c | ||
|
|
152b8d4dc5 | ||
|
|
b2d44c9654 | ||
|
|
b5be252e9e |
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("Furnace", (tag, world) -> {
|
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
|
||||||
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
|
|||||||
#### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks.
|
#### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
|
BiFunction<BlockConversionInfo, World, BlockConversionInfo> blockTransformer = (blockConversionInfoOld, world) -> {
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
|
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.colen.postea.API;
|
package com.colen.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;
|
||||||
|
|
||||||
@@ -10,7 +11,8 @@ import com.colen.postea.Utility.BlockConversionInfo;
|
|||||||
|
|
||||||
public class BlockReplacementManager {
|
public class BlockReplacementManager {
|
||||||
|
|
||||||
private 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<>();
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static void addBlockReplacement(String blockNameIn,
|
public static void addBlockReplacement(String blockNameIn,
|
||||||
@@ -30,4 +32,9 @@ public class BlockReplacementManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need this to save reprocessing blocks.
|
||||||
|
public static boolean blockNotConvertible(int blockID) {
|
||||||
|
return !posteaMarkedIDs.contains(blockID);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
package com.colen.postea;
|
package com.colen.postea;
|
||||||
|
|
||||||
|
import static com.colen.postea.API.BlockReplacementManager.blockReplacementMap;
|
||||||
|
import static com.colen.postea.API.BlockReplacementManager.posteaMarkedIDs;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
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;
|
||||||
|
|
||||||
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@@ -10,4 +17,20 @@ public class Postea {
|
|||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {}
|
public void preInit(FMLPreInitializationEvent event) {}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStarting(FMLServerAboutToStartEvent event) {
|
||||||
|
for (String name : blockReplacementMap.keySet()) {
|
||||||
|
Block block = Block.getBlockFromName(name);
|
||||||
|
if (block != null) {
|
||||||
|
int id = Block.getIdFromBlock(block);
|
||||||
|
posteaMarkedIDs.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStopping(FMLServerStoppingEvent event) {
|
||||||
|
posteaMarkedIDs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.colen.postea.Utility;
|
package com.colen.postea.Utility;
|
||||||
|
|
||||||
|
import static com.colen.postea.API.BlockReplacementManager.blockNotConvertible;
|
||||||
import static com.colen.postea.Utility.PosteaUtilities.getModListHash;
|
import static com.colen.postea.Utility.PosteaUtilities.getModListHash;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -43,6 +45,9 @@ public class ChunkFixerUtility {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final int AIR_ID = 0;
|
||||||
|
private static final HashMap<Block, String> loadedBlocks = new HashMap<>();
|
||||||
|
|
||||||
private static void transformNormalBlocks(NBTTagCompound levelCompoundTag, World world) {
|
private static void transformNormalBlocks(NBTTagCompound levelCompoundTag, World world) {
|
||||||
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
||||||
|
|
||||||
@@ -59,12 +64,21 @@ public class ChunkFixerUtility {
|
|||||||
byte sectionY = section.getByte("Y");
|
byte sectionY = section.getByte("Y");
|
||||||
|
|
||||||
for (int index = 0; index < blockArray.length / 2; index++) {
|
for (int index = 0; index < blockArray.length / 2; index++) {
|
||||||
|
// Horrible bit jank to recreate the actual IDs, because the array is just a byte array.
|
||||||
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
||||||
int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF);
|
int metadata = ((metadataArray[index * 2] & 0xFF) << 8) | (metadataArray[index * 2 + 1] & 0xFF);
|
||||||
|
|
||||||
|
// Skip air.
|
||||||
|
if (blockId == AIR_ID) continue;
|
||||||
|
// If this block has no registered Postea conversion, skip it.
|
||||||
|
if (blockNotConvertible(blockId)) continue;
|
||||||
|
|
||||||
|
// Cache block names to improve performance, as findUniqueIdentifierFor is expensive.
|
||||||
Block block = Block.getBlockById(blockId);
|
Block block = Block.getBlockById(blockId);
|
||||||
String blockName = GameRegistry.findUniqueIdentifierFor(block)
|
String blockName = loadedBlocks.computeIfAbsent(
|
||||||
.toString();
|
block,
|
||||||
|
b -> GameRegistry.findUniqueIdentifierFor(b)
|
||||||
|
.toString());
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
||||||
blockConversionInfo.blockName = blockName;
|
blockConversionInfo.blockName = blockName;
|
||||||
|
|||||||
Reference in new issue
Block a user