Compare commits

..
5 Commits
Author SHA1 Message Date
Martin Robertz 7b885b8eda sa 2024-01-12 23:13:42 +01:00
Connor Colenso 318af9da8c Spotless + remove debug code 2024-01-12 22:06:07 +00:00
Connor Colenso 152b8d4dc5 Spotless 2024-01-12 21:03:45 +00:00
Connor Colenso b2d44c9654 Optimise block conversion 2024-01-12 20:43:34 +00:00
Connor Colenso b5be252e9e Update README.md 2024-01-12 20:43:20 +00:00
4 changed files with 49 additions and 5 deletions

No files matched your search

+2 -2
View File
@@ -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.
```java
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world) -> {
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
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.
```java
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
BiFunction<BlockConversionInfo, World, BlockConversionInfo> blockTransformer = (blockConversionInfoOld, world) -> {
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
@@ -1,6 +1,7 @@
package com.colen.postea.API;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.function.BiFunction;
@@ -10,7 +11,8 @@ import com.colen.postea.Utility.BlockConversionInfo;
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")
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;
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.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]")
@SuppressWarnings("unused")
@@ -10,4 +17,20 @@ public class Postea {
@Mod.EventHandler
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;
import static com.colen.postea.API.BlockReplacementManager.blockNotConvertible;
import static com.colen.postea.Utility.PosteaUtilities.getModListHash;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@@ -43,6 +45,9 @@ public class ChunkFixerUtility {
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) {
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
@@ -59,12 +64,21 @@ public class ChunkFixerUtility {
byte sectionY = section.getByte("Y");
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 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);
String blockName = GameRegistry.findUniqueIdentifierFor(block)
.toString();
String blockName = loadedBlocks.computeIfAbsent(
block,
b -> GameRegistry.findUniqueIdentifierFor(b)
.toString());
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
blockConversionInfo.blockName = blockName;