mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2641e10174 | ||
|
|
85cacc679c | ||
|
|
727348ecad | ||
|
|
0a612fec9c | ||
|
|
4cebca9e16 |
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.
|
||||
|
||||
```java
|
||||
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
|
||||
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world, chunk) -> {
|
||||
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
||||
});
|
||||
|
||||
@@ -52,6 +52,7 @@ private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
|
||||
return newTag;
|
||||
}
|
||||
```
|
||||
Remember that unlike items, tile entities manually store every tag of their nbt data individually, meaning that any additional tags will be discarded and cannot be used to store additional data unless it is already a part of the new tile entity.
|
||||
|
||||
### 2. Normal Block Transformation
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
dependencies {
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.6.21:dev")
|
||||
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.7:dev')
|
||||
api("com.github.GTNewHorizons:GTNHLib:0.6.38: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')
|
||||
}
|
||||
+1
-1
@@ -151,7 +151,7 @@ modrinthProjectId =
|
||||
# type can be one of [project, version],
|
||||
# and the name is the Modrinth project or version slug/id of the other mod.
|
||||
# Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
|
||||
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
|
||||
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
|
||||
modrinthRelations =
|
||||
|
||||
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ repositories {
|
||||
name = "mavenpattern"
|
||||
url = "https://mvn.falsepattern.com/releases"
|
||||
content {
|
||||
group("com.falsepattern")
|
||||
includeGroup("com.falsepattern")
|
||||
}
|
||||
}
|
||||
mavenLocal()
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.38'
|
||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.41'
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import static com.gtnewhorizons.postea.api.BlockReplacementManager.posteaMarkedI
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLModIdMappingEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||
|
||||
@Mod(
|
||||
@@ -26,7 +26,8 @@ public class Postea {
|
||||
public void preInit(FMLPreInitializationEvent event) {}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStarting(FMLServerAboutToStartEvent event) {
|
||||
public void onIdMappingsChanged(FMLModIdMappingEvent event) {
|
||||
posteaMarkedIDs.clear();
|
||||
for (String name : blockReplacementMap.keySet()) {
|
||||
Block block = Block.getBlockFromName(name);
|
||||
if (block != null) {
|
||||
|
||||
@@ -5,19 +5,40 @@ import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TileEntityReplacementManager {
|
||||
|
||||
private static final HashMap<String, BiFunction<NBTTagCompound, World, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
|
||||
private static final HashMap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @deprecated Superseded by {@link #tileEntityTransformer(String, TriFunction)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void tileEntityTransformer(String tileEntityId,
|
||||
BiFunction<NBTTagCompound, World, BlockInfo> transformerFunction) {
|
||||
tileEntityToNormalBlockTransformer
|
||||
.put(tileEntityId, (tag, world, chunk) -> transformerFunction.apply(tag, world));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback function to transform a tile entity before it's loaded.
|
||||
* Callback returns a {@link BlockInfo} which the tile entity will be transformed into.</br>
|
||||
* Note that the callback will be called before the world is fully loaded, and world.getBlock will throw an error.
|
||||
* Use chunk.getBlock(x & 15, y, z & 15) instead.
|
||||
*
|
||||
* @param tileEntityId ID of the tile entity to be transformed
|
||||
* @param transformerFunction Callback function to transforms the tile entity
|
||||
*/
|
||||
public static void tileEntityTransformer(String tileEntityId,
|
||||
TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformerFunction) {
|
||||
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
||||
}
|
||||
|
||||
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
||||
public static TriFunction<NBTTagCompound, World, Chunk, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
||||
String tileEntityId) {
|
||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TriFunction<T, U, O, R> {
|
||||
|
||||
R apply(T t, U u, O o);
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import static com.gtnewhorizons.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;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -18,6 +17,7 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import com.gtnewhorizons.postea.api.BlockReplacementManager;
|
||||
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
||||
import com.gtnewhorizons.postea.api.TriFunction;
|
||||
import com.gtnewhorizons.postea.compat.Compat;
|
||||
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||
|
||||
@@ -86,7 +86,8 @@ public class ChunkFixerUtility {
|
||||
|
||||
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
||||
levelCompoundTag.getTagList("TileEntities", 10),
|
||||
world);
|
||||
world,
|
||||
chunk);
|
||||
List<ConversionInfo> conversionInfoList = output.first();
|
||||
NBTTagList tileEntities = output.second();
|
||||
|
||||
@@ -116,7 +117,8 @@ public class ChunkFixerUtility {
|
||||
}
|
||||
}
|
||||
|
||||
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
|
||||
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world,
|
||||
Chunk chunk) {
|
||||
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
||||
|
||||
NBTTagList tileEntitiesCopy = new NBTTagList();
|
||||
@@ -126,7 +128,7 @@ public class ChunkFixerUtility {
|
||||
String tileEntityId = tileEntity.getString("id");
|
||||
|
||||
// Check if we have a transformer registered for this tile entity ID
|
||||
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager
|
||||
TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformationFunction = TileEntityReplacementManager
|
||||
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||
|
||||
if (transformationFunction != null) {
|
||||
@@ -134,7 +136,7 @@ public class ChunkFixerUtility {
|
||||
int y = tileEntity.getInteger("y");
|
||||
int z = tileEntity.getInteger("z");
|
||||
|
||||
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world);
|
||||
BlockInfo blockInfo = transformationFunction.apply(tileEntity, world, chunk);
|
||||
if (blockInfo == null) {
|
||||
// Do nothing.
|
||||
tileEntitiesCopy.appendTag(tileEntity);
|
||||
|
||||
Reference in new issue
Block a user