mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-24 05:54:31 +00:00
Compare commits
58
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd4bd60c3e | ||
|
|
bdd8977182 | ||
|
|
b4c46e95be | ||
|
|
e590bbfb61 | ||
|
|
e5eefc8f8b | ||
|
|
82349735e4 | ||
|
|
987ceffb0d | ||
|
|
b03184a934 | ||
|
|
49ef265f85 | ||
|
|
649fa9b5b9 | ||
|
|
2e73e94ed1 | ||
|
|
d14955b5ba | ||
|
|
1df9b851ee | ||
|
|
de78b11610 | ||
|
|
dbcfcbff48 | ||
|
|
71d49fc7d9 | ||
|
|
ef4230fa86 | ||
|
|
ccdd37c38f | ||
|
|
4f8e73f915 | ||
|
|
2e0b571550 | ||
|
|
99907e564c | ||
|
|
490eefc6b7 | ||
|
|
42b5e4d38c | ||
|
|
a803845017 | ||
|
|
7ad4145c0a | ||
|
|
b0df1a2444 | ||
|
|
2067bd1ab0 | ||
|
|
77de0dcac0 | ||
|
|
c59ec9bb36 | ||
|
|
2641e10174 | ||
|
|
85cacc679c | ||
|
|
727348ecad | ||
|
|
0a612fec9c | ||
|
|
4cebca9e16 | ||
|
|
6eff77d785 | ||
|
|
46877823aa | ||
|
|
0999b44caf | ||
|
|
ff224e4b1f | ||
|
|
3c29e17434 | ||
|
|
6c3668c405 | ||
|
|
ef42dfc91f | ||
|
|
361c851706 | ||
|
|
ebb2517488 | ||
|
|
ff97e8841c | ||
|
|
b60e19b434 | ||
|
|
cb9de2d290 | ||
|
|
ec2b6a9007 | ||
|
|
d9ceee01b5 | ||
|
|
d1817ea4c2 | ||
|
|
d168177c1d | ||
|
|
7259ad0a54 | ||
|
|
1f2314a8a5 | ||
|
|
a79bb55395 | ||
|
|
0fda010523 | ||
|
|
1f6f4605b1 | ||
|
|
99c887e67e | ||
|
|
374cad1e5c | ||
|
|
4d247eb701 |
No files matched your search
@@ -3,9 +3,9 @@ name: Build and test
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master, main ]
|
branches: [ master, main, release/** ]
|
||||||
push:
|
push:
|
||||||
branches: [ master, main ]
|
branches: [ master, main, release/** ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-test:
|
build-and-test:
|
||||||
|
|||||||
@@ -1,92 +1,605 @@
|
|||||||
# TileEntityReplacementManager API
|
# Postea
|
||||||
|
|
||||||
This API provides a suite of tools for transforming blocks and items in the game, allowing developers to replace or modify game elements based on specific conditions.
|
This library provides a suite of tools for transforming any existing tile entities, blocks and items the world at
|
||||||
|
runtime. Allowing developers to replace, migrate or modify game elements based on specific conditions.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
1. **Tile Entity Transformation**: Replace or modify Tile Entities in the game.
|
1. **Tile Entity Transformers**: Replace or modify tile entities.
|
||||||
2. **Block Replacement**: Replace normal blocks with another normal block.
|
2. **Block Transformers**: Replace normal blocks with another normal block.
|
||||||
3. **ItemStack Replacement**: Modify or replace items.
|
3. **ItemStack Transformers**: Replace or Modify items.
|
||||||
|
4. **Simple Replacement API**: Efficiently replace or remap large amounts of blocks and items at scale without incurring any noticeable performance impact.
|
||||||
|
5. **Missing Mapping Replacement API**: A set of API endpoints to register actions to be taken when FML detects a missing mapping for a given ID.
|
||||||
|
6. **Numeric ID Identification for Removed Content**: A way to identify the ID of any content that has ceased to exist.
|
||||||
|
7. **Versioned Chunk and Player Transformers**: transform a chunk or a player's data exactly once per version of your content, however many sessions it was saved across.
|
||||||
|
8. **Retired Id Table**: names of removed content keep resolving in every later session.
|
||||||
|
9. **Custom World Data Transformers**: versioned transformation of a mod's own world storage, offered by the mod that owns it.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### 1. Tile Entity Transformation
|
### 1. Tile Entity to Regular Block Transformation
|
||||||
|
|
||||||
#### a. We provide the registered TE ID "GT_TileEntity_Ores" and a lambda function that takes in the NBTTagCompound for any matching tile entity in world and a World and returns a BlockInfo. This will replace all TE's with the ID "GT_TileEntity_Ores" with the block specified in the BlockInfo. The secondary parameter determines the damage value of the block.
|
The `TileEntityReplacementManager` class can be used to register tile entity transformers for any tile entities with
|
||||||
|
the given ID. These transformers usually perform one of 3 types of interactions: Block replacements, NBT transformations
|
||||||
|
and full-on replacements.
|
||||||
|
|
||||||
|
When doing a block replacement, you simply just return a `BlockInfo` without specifying an NBT transformer (the third
|
||||||
|
argument of the constructor). This will replace the existing block and erase the presence of the tile entity being
|
||||||
|
transformed.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> Tile entity transformers are always applied before any block transformers.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> Tile entity, block, and item transformers run once per chunk until the mod list changes (disabled in a dev
|
||||||
|
> environment). For transformations that must run exactly once per version of your own content, use a versioned
|
||||||
|
> transformer (§9).
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
>
|
||||||
|
> Tile entity and block transformers are executed as the chunk data is being read and so the world being passed isn't
|
||||||
|
> fully loaded. **If you try to perform any kind of block access using the world parameter, forge will throw an error.**
|
||||||
|
>
|
||||||
|
> **If you need to perform any kind of block access on the block located at the same place as the tile entity being
|
||||||
|
> transformed use the `BlockAccessCompat`**. These endpoints will fetch the ID and meta value of that block without
|
||||||
|
> causing any errors. You can then compare it to a value obtained from a callback registered using
|
||||||
|
> `BlockReplacementManager.registerIDResolver` to match the block in question.
|
||||||
|
>
|
||||||
|
> If you try to use the chunk, to get a value, you may get an incorrect value if the block that was previously located
|
||||||
|
> at the location of the tile entity no longer exists. The `BlockAccessCompat` endpoints are able to overcome this
|
||||||
|
> issue and will allow you to identify block ids linked to content that no longer exists without the use of a
|
||||||
|
> FMLMissingMapping remap.
|
||||||
|
|
||||||
|
Code example:
|
||||||
```java
|
```java
|
||||||
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> {
|
public abstract class TEToBlockExample {
|
||||||
if (world.provider.dimensionId == -1) {
|
public static void postLoad() {
|
||||||
return new BlockInfo(Blocks.wool, 1);
|
// In this example, we look for any tile entity with the ID of `GT_TileEntity_Ores` and
|
||||||
}
|
// replace it with are regular block with no tile entities. This is specified by returning
|
||||||
if (world.provider.dimensionId == 1) {
|
// a `BlockInfo` that has no nbt transformation function.
|
||||||
return new BlockInfo(Blocks.wool, 2);
|
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world, chunk) -> {
|
||||||
}
|
// yes, it's in great shame that we admit that Gregtech ores used to be tile entities.
|
||||||
return new BlockInfo(Blocks.wool, 3);
|
if (world.provider.dimensionId == -1) {
|
||||||
});
|
// nether gets orange wool
|
||||||
|
return new BlockInfo(Blocks.wool, 1);
|
||||||
|
}
|
||||||
|
if (world.provider.dimensionId == 1) {
|
||||||
|
// the end gets magenta wool
|
||||||
|
return new BlockInfo(Blocks.wool, 2);
|
||||||
|
}
|
||||||
|
// all other dimensions get light blue wool
|
||||||
|
return new BlockInfo(Blocks.wool, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
### 2. Tile Entity NBT Transformations
|
||||||
|
|
||||||
#### 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.
|
If you need to edit an existing tile entity without replacing it, simply perform the modification as usual inside the
|
||||||
|
main transformer function and return a `null` value instead of a `BlockInfo`. This will tell Postea that you haven't
|
||||||
|
done any replacements and that any other handler targeting this tile entity type should also be able to perform their
|
||||||
|
tasks.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> Technically you can also return a `BlockInfo` with the same block and meta value, and a pass though function for the
|
||||||
|
> NBT transformer, _**but this is considered bad practice for pure NBT transformations**_.
|
||||||
|
>
|
||||||
|
> You should also note that when multiple tile entity transformers are registered to a single tile entity ID, they will
|
||||||
|
> always be executed in order of their registrations.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> It's technically more efficient to use Postea to do data migrations since your TE's own code won't have to do extra
|
||||||
|
> checks every time it reads its own NBT data.
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
>
|
||||||
|
> Remember that unlike items, tile entities manually store every tag of their NBT data individually, meaning that any
|
||||||
|
> additional tags will be discarded if the tile entity doesn't read it when it reads it's reloads it's state by
|
||||||
|
> reading it's stored NBT data.
|
||||||
|
|
||||||
|
Code example:
|
||||||
```java
|
```java
|
||||||
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world) -> {
|
public abstract class TEModifyExample {
|
||||||
return new BlockInfo(Blocks.chest, 0, Postea::chestTransformer);
|
|
||||||
});
|
|
||||||
|
|
||||||
private static NBTTagCompound chestTransformer(NBTTagCompound oldTag) {
|
private static int reedsId = -1;
|
||||||
|
private static int diamondId = -1;
|
||||||
|
private static int stoneId = -1;
|
||||||
|
|
||||||
NBTTagCompound newTag = cleanseNBT("Chest", oldTag);
|
private static int record11Id = -1;
|
||||||
|
|
||||||
NBTTagList tagList = new NBTTagList();
|
public static void postLoad() {
|
||||||
|
// pre caching ids like this will lead to faster transformers
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:reeds", i -> reedsId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:diamond", i -> diamondId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:stone", i -> stoneId = i);
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world, chunk) -> {
|
||||||
|
// This transformer replaces all sugar cane stacks inside a chest with
|
||||||
|
// stone, unless it's in the 13th slot at which point it's replaced with
|
||||||
|
// diamonds. All transformations are done without affecting the stack size.
|
||||||
|
NBTTagList slots = tag.getTagList("Items", 10);
|
||||||
|
for (int i = 0; i < slots.tagCount(); i++) {
|
||||||
|
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||||
|
// only target the removed item
|
||||||
|
if (IDExtenderCompat.getItemStackID(slot) != reedsId) continue;
|
||||||
|
if (slot.getByte("Slot") == 13) {
|
||||||
|
// replace it with diamonds if it's in slot 13
|
||||||
|
IDExtenderCompat.setItemStackID(slot, diamondId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// else replace it with stone.
|
||||||
|
IDExtenderCompat.setItemStackID(slot, stoneId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
NBTTagCompound stoneAtSlot13 = new NBTTagCompound();
|
// this tile entity transformer also executes because the other transformer returned null
|
||||||
stoneAtSlot13.setByte("Count", (byte) 1);
|
ItemStackReplacementManager.registerIDResolver("minecraft:record_11", i -> record11Id = i);
|
||||||
stoneAtSlot13.setByte("Slot", (byte) 13);
|
byte targetSLot = (byte) 12;
|
||||||
stoneAtSlot13.setShort("Damage", (short) 0);
|
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world, chunk) -> {
|
||||||
stoneAtSlot13.setShort("id", (short) Block.getIdFromBlock(Blocks.stone));
|
// This transformer looks for the 12th slot of the chest and replaces
|
||||||
|
// or sets it's content to a new stack of record 11 with a stack size of 1.
|
||||||
tagList.appendTag(stoneAtSlot13);
|
NBTTagList slots = tag.getTagList("Items", 10);
|
||||||
|
NBTTagCompound toEdit = null;
|
||||||
newTag.setTag("Items", tagList);
|
for (int i = 0; i < slots.tagCount(); i++) {
|
||||||
|
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||||
return newTag;
|
if (slot.getByte("Slot") != targetSLot) continue;
|
||||||
|
toEdit = slot;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (toEdit == null) {
|
||||||
|
toEdit = new NBTTagCompound();
|
||||||
|
toEdit.setByte("Slot", (byte) targetSLot);
|
||||||
|
slots.appendTag(toEdit);
|
||||||
|
}
|
||||||
|
toEdit.setByte("Count", (byte) 1);
|
||||||
|
toEdit.setShort("Damage", (short) 0);
|
||||||
|
IDExtenderCompat.setItemStackID(toEdit, stoneId);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Normal Block Transformation
|
### 3. Full Tile Entity Replacements
|
||||||
|
|
||||||
#### a. The following example will replace all grass blocks with even x-coordinates with orange wool blocks.
|
If you need to fully replace a tile entity, your tile entity transformer should return a `BlockInfo` that includes an
|
||||||
|
NBT transformation callback.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
>
|
||||||
|
> When you're doing a full replacement, changing the NBT parameter outside the NBT transformation callback is considered
|
||||||
|
> to be bad practice. It's only acceptable, (and even reccomended to do so) if you're performing a pure NBT
|
||||||
|
> transformation like in the last example.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> If your NBT transformer returns `null`, the previous tile entity data will simply be removed. Then what ever block you
|
||||||
|
> specified can now simply create its own tile entity from scratch when it's loaded.
|
||||||
|
|
||||||
|
Code example:
|
||||||
|
```java
|
||||||
|
public abstract class TEFullReplacementExample {
|
||||||
|
|
||||||
|
public static int litFurnaceId = -1;
|
||||||
|
public static int unlitFurnaceId = -1;
|
||||||
|
public static int fireChargeId = -1;
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
BlockReplacementManager.registerIDResolver("minecraft:lit_furnace", i -> litFurnaceId = i);
|
||||||
|
BlockReplacementManager.registerIDResolver("minecraft:furnace", i -> unlitFurnaceId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:fire_charge", i -> fireChargeId = i);
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("Furnace", TEFullReplacementExample::transformFurnace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This transformer transforms a furnace into a chest, and adds a fire charge in the 4th slot of the chest if
|
||||||
|
* the block where the tile entity once stood was a lit furnace. If it's not either a lit or unlit furnace,
|
||||||
|
* the block is simply transformed into air.
|
||||||
|
*
|
||||||
|
* @param tag The NBT data of the tile entity being transformed.
|
||||||
|
* @param world The world in which the tile entity is located.
|
||||||
|
* @param chunk The chunk in which the tile entity is located.
|
||||||
|
* @return Null if we didn't update the block, else a BlockInfo with the transformation data you wish to
|
||||||
|
* execute.
|
||||||
|
*/
|
||||||
|
private static BlockInfo transformFurnace(NBTTagCompound tag, World world, Chunk chunk) {
|
||||||
|
int[] blockIdAndMeta = BlockAccessCompat.getBlockIDAndMetaAtTE(tag, chunk);
|
||||||
|
int blockId = blockIdAndMeta[0];
|
||||||
|
int meta = blockIdAndMeta[1];
|
||||||
|
// we return a value this time because we are actually replacing the block and tile entity.
|
||||||
|
// we copy the meta value since that preserves the orientation for these blocks.
|
||||||
|
return new BlockInfo(Blocks.chest, meta, oldTag -> transformFurnaceNBT(oldTag, blockId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the content of the furnace to the chest and adds a fire charge in the 4th slot if the furnace was lit.
|
||||||
|
*
|
||||||
|
* @param oldTag The current NBT data ofthe tile entity being transformed.
|
||||||
|
* @return null if we want the tile entity to be erased.
|
||||||
|
*/
|
||||||
|
private static NBTTagCompound transformFurnaceNBT(NBTTagCompound oldTag, int blockId) {
|
||||||
|
// if the block wasn't a furnace, clear the current tile entity and let the chest spawn a new one.
|
||||||
|
if (blockId != litFurnaceId && blockId != unlitFurnaceId) return null;
|
||||||
|
// use this function to create a new tile entity tag with the same positional data as the old one.
|
||||||
|
NBTTagCompound newTag = TileEntityReplacementManager.createTETagAtSamePosition("Chest", oldTag);
|
||||||
|
NBTTagList newSlots = (NBTTagList) oldTag.getTagList("Items", 10)
|
||||||
|
.copy();
|
||||||
|
// if the block used to be a lit furnace add a fire charge in the 4th slot.
|
||||||
|
if (blockId == litFurnaceId) {
|
||||||
|
NBTTagCompound fireChargeStack = new NBTTagCompound();
|
||||||
|
IDExtenderCompat.setItemStackID(fireChargeStack, fireChargeId);
|
||||||
|
fireChargeStack.setByte("Slot", (byte) 4);
|
||||||
|
fireChargeStack.setByte("Count", (byte) 1);
|
||||||
|
fireChargeStack.setShort("Damage", (short) 0);
|
||||||
|
newSlots.appendTag(fireChargeStack);
|
||||||
|
}
|
||||||
|
newTag.setTag("Items", newSlots);
|
||||||
|
return newTag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Simple Block and Item Replacements
|
||||||
|
|
||||||
|
If you need to transform an existing block or item into something else, Postea now features a set of API endpoints that
|
||||||
|
let you register "Simple Transformations".
|
||||||
|
|
||||||
|
When applicable, we recommend using these endpoints as they will generally result in a faster execution time than if you
|
||||||
|
were to implement your own handler. Another advantage is that multiple, completely distinct, mods can now target the
|
||||||
|
same item ID for a simple transformation with zero impact to compatibility.
|
||||||
|
|
||||||
|
Simple Transformers can be used to perform one of 4 types of transformations:
|
||||||
|
1. Some block or item with any meta or damage value -> some block or item, preserving the meta or damage value.
|
||||||
|
- Behaves similarly to an FMLMissingMapping remap, but is more effective in the long term as it doesn't cause an ID
|
||||||
|
aliasing.
|
||||||
|
2. Some block or item with any meta or damage value -> some block or item with a specific meta or damage value.
|
||||||
|
3. Some block or item with a specific meda or damage value -> some block or item, preserving the meta or damage value.
|
||||||
|
4. Some block or item with a specific meta or damage value -> some block or item, with a specific meta or damage value.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> These simple transformers can be used to target blocks and items that no longer exist in the world due to a content
|
||||||
|
> or mod removal. Postea can identify the numeric ID of any content that was once registered to a world's ID map. Even
|
||||||
|
> if postea wasn't installed when those mods were installed or removed.
|
||||||
|
>
|
||||||
|
> This also applies to the `BlockReplacementManager.registerIDResolver` and `ItemStackReplacementManager.registerIDResolver`
|
||||||
|
> functions. The callbacks registered by these function will return with a value of -1 which is impossible to get from
|
||||||
|
> the `BlockAccessCompat` functions that return block IDs, (they return 0 (air) when encountering something which isn't
|
||||||
|
> in the known ID map as a failsafe.)
|
||||||
|
>
|
||||||
|
> This means that technically it's better to use simple transformation to migrate removed content as it removes the
|
||||||
|
> need for forge to create any kind of ID aliases which usually need to be resolved at runtime.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> `OreDictionary.WILDCARD_VALUE` has a meaning when registering simple transformations:
|
||||||
|
>
|
||||||
|
> When used as the **source** meta or damage value; Postea will use the transformation being specified as a **fallback**
|
||||||
|
> if nothing has specified a meta or damage transformation for the block or item's current meta or damage value.
|
||||||
|
>
|
||||||
|
> When used as the **target** meta or damage value; Postea will **preserve the existing value** instead of over-writing it.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> When registering block or item conversions, Postea will automatically detect if the given item or block has a block or
|
||||||
|
> item counterpart (respectively) and register an appropriate simple transformation. You can disable this behaviour by
|
||||||
|
> adding a `true` argument to end of all simple transformation endpoints.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> Simple transformations are usually executed after all other complex transformers.
|
||||||
|
|
||||||
|
Code example
|
||||||
|
```java
|
||||||
|
public abstract class SimpleTransformationExample {
|
||||||
|
public static void postLoad() {
|
||||||
|
// item/block -> item/block, preserving the Meta/Damage value.
|
||||||
|
//
|
||||||
|
// remap all block and items of colored stone blocks with wool of the same color
|
||||||
|
BlockReplacementManager.addSimpleReplacement("ExtraUtilities:colorStoneBrick", Blocks.wool);
|
||||||
|
|
||||||
|
// Item/Block with meta -> Item/Block, meta preserved
|
||||||
|
//
|
||||||
|
// angel ring:3 to disk 11
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement("ExtraUtilities:angelRing", 3, new ItemStack(Items.record_11));
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement("ExtraUtilities:angelRing", 4, new ItemStack(Items.record_13));
|
||||||
|
|
||||||
|
// Item/Block with meta -> Item/Block with specific meta
|
||||||
|
//
|
||||||
|
// remap all compressed cobble to oak planks
|
||||||
|
//
|
||||||
|
// When using a stack as a target the passed stack size is ignored,
|
||||||
|
// only the contained item and meta value are kept.
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", 0, new ItemStack(Blocks.planks, 0, 0));
|
||||||
|
|
||||||
|
// block only with meta -> block with specific meta value.
|
||||||
|
//
|
||||||
|
// remap blocks of double compressed cobble to cobble.
|
||||||
|
BlockReplacementManager.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", 1, Blocks.cobblestone, 0, true);
|
||||||
|
// item only with damage -> item only with specific damage value.
|
||||||
|
//
|
||||||
|
// remap stacks of double compressed cobble to oak saplings.
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", 1,new ItemStack(Blocks.sapling, 1, 0), true);
|
||||||
|
|
||||||
|
// Block/Item with any Meta/Damage -> Block/Item with specific Meta/Damage value.
|
||||||
|
//
|
||||||
|
// Using OreDictionary.WILDCARD_VALUE will tell postea to use this mapping as a fallback when
|
||||||
|
// there is no transformer targeting the specific meta/damage value of the block/item.
|
||||||
|
//
|
||||||
|
// remap all other instances of compressed blocks to endstone
|
||||||
|
BlockReplacementManager.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", OreDictionary.WILDCARD_VALUE, Blocks.end_stone, 0);
|
||||||
|
|
||||||
|
// Block/Item with any Meta/Damage -> Block/Item, preserving the Meta/Damage value.
|
||||||
|
//
|
||||||
|
// When passing OreDictionary.WILDCARD_VALUE as the target Meta/Damage value, Postea will
|
||||||
|
// preserve any existing Meta/Damage value. This is also the default value when you don't
|
||||||
|
// specify a target meta value.
|
||||||
|
//
|
||||||
|
// remap all other instances of compressed blocks to endstone
|
||||||
|
BlockReplacementManager.addSimpleReplacement(
|
||||||
|
"ExtraUtilities:cobblestone_compressed",
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
Blocks.end_stone,
|
||||||
|
OreDictionary.WILDCARD_VALUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Complex Block Transformers
|
||||||
|
|
||||||
|
If you need some custom logic in order to perform a block conversion, you can register a custom transformer using
|
||||||
|
`BlockReplacementManager.addTransformationHandler`.
|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
>
|
||||||
|
> Returning `true` tells Postea to stop looking for any other handlers for the current block, and to replace the block
|
||||||
|
> being transformed using the `blockID` and `metadata` currently stored in the `BlockConversionInfo` parameter.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
>
|
||||||
|
> Just like for Tile Entity transformers, trying to perform block access using the world provided by the
|
||||||
|
> BlockTransformationInfo parameter will result in an error as the transformers are executed before the world's content
|
||||||
|
> are properly initialized.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
BiFunction<BlockConversionInfo, World, BlockConversionInfo> blockTransformer = (blockConversionInfoOld, world) -> {
|
public abstract class ComplexBlockTransformer {
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfoNew = new BlockConversionInfo();
|
private static int woolId = -1;
|
||||||
|
|
||||||
if ((blockConversionInfoOld.x % 2 == 0)) {
|
public static void postLoad() {
|
||||||
blockConversionInfoNew.blockID = Block.getIdFromBlock(Blocks.wool);
|
// This transformer replaces all grass blocks with even x-coordinates with orange wool.
|
||||||
blockConversionInfoNew.metadata = 1;
|
BlockReplacementManager.registerIDResolver("minecraft:wool", i -> woolId = i);
|
||||||
} else {
|
BlockReplacementManager.addTransformationHandler("minecraft:grass", ComplexBlockTransformer::transformGrass);
|
||||||
blockConversionInfoNew.blockID = blockConversionInfoOld.blockID;
|
}
|
||||||
blockConversionInfoNew.metadata = blockConversionInfoOld.metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
return blockConversionInfoNew;
|
private static boolean transformGrass(BlockConversionInfo info) {
|
||||||
};
|
// only affect blocks that are on even x coordinates
|
||||||
|
if (info.x % 2 != 0) return false;
|
||||||
|
// transform all these blocks into orange wool.
|
||||||
|
info.blockID = woolId;
|
||||||
|
info.metadata = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer);
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### 3. ItemStack Transformation
|
### 6. Stack Transformation
|
||||||
|
|
||||||
#### a. The following example will replace all iron ingots with gold ingots.
|
If you need some custom logic in order to perform an item conversion, you can register a custom transformer using
|
||||||
|
`ItemStackReplacementManager.addTransformationHandler`.
|
||||||
|
|
||||||
|
Code example:
|
||||||
```java
|
```java
|
||||||
Function<NBTTagCompound, NBTTagCompound> itemTransformer = (tag) -> {
|
public abstract class ComplexItemTransformer {
|
||||||
tag.setShort("id", (short) Item.getIdFromItem(Items.gold_ingot));
|
|
||||||
return tag;
|
|
||||||
};
|
|
||||||
|
|
||||||
ItemStackReplacementManager.addItemReplacement("minecraft:iron_ingot", itemTransformer);
|
private static int writableBookId = -1;
|
||||||
|
private static int woolId = -1;
|
||||||
|
|
||||||
|
private static void postLoad() {
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:writable_book", i -> writableBookId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:wool", i -> woolId = i);
|
||||||
|
ItemStackReplacementManager.addTransformationHandler("minecraft:written_book", ComplexItemTransformer::unsignBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This transformer transforms a written book into either an unsigned book or orange wool depending on it's title.
|
||||||
|
*
|
||||||
|
* @param name The name of the item being transformed, even if that item doesn't exist anymore.
|
||||||
|
* @param nbt The NBT data of the stack item being transformed.
|
||||||
|
* @return True if we've actually transformed the item.
|
||||||
|
*/
|
||||||
|
private static boolean unsignBook(String name, NBTTagCompound nbt) {
|
||||||
|
// check if the book has a title.
|
||||||
|
if (!nbt.hasKey("tag",10)) return false;
|
||||||
|
NBTTagCompound tag = nbt.getCompoundTag("tag");
|
||||||
|
if (!tag.hasKey("title", 8)) return false;
|
||||||
|
String title = tag.getString("title");
|
||||||
|
if (title.equalsIgnoreCase("unsign me")) {
|
||||||
|
// unsign the book
|
||||||
|
IDExtenderCompat.setItemStackID(nbt, writableBookId);
|
||||||
|
nbt.setShort("Damage", (short) 0);
|
||||||
|
nbt.setByte("Count", (byte) 1);
|
||||||
|
// clear the signed book nbt
|
||||||
|
tag.removeTag("title");
|
||||||
|
tag.removeTag("author");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (title.equalsIgnoreCase("orange wool")) {
|
||||||
|
// Transform it into orange wool.
|
||||||
|
IDExtenderCompat.setItemStackID(nbt, woolId);
|
||||||
|
nbt.setShort("Damage", (short) 1);
|
||||||
|
nbt.setByte("Count", (byte) 1);
|
||||||
|
// removes the NBT tag from the stack.
|
||||||
|
nbt.removeTag("tag");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 7. Remapping Missing Mappings using FML
|
||||||
|
|
||||||
|
Postea provides a few API endpoints to quickly register re-mappings for any given Item or Block that has been removed.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> It's generally more advisable to use the simple transformers instead as they will create less overhead in the
|
||||||
|
> long term.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
>
|
||||||
|
> If you try to remap something to a block or item that already has ever existed at a prior date inside a world,
|
||||||
|
> (eg: remapping to a block of dirt or stick, or something from your own mod that has existed for a while) FML will
|
||||||
|
> throw an error when it loads the world and tell you that your world is corrupted.
|
||||||
|
>
|
||||||
|
> Simple Transformers are generally safer in that regard and do not care if a thing has ever existed in a world before.
|
||||||
|
> Therefore we generally recommend using them instead of FML re-mappings.
|
||||||
|
|
||||||
|
Code example:
|
||||||
|
```java
|
||||||
|
public abstract class FMLReMappingExample {
|
||||||
|
|
||||||
|
// You have to make your own block class since the block constructor is protected.
|
||||||
|
public static class MyBlock extends Block {
|
||||||
|
protected MyBlock() {
|
||||||
|
super(Material.ground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// this only works when the thing you're replacing with has never been registered to a world's
|
||||||
|
// ID map. If you try to run this with a block that already exists (eg good old dirt), FML
|
||||||
|
// error out and you that your world is corrupted beyond repair, and advise you to undo what
|
||||||
|
// ever you just did.
|
||||||
|
//
|
||||||
|
// Postea Simple Transformers don't have that issue and are more lag friendly in the long term.
|
||||||
|
// Consider using them when ever possible, instead of FML mappings.
|
||||||
|
Item item = new Item();
|
||||||
|
GameRegistry.registerItem(item, "my_item");
|
||||||
|
ItemStackReplacementManager.replaceMissingMapping("IC2:itemFertilizer", item);
|
||||||
|
|
||||||
|
// This also remaps the stacks of IC2:blockCrop
|
||||||
|
Block block = new MyBlock();
|
||||||
|
GameRegistry.registerBlock(block, "my_block");
|
||||||
|
BlockReplacementManager.replaceMissingMapping("IC2:blockCrop", block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. Ignoring Missing Mappings from FML
|
||||||
|
|
||||||
|
Postea provides a few API endpoints that let you tell FML to hide any missing mapping warnings regarding that ID when
|
||||||
|
loading a world.
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> You should only register an ignore mapping when you know that your transformers fully replace what ever used to be
|
||||||
|
> associated with the given ID.
|
||||||
|
|
||||||
|
Code example:
|
||||||
|
```java
|
||||||
|
public abstract class FMLIgnoreMissingMappingExample {
|
||||||
|
public static void postLoad() {
|
||||||
|
// It doesn't really matter which one you use, they both do the same thing under the hood.
|
||||||
|
ItemStackReplacementManager.ignoreMissingMapping("IC2:itemFertilizer");
|
||||||
|
BlockReplacementManager.ignoreMissingMapping("IC2:blockCrop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 9. Versioned Transformers
|
||||||
|
|
||||||
|
Postea provides some API endpoints to allow mods to have versioned changes. The mod declares that it
|
||||||
|
expects some version, and if Postea detects that a chunk or player was saved on a previous version, runs a transformer
|
||||||
|
to bring them up-to-date. Register an `IVersionedTransformer` through `VersionedReplacementManager.register`.
|
||||||
|
|
||||||
|
Some mods keep item stacks stored outside chunks or player data. Postea provides an API, `CustomDataReplacementManager`,
|
||||||
|
for those mods to allow that data to be transformed by an `IVersionedTransformer`.
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
>
|
||||||
|
> Versioned transformers run before every other Postea pass, in registration order, and are never disabled in a dev
|
||||||
|
> environment. Data saved before a transformer existed reads as `UNSTAMPED`; the transformer decides what that means.
|
||||||
|
|
||||||
|
> [!CAUTION]
|
||||||
|
>
|
||||||
|
> Chunk transformers may run on a chunk I/O thread, several concurrently for different chunks. They must not touch
|
||||||
|
> world state beyond the context, and their own state must be safe to read concurrently. As with the other chunk-read
|
||||||
|
> passes, `ChunkTransformContext.world()` cannot be used for block access.
|
||||||
|
>
|
||||||
|
> When a transformer changes a block id, Postea recomputes the chunk's height map and flags it for a relight once
|
||||||
|
> every transformer has run; nothing is recomputed for metadata-only changes.
|
||||||
|
>
|
||||||
|
> An exception thrown by a transformer crashes the game, with the key, both versions, and the chunk or player named in
|
||||||
|
> the crash report. This is deliberate: a half-transformed chunk stamped at the current version could never be
|
||||||
|
> recovered.
|
||||||
|
|
||||||
|
Code example:
|
||||||
|
```java
|
||||||
|
public final class VersionedExample implements IVersionedTransformer {
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
VersionedReplacementManager.register(new VersionedExample());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return "examplemod:gemIndex";
|
||||||
|
}
|
||||||
|
|
||||||
|
// The version the running mod writes gems under; bump it whenever the index assignment changes.
|
||||||
|
@Override
|
||||||
|
public int currentVersion() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transformChunk(ChunkTransformContext ctx) {
|
||||||
|
// Data saved before this transformer existed carries no stamp.
|
||||||
|
if (ctx.storedVersion() == ChunkTransformContext.UNSTAMPED || ctx.storedVersion() == 1) {
|
||||||
|
int gemBlockId = Block.getIdFromBlock(ExampleMod.gemBlock);
|
||||||
|
ctx.forEachBlock((x, y, z, id, meta) -> {
|
||||||
|
if (id == gemBlockId) ctx.setBlock(x, y, z, id, meta + 1);
|
||||||
|
});
|
||||||
|
ctx.forEachItemStackTag(stack -> {
|
||||||
|
if (IDExtenderCompat.getItemStackID(stack) == Item.getIdFromItem(ExampleMod.gemItem)) {
|
||||||
|
stack.setShort("Damage", (short) (stack.getShort("Damage") + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transformPlayer(PlayerDataTransformContext ctx) {
|
||||||
|
if (ctx.storedVersion() == PlayerDataTransformContext.UNSTAMPED || ctx.storedVersion() == 1) {
|
||||||
|
ctx.forEachItemStackTag(stack -> {
|
||||||
|
if (IDExtenderCompat.getItemStackID(stack) == Item.getIdFromItem(ExampleMod.gemItem)) {
|
||||||
|
stack.setShort("Damage", (short) (stack.getShort("Damage") + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 10. Retired Ids
|
||||||
|
|
||||||
|
Whenever a world loads, every block or item name in its saved id map that no longer exists is recorded, with the id it
|
||||||
|
held, in `<world>/postea/known-ids.json`. This way, retired objects can still be referenced by transformers.
|
||||||
|
|
||||||
|
When a name resolves only through retired ids, Postea logs it once per world load:
|
||||||
|
|
||||||
|
```
|
||||||
|
Block ExtraUtilities:cobblestone_compressed is no longer registered; its transformers target retired id(s) [3402]
|
||||||
|
```
|
||||||
+4
-1600
File diff suppressed because it is too large.
Load diff
+10
-1
@@ -1,4 +1,13 @@
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api('com.github.GTNewHorizons:NotEnoughIds:1.5.4-pre:dev')
|
api("com.github.GTNewHorizons:GTNHLib:0.9.39:dev")
|
||||||
|
compileOnly('com.github.GTNewHorizons:NotEnoughIds:2.1.10:dev')
|
||||||
|
compileOnly('com.falsepattern:endlessids-mc1.7.10:1.7.1:dev')
|
||||||
|
compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.8.75-GTNH:dev") { transitive = false }
|
||||||
|
|
||||||
|
testImplementation(platform('org.junit:junit-bom:5.11.4'))
|
||||||
|
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||||
|
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
|
||||||
|
// fastutil is only on the compile/runtime classpath via the patched Minecraft jar, not the plain test JVM.
|
||||||
|
testRuntimeOnly('it.unimi.dsi:fastutil:8.5.18')
|
||||||
}
|
}
|
||||||
+138
-52
@@ -1,77 +1,135 @@
|
|||||||
|
# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable.
|
||||||
|
# LOCAL to test local config updates.
|
||||||
|
gtnh.settings.blowdryerTag = 0.2.2
|
||||||
|
|
||||||
|
# Human-readable mod name, available for mcmod.info population.
|
||||||
modName = Postea
|
modName = Postea
|
||||||
|
|
||||||
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
|
# Case-sensitive identifier string, available for mcmod.info population and used for automatic mixin JSON generation.
|
||||||
|
# Conventionally lowercase.
|
||||||
modId = postea
|
modId = postea
|
||||||
|
|
||||||
modGroup = com.colen.postea
|
# Root package of the mod, used to find various classes in other properties,
|
||||||
|
# mcmod.info substitution, enabling assertions in run tasks, etc.
|
||||||
|
modGroup = com.gtnewhorizons.postea
|
||||||
|
|
||||||
# WHY is there no version field?
|
# Whether to use modGroup as the maven publishing group.
|
||||||
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
|
# When false, com.github.GTNewHorizons is used.
|
||||||
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/
|
useModGroupForPublishing = false
|
||||||
|
|
||||||
# Will update your build.gradle automatically whenever an update is available
|
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
|
||||||
autoUpdateBuildScript = false
|
autoUpdateBuildScript = false
|
||||||
|
|
||||||
|
# Version of Minecraft to target
|
||||||
minecraftVersion = 1.7.10
|
minecraftVersion = 1.7.10
|
||||||
|
|
||||||
|
# Version of Minecraft Forge to target
|
||||||
forgeVersion = 10.13.4.1614
|
forgeVersion = 10.13.4.1614
|
||||||
|
|
||||||
# Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task.
|
# Specify an MCP channel for dependency deobfuscation and the deobfParams task.
|
||||||
channel = stable
|
channel = stable
|
||||||
|
|
||||||
|
# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task.
|
||||||
mappingsVersion = 12
|
mappingsVersion = 12
|
||||||
|
|
||||||
# Define other MCP mappings for dependency deobfuscation
|
# Defines other MCP mappings for dependency deobfuscation.
|
||||||
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
|
remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
|
||||||
|
|
||||||
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
|
# Select a default username for testing your mod. You can always override this per-run by running
|
||||||
# restart Minecraft in development. Choose this dependent on your mod:
|
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
|
||||||
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
|
|
||||||
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
|
|
||||||
developmentEnvironmentUserName = Developer
|
developmentEnvironmentUserName = Developer
|
||||||
|
|
||||||
# Enables using modern java syntax (up to version 17) via Jabel, while still targeting JVM 8.
|
# Enables modern Java syntax support. Valid values:
|
||||||
# See https://github.com/bsideup/jabel for details on how this works.
|
# - false: No modern syntax, Java 8 only
|
||||||
enableModernJavaSyntax = true
|
# - jabel: Jabel syntax-only support, compiles to J8 bytecode
|
||||||
|
# - jvmDowngrader: Full modern Java via JVM Downgrader (syntax + stdlib APIs)
|
||||||
|
# - modern: Native modern Java bytecode, no downgrading
|
||||||
|
enableModernJavaSyntax = jabel
|
||||||
|
|
||||||
# Enables injecting missing generics into the decompiled source code for a better coding experience
|
# If set, ignores the above setting and compiles with the given toolchain. This may cause unexpected issues,
|
||||||
# Turns most publicly visible List, Map, etc. into proper List<Type>, Map<K, V> types
|
# and should *not* be used in most situations. -1 disables this.
|
||||||
|
# forceToolchainVersion = -1
|
||||||
|
|
||||||
|
# Target JVM version for JVM Downgrader bytecode downgrading.
|
||||||
|
# Only used when enableModernJavaSyntax = jvmDowngrader
|
||||||
|
# downgradeTargetVersion = 8
|
||||||
|
|
||||||
|
# Comma-separated list of Java versions for multi-release jar support (JVM Downgrader only).
|
||||||
|
# Classes will be available in META-INF/versions/N/ for each version N in this list.
|
||||||
|
# Default: "21,25" (J25+ gets native classes, J21-24 gets partial downgrade, J8-20 gets full downgrade).
|
||||||
|
# jvmDowngraderMultiReleaseVersions = 21,25
|
||||||
|
|
||||||
|
# Specifies how JVM Downgrader API stubs are provided. Options:
|
||||||
|
# - shade: Shade minimized stubs into the jar
|
||||||
|
# - gtnhlib: GTNHLib provides stubs at runtime (adds version constraint)
|
||||||
|
# - external: Another dependency provides stubs (no constraint, no warning)
|
||||||
|
# - (empty): Warning reminding you to configure stubs
|
||||||
|
# Note: 'shade' option requires you to verify license compliance, see: https://github.com/unimined/JvmDowngrader/blob/main/LICENSE.md
|
||||||
|
# jvmDowngraderStubsProvider =
|
||||||
|
|
||||||
|
# Enables injecting missing generics into the decompiled source code for a better coding experience.
|
||||||
|
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
|
||||||
enableGenericInjection = false
|
enableGenericInjection = false
|
||||||
|
|
||||||
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
|
# Generate a class with a String field for the mod version named as defined below.
|
||||||
generateGradleTokenClass = com.colen.postea.Tags
|
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
|
||||||
gradleTokenModId = MODID
|
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
|
||||||
gradleTokenModName = MODNAME
|
generateGradleTokenClass = com.gtnewhorizons.postea.Tags
|
||||||
|
|
||||||
|
# Name of the token containing the project's current version to generate/replace.
|
||||||
gradleTokenVersion = VERSION
|
gradleTokenVersion = VERSION
|
||||||
gradleTokenGroupName = GROUPNAME
|
|
||||||
|
# [DEPRECATED] Mod ID replacement token.
|
||||||
|
gradleTokenModId =
|
||||||
|
|
||||||
|
# [DEPRECATED] Mod name replacement token.
|
||||||
|
gradleTokenModName =
|
||||||
|
|
||||||
|
# [DEPRECATED] Mod Group replacement token.
|
||||||
|
gradleTokenGroupName =
|
||||||
|
|
||||||
# [DEPRECATED]
|
# [DEPRECATED]
|
||||||
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
|
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
|
||||||
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
# public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||||
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
|
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
|
||||||
# version in @Mod([...], version = VERSION, [...])
|
# version in @Mod([...], version = VERSION, [...]).
|
||||||
# Leave these properties empty to skip individual token replacements
|
# Leave these properties empty to skip individual token replacements.
|
||||||
replaceGradleTokenInFile =
|
replaceGradleTokenInFile =
|
||||||
|
|
||||||
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
|
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
|
||||||
# leave this property empty.
|
# leave this property empty.
|
||||||
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
|
# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api
|
||||||
apiPackage =
|
apiPackage =
|
||||||
|
|
||||||
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
|
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
|
||||||
# There can be multiple files in a comma-separated list.
|
# There can be multiple files in a space-separated list.
|
||||||
# Example value: mymodid_at.cfg,nei_at.cfg
|
# Example value: mymodid_at.cfg nei_at.cfg
|
||||||
accessTransformersFile =
|
accessTransformersFile =
|
||||||
|
|
||||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||||
usesMixins = true
|
usesMixins = true
|
||||||
# Adds some debug arguments like verbose output and export
|
|
||||||
|
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
|
||||||
|
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
|
||||||
|
# Mixin classes will have access to "main" classes, but not the other way around.
|
||||||
|
separateMixinSourceSet =
|
||||||
|
|
||||||
|
# Adds some debug arguments like verbose output and class export.
|
||||||
usesMixinDebug = true
|
usesMixinDebug = true
|
||||||
|
|
||||||
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
||||||
mixinPlugin =
|
mixinPlugin =
|
||||||
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
|
|
||||||
|
# Specify the package that contains all of your Mixins. The package must exist or
|
||||||
|
# the build will fail. If you have a package property defined in your mixins.<modid>.json,
|
||||||
|
# it must match with this or the build will fail.
|
||||||
mixinsPackage = mixins
|
mixinsPackage = mixins
|
||||||
|
|
||||||
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
||||||
# This parameter is for legacy compatibility only
|
# This parameter is for legacy compatibility only
|
||||||
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
|
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
|
||||||
coreModClass = mixins.PosteaLoadingPlugin
|
coreModClass = mixins.PosteaLoadingPlugin
|
||||||
|
|
||||||
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
|
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
|
||||||
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
|
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
|
||||||
containsMixinsAndOrCoreModOnly = false
|
containsMixinsAndOrCoreModOnly = false
|
||||||
@@ -79,28 +137,38 @@ containsMixinsAndOrCoreModOnly = false
|
|||||||
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
|
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
|
||||||
forceEnableMixins = true
|
forceEnableMixins = true
|
||||||
|
|
||||||
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
|
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
|
||||||
# responsibility check the licence and request permission for distribution, if required.
|
# responsibility to check the license and request permission for distribution if required.
|
||||||
usesShadowedDependencies = false
|
usesShadowedDependencies = false
|
||||||
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
|
|
||||||
|
# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
|
||||||
# their own classes, making the minimization unreliable.
|
# their own classes, making the minimization unreliable.
|
||||||
minimizeShadowedDependencies = true
|
minimizeShadowedDependencies = true
|
||||||
|
|
||||||
# If disabled, won't rename the shadowed classes.
|
# If disabled, won't rename the shadowed classes.
|
||||||
relocateShadowedDependencies = true
|
relocateShadowedDependencies = true
|
||||||
|
|
||||||
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories
|
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
|
||||||
includeWellKnownRepositories = true
|
includeWellKnownRepositories = true
|
||||||
|
|
||||||
|
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
|
||||||
|
# list of strings, with the acceptable keys being(case does not matter):
|
||||||
|
# cursemaven
|
||||||
|
# modrinth
|
||||||
|
excludeWellKnownRepositories =
|
||||||
|
|
||||||
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
||||||
# Authenticate with the MAVEN_USERNAME and MAVEN_PASSWORD environment variables.
|
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
|
||||||
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
|
||||||
usesMavenPublishing = true
|
usesMavenPublishing = true
|
||||||
# mavenPublishUrl = http://jenkins.usrv.eu:8081/nexus/content/repositories/releases
|
|
||||||
|
|
||||||
# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.
|
# Maven repository to publish the mod to.
|
||||||
|
# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/
|
||||||
|
|
||||||
|
# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
|
||||||
|
#
|
||||||
# The project's ID on Modrinth. Can be either the slug or the ID.
|
# The project's ID on Modrinth. Can be either the slug or the ID.
|
||||||
# Leave this empty if you don't want to publish on Modrinth.
|
# Leave this empty if you don't want to publish to Modrinth.
|
||||||
modrinthProjectId =
|
modrinthProjectId =
|
||||||
|
|
||||||
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
|
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
|
||||||
@@ -109,12 +177,11 @@ modrinthProjectId =
|
|||||||
# type can be one of [project, version],
|
# type can be one of [project, version],
|
||||||
# and the name is the Modrinth project or version slug/id of the other mod.
|
# 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
|
# 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 =
|
modrinthRelations =
|
||||||
|
|
||||||
|
|
||||||
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
|
||||||
|
#
|
||||||
# The project's numeric ID on CurseForge. You can find this in the About Project box.
|
# The project's numeric ID on CurseForge. You can find this in the About Project box.
|
||||||
# Leave this empty if you don't want to publish on CurseForge.
|
# Leave this empty if you don't want to publish on CurseForge.
|
||||||
curseForgeProjectId =
|
curseForgeProjectId =
|
||||||
@@ -124,29 +191,48 @@ curseForgeProjectId =
|
|||||||
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
|
||||||
# and the name is the CurseForge project slug of the other mod.
|
# and the name is the CurseForge project slug of the other mod.
|
||||||
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
|
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
|
||||||
# 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.
|
||||||
curseForgeRelations =
|
curseForgeRelations =
|
||||||
|
|
||||||
|
# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older
|
||||||
# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
|
|
||||||
# projects. New projects should not use this parameter.
|
# projects. New projects should not use this parameter.
|
||||||
# customArchiveBaseName =
|
# customArchiveBaseName =
|
||||||
|
|
||||||
# Optional parameter to prevent the source code from being published
|
# Optional parameter to customize the default working directory used by the runClient* tasks. Relative to the project directory.
|
||||||
# noPublishedSources =
|
# runClientWorkingDirectory = run/client
|
||||||
|
|
||||||
# Uncomment this to disable spotless checks
|
# Optional parameter to customize the default working directory used by the runServer* tasks. Relative to the project directory.
|
||||||
|
# runServerWorkingDirectory = run/server
|
||||||
|
|
||||||
|
# Optional parameter to have the build automatically fail if an illegal version is used.
|
||||||
|
# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'.
|
||||||
|
# The check is ONLY performed if the version is a git tag.
|
||||||
|
# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+
|
||||||
|
# versionPattern =
|
||||||
|
|
||||||
|
# Uncomment to prevent the source code from being published.
|
||||||
|
# noPublishedSources = true
|
||||||
|
|
||||||
|
# Uncomment this to disable Spotless checks.
|
||||||
# This should only be uncommented to keep it easier to sync with upstream/other forks.
|
# This should only be uncommented to keep it easier to sync with upstream/other forks.
|
||||||
# That is, if there is no other active fork/upstream, NEVER change this.
|
# That is, if there is no other active fork/upstream, NEVER change this.
|
||||||
# disableSpotless = true
|
# disableSpotless = true
|
||||||
|
|
||||||
# Uncomment this to disable checkstyle checks (currently wildcard import check).
|
# Uncomment this to disable Checkstyle checks (currently wildcard import check).
|
||||||
# disableCheckstyle = true
|
# disableCheckstyle = true
|
||||||
|
|
||||||
# Override the IDEA build type. Valid value is "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
|
# Override the IDEA build type. Valid values are: "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
|
||||||
# (force use delegated build).
|
# (force use delegated build).
|
||||||
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
||||||
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be always native build.
|
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be native build.
|
||||||
# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want!
|
# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want!
|
||||||
# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you.
|
# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you.
|
||||||
# ideaOverrideBuildType = idea
|
# ideaOverrideBuildType = idea
|
||||||
|
|
||||||
|
# Whether IDEA should run spotless checks when pressing the Build button.
|
||||||
|
# This is meant to be set in $HOME/.gradle/gradle.properties.
|
||||||
|
# ideaCheckSpotlessOnBuild = true
|
||||||
|
|
||||||
|
# Non-GTNH properties
|
||||||
|
org.gradle.configuration-cache = true
|
||||||
|
org.gradle.parallel = true
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#This file is generated by updateDaemonJvm
|
||||||
|
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||||
|
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||||
|
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||||
|
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||||
|
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d4fd992c9557644e637ebe98263e0ae7/redirect
|
||||||
|
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/59a9771cad43219260d9aac9a8ec4d6a/redirect
|
||||||
|
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
|
||||||
|
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
|
||||||
|
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/a4c09dd2e2d7079373d30e524bbc2829/redirect
|
||||||
|
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
|
||||||
|
toolchainVersion=25
|
||||||
Vendored
BIN
Binary file not shown.
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright © 2015-2021 the original authors.
|
# Copyright © 2015 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/b631911858264c0b6e4d6603d677ff5218766cee/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@@ -83,7 +85,8 @@ done
|
|||||||
# This is normally unused
|
# This is normally unused
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -111,7 +114,6 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -144,7 +146,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
@@ -152,7 +154,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
# shellcheck disable=SC3045
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@@ -169,7 +171,6 @@ fi
|
|||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
if "$cygwin" || "$msys" ; then
|
if "$cygwin" || "$msys" ; then
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
@@ -201,16 +202,15 @@ fi
|
|||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
# Collect all arguments for the java command:
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
# and any embedded shellness will be escaped.
|
||||||
# double quotes to make sure that they get re-expanded; and
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|||||||
Vendored
+13
-12
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
|
|||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@@ -57,22 +59,21 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
// Add any additional repositories for your dependencies here
|
// Add any additional repositories for your dependencies here
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven {
|
||||||
|
name = "mavenpattern"
|
||||||
|
url = "https://mvn.falsepattern.com/releases"
|
||||||
|
content {
|
||||||
|
includeGroup("com.falsepattern")
|
||||||
|
}
|
||||||
|
}
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
+5
-10
@@ -4,10 +4,10 @@ pluginManagement {
|
|||||||
maven {
|
maven {
|
||||||
// RetroFuturaGradle
|
// RetroFuturaGradle
|
||||||
name "GTNH Maven"
|
name "GTNH Maven"
|
||||||
url "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
|
url "https://nexus.gtnewhorizons.com/repository/public/"
|
||||||
allowInsecureProtocol = true
|
|
||||||
mavenContent {
|
mavenContent {
|
||||||
includeGroup("com.gtnewhorizons.retrofuturagradle")
|
includeGroup("com.gtnewhorizons")
|
||||||
|
includeGroupByRegex("com\\.gtnewhorizons\\..+")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
@@ -17,12 +17,7 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.diffplug.blowdryerSetup' version '1.6.0'
|
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.24'
|
||||||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' // Provides java toolchains
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blowdryerSetup {
|
|
||||||
repoSubfolder 'gtnhShared'
|
|
||||||
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.2.2')
|
|
||||||
//devLocal '.' // Use this when testing config updates locally
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.colen.postea.API;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import com.colen.postea.Utility.BlockConversionInfo;
|
|
||||||
|
|
||||||
public class BlockReplacementManager {
|
|
||||||
|
|
||||||
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,
|
|
||||||
BiFunction<BlockConversionInfo, World, BlockConversionInfo> transformer) {
|
|
||||||
blockReplacementMap.put(blockNameIn, transformer);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need this to save reprocessing blocks.
|
|
||||||
public static boolean blockNotConvertible(int blockID) {
|
|
||||||
return !posteaMarkedIDs.contains(blockID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.colen.postea.API;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
public class ItemStackReplacementManager {
|
|
||||||
|
|
||||||
private static final Map<String, Function<NBTTagCompound, NBTTagCompound>> replacementMap = new HashMap<>();
|
|
||||||
|
|
||||||
// Public API for converting ItemStacks.
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static void addItemReplacement(String itemName, Function<NBTTagCompound, NBTTagCompound> transformer) {
|
|
||||||
replacementMap.put(itemName, transformer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static Function<NBTTagCompound, NBTTagCompound> getItemReplacement(String itemNameInternal) {
|
|
||||||
return replacementMap.get(itemNameInternal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.colen.postea.API;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import com.colen.postea.Utility.BlockInfo;
|
|
||||||
|
|
||||||
public class TileEntityReplacementManager {
|
|
||||||
|
|
||||||
private static final HashMap<String, BiFunction<NBTTagCompound, World, BlockInfo>> tileEntityToNormalBlockTransformer = new HashMap<>();
|
|
||||||
|
|
||||||
public static void tileEntityTransformer(String tileEntityId,
|
|
||||||
BiFunction<NBTTagCompound, World, BlockInfo> transformerFunction) {
|
|
||||||
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
|
||||||
String tileEntityId) {
|
|
||||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
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")
|
|
||||||
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,19 +0,0 @@
|
|||||||
package com.colen.postea.Utility;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
public final class BlockConversionInfo {
|
|
||||||
|
|
||||||
public int x;
|
|
||||||
public int y;
|
|
||||||
public int z;
|
|
||||||
|
|
||||||
public int blockID;
|
|
||||||
public int metadata;
|
|
||||||
|
|
||||||
public World world;
|
|
||||||
public NBTTagCompound tileEntityNBT;
|
|
||||||
|
|
||||||
public String blockName;
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.colen.postea.Utility;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
public final class BlockInfo {
|
|
||||||
|
|
||||||
public final Block block;
|
|
||||||
public final int metadata;
|
|
||||||
public final Function<NBTTagCompound, NBTTagCompound> tileTransformer;
|
|
||||||
|
|
||||||
public BlockInfo(Block block, int metadata, Function<NBTTagCompound, NBTTagCompound> tileTransformer) {
|
|
||||||
this.block = block;
|
|
||||||
this.metadata = metadata;
|
|
||||||
this.tileTransformer = tileTransformer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockInfo(Block block, int metadata) {
|
|
||||||
this.block = block;
|
|
||||||
this.metadata = metadata;
|
|
||||||
this.tileTransformer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,230 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import com.colen.postea.API.BlockReplacementManager;
|
|
||||||
import com.colen.postea.API.TileEntityReplacementManager;
|
|
||||||
|
|
||||||
import akka.japi.Pair;
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
|
|
||||||
public class ChunkFixerUtility {
|
|
||||||
|
|
||||||
public static void processChunkNBT(NBTTagCompound compound, World world) {
|
|
||||||
NBTTagCompound levelCompoundTag = compound.getCompoundTag("Level");
|
|
||||||
|
|
||||||
if (processChunk(levelCompoundTag)) {
|
|
||||||
transformTileEntities(levelCompoundTag, world);
|
|
||||||
transformNormalBlocks(levelCompoundTag, world);
|
|
||||||
levelCompoundTag.setInteger("POSTEA", POSTEA_UPDATE_CODE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will not change between runs, unless a mod is updated or added.
|
|
||||||
public static final int POSTEA_UPDATE_CODE = getModListHash();
|
|
||||||
|
|
||||||
// If a chunk has the same postea code, then do not update it. Return false.
|
|
||||||
private static boolean processChunk(NBTTagCompound compound) {
|
|
||||||
// I'm minimising the string length here since this
|
|
||||||
// will be on every single chunk in every world... Rather not duplicate too much.
|
|
||||||
if (compound.hasKey("POSTEA")) {
|
|
||||||
return compound.getInteger("POSTEA") != POSTEA_UPDATE_CODE;
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16;
|
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16;
|
|
||||||
|
|
||||||
for (int i = 0; i < sections.tagCount(); i++) {
|
|
||||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
|
||||||
|
|
||||||
// Blocks16 and Data16 exist only because of NEID.
|
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
|
||||||
byte[] metadataArray = section.getByteArray("Data16");
|
|
||||||
|
|
||||||
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 = loadedBlocks.computeIfAbsent(
|
|
||||||
block,
|
|
||||||
b -> GameRegistry.findUniqueIdentifierFor(b)
|
|
||||||
.toString());
|
|
||||||
|
|
||||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
|
||||||
blockConversionInfo.blockName = blockName;
|
|
||||||
blockConversionInfo.blockID = blockId;
|
|
||||||
blockConversionInfo.metadata = (byte) metadata; // Updated
|
|
||||||
blockConversionInfo.world = world;
|
|
||||||
|
|
||||||
int x = index % 16;
|
|
||||||
int y = (index / 256) + (sectionY * 16);
|
|
||||||
int z = (index / 16) % 16;
|
|
||||||
|
|
||||||
blockConversionInfo.x = x + chunkXPos + 1;
|
|
||||||
blockConversionInfo.y = y;
|
|
||||||
blockConversionInfo.z = z + chunkZPos + 1;
|
|
||||||
|
|
||||||
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo, world);
|
|
||||||
|
|
||||||
if (output != null) {
|
|
||||||
int newBlockId = output.blockID;
|
|
||||||
int newMetadata = output.metadata;
|
|
||||||
|
|
||||||
blockArray[index * 2] = (byte) ((newBlockId >> 8) & 0xFF);
|
|
||||||
blockArray[index * 2 + 1] = (byte) (newBlockId & 0xFF);
|
|
||||||
|
|
||||||
metadataArray[index * 2] = (byte) ((newMetadata >> 8) & 0xFF);
|
|
||||||
metadataArray[index * 2 + 1] = (byte) (newMetadata & 0xFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void transformTileEntities(NBTTagCompound levelCompoundTag, World world) {
|
|
||||||
|
|
||||||
Pair<List<ConversionInfo>, NBTTagList> output = adjustTileEntities(
|
|
||||||
levelCompoundTag.getTagList("TileEntities", 10),
|
|
||||||
world);
|
|
||||||
List<ConversionInfo> conversionInfoList = output.first();
|
|
||||||
NBTTagList tileEntities = output.second();
|
|
||||||
|
|
||||||
if (tileEntities.tagCount() > 0) {
|
|
||||||
levelCompoundTag.setTag("TileEntities", tileEntities);
|
|
||||||
}
|
|
||||||
|
|
||||||
int chunkXPos = levelCompoundTag.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
|
||||||
int chunkZPos = levelCompoundTag.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
|
||||||
|
|
||||||
NBTTagList sections = levelCompoundTag.getTagList("Sections", 10);
|
|
||||||
for (int i = 0; i < sections.tagCount(); i++) {
|
|
||||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
|
||||||
processSection(section, conversionInfoList, chunkXPos, chunkZPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void processSection(NBTTagCompound section, List<ConversionInfo> conversionInfoList, int chunkXPos,
|
|
||||||
int chunkZPos) {
|
|
||||||
byte[] blockArray = section.getByteArray("Blocks16");
|
|
||||||
byte[] metadataArray = section.getByteArray("Data16"); // Updated to use Data16
|
|
||||||
byte y = section.getByte("Y");
|
|
||||||
|
|
||||||
List<ConversionInfo> filteredList = filterConversionInfosByY(conversionInfoList, y);
|
|
||||||
|
|
||||||
for (ConversionInfo info : filteredList) {
|
|
||||||
int[] localCoords = convertToChunkLocalCoordinates(info, y, chunkXPos, chunkZPos);
|
|
||||||
int index = computeBlockIndex(localCoords);
|
|
||||||
setBlockInfo(info.blockInfo.block, index, blockArray);
|
|
||||||
setMetadata(info.blockInfo.metadata, index, metadataArray); // This uses the updated setMetadata
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<ConversionInfo> filterConversionInfosByY(List<ConversionInfo> conversionInfoList, byte y) {
|
|
||||||
return conversionInfoList.stream()
|
|
||||||
.filter(info -> info.y >= y * 16 && info.y < (y + 1) * 16)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int[] convertToChunkLocalCoordinates(ConversionInfo info, byte y, int chunkXPos, int chunkZPos) {
|
|
||||||
int tileX = info.x - chunkXPos;
|
|
||||||
int tileY = info.y - y * 16;
|
|
||||||
int tileZ = info.z - chunkZPos;
|
|
||||||
return new int[] { tileX, tileY, tileZ };
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int computeBlockIndex(int[] localCoords) {
|
|
||||||
return localCoords[1] * 256 + localCoords[2] * 16 + localCoords[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setBlockInfo(Block block, int index, byte[] blockArray) {
|
|
||||||
int blockID = Block.getIdFromBlock(block);
|
|
||||||
blockArray[index * 2] = (byte) ((blockID >> 8) & 0xFF);
|
|
||||||
blockArray[index * 2 + 1] = (byte) (blockID & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setMetadata(int metadata, int index, byte[] metadataArray) {
|
|
||||||
// Since each metadata is now two bytes, multiply the index by 2 to get the correct position.
|
|
||||||
int metadataStartIndex = index * 2;
|
|
||||||
|
|
||||||
// Split the 16-bit metadata into two bytes and store them in the array.
|
|
||||||
metadataArray[metadataStartIndex] = (byte) ((metadata >> 8) & 0xFF); // Higher 8 bits
|
|
||||||
metadataArray[metadataStartIndex + 1] = (byte) (metadata & 0xFF); // Lower 8 bits
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Pair<List<ConversionInfo>, NBTTagList> adjustTileEntities(NBTTagList tileEntities, World world) {
|
|
||||||
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
|
||||||
|
|
||||||
NBTTagList tileEntitiesCopy = new NBTTagList();
|
|
||||||
|
|
||||||
for (int i = 0; i < tileEntities.tagCount(); i++) {
|
|
||||||
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
|
|
||||||
String tileEntityId = tileEntity.getString("id");
|
|
||||||
|
|
||||||
// Check if we have a transformer registered for this tile entity ID
|
|
||||||
BiFunction<NBTTagCompound, World, 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);
|
|
||||||
|
|
||||||
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 {
|
|
||||||
tileEntitiesCopy.appendTag(tileEntity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Pair<>(conversionInfo, tileEntitiesCopy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ConversionInfo {
|
|
||||||
|
|
||||||
public final int x;
|
|
||||||
public final int y;
|
|
||||||
public final int z;
|
|
||||||
public final BlockInfo blockInfo;
|
|
||||||
|
|
||||||
public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.blockInfo = blockInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.colen.postea.Utility;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
import com.colen.postea.API.ItemStackReplacementManager;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
|
||||||
|
|
||||||
public abstract class ItemFixerUtility {
|
|
||||||
|
|
||||||
public static void fixItemStack(NBTTagCompound tag) {
|
|
||||||
|
|
||||||
if (tag.hasNoTags()) return;
|
|
||||||
|
|
||||||
if (tag.hasKey("id")) {
|
|
||||||
short id = tag.getShort("id");
|
|
||||||
Item item = Item.getItemById(id);
|
|
||||||
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
|
|
||||||
+ GameRegistry.findUniqueIdentifierFor(item).name;
|
|
||||||
|
|
||||||
Function<NBTTagCompound, NBTTagCompound> transformer = ItemStackReplacementManager
|
|
||||||
.getItemReplacement(itemNameInternal);
|
|
||||||
|
|
||||||
if (transformer != null) {
|
|
||||||
transformer.apply(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.colen.postea.mixins.early;
|
|
||||||
|
|
||||||
import static com.colen.postea.Utility.ChunkFixerUtility.POSTEA_UPDATE_CODE;
|
|
||||||
import static com.colen.postea.Utility.ChunkFixerUtility.processChunkNBT;
|
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
|
||||||
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
|
||||||
|
|
||||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import com.colen.postea.mixins.interfaces.IChunkMixin;
|
|
||||||
|
|
||||||
@Mixin(AnvilChunkLoader.class)
|
|
||||||
public abstract class MixinAnvilChunkLoader {
|
|
||||||
|
|
||||||
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("HEAD"), remap = false)
|
|
||||||
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
|
|
||||||
CallbackInfoReturnable<Object[]> cir) {
|
|
||||||
processChunkNBT(compound, world);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "readChunkFromNBT", at = @At("RETURN"))
|
|
||||||
private Chunk onReadChunkFromNBT(World world, NBTTagCompound nbtTagCompound, CallbackInfoReturnable<Chunk> cir) {
|
|
||||||
Chunk chunk = cir.getReturnValue();
|
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
|
||||||
if (nbtTagCompound.hasKey("POSTEA")) {
|
|
||||||
long posteaCode = nbtTagCompound.getLong("POSTEA");
|
|
||||||
iChunkMixin.Postea$setPosteaCode(posteaCode);
|
|
||||||
|
|
||||||
// Chunk has been updated with Postea, so we will mark it to save later.
|
|
||||||
if (posteaCode != POSTEA_UPDATE_CODE) chunk.setChunkModified();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunk;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(method = "writeChunkToNBT", at = @At("HEAD"))
|
|
||||||
private void onWriteChunkToNBT(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
|
||||||
if (chunk instanceof IChunkMixin iChunkMixin) {
|
|
||||||
nbtTagCompound.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.colen.postea.mixins.early;
|
|
||||||
|
|
||||||
import net.minecraft.world.chunk.Chunk;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Unique;
|
|
||||||
|
|
||||||
import com.colen.postea.mixins.interfaces.IChunkMixin;
|
|
||||||
|
|
||||||
@Mixin(Chunk.class)
|
|
||||||
public class MixinChunk implements IChunkMixin {
|
|
||||||
|
|
||||||
// This new field will store the hash of mod name + versions. We use this to check
|
|
||||||
// if we need to reprocess this chunk.
|
|
||||||
@Unique
|
|
||||||
private long postea_GTNH$posteaID;
|
|
||||||
|
|
||||||
@Unique
|
|
||||||
public long Postea$getPosteaCode() {
|
|
||||||
return postea_GTNH$posteaID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Unique
|
|
||||||
public void Postea$setPosteaCode(long POSTEA_ID) {
|
|
||||||
this.postea_GTNH$posteaID = POSTEA_ID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.colen.postea.mixins.interfaces;
|
|
||||||
|
|
||||||
public interface IChunkMixin {
|
|
||||||
|
|
||||||
long Postea$getPosteaCode();
|
|
||||||
|
|
||||||
void Postea$setPosteaCode(long posteaID);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,398 @@
|
|||||||
|
package com.gtnewhorizons.postea;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.BlockAccessCompat;
|
||||||
|
import com.gtnewhorizons.postea.api.BlockReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.api.ChunkTransformContext;
|
||||||
|
import com.gtnewhorizons.postea.api.IDExtenderCompat;
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
import com.gtnewhorizons.postea.api.ItemStackReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.api.PlayerDataTransformContext;
|
||||||
|
import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.api.VersionedReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||||
|
import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
|
abstract class ExampleMigrators {
|
||||||
|
|
||||||
|
static void postLoad() {
|
||||||
|
TEToBlockExample.postLoad();
|
||||||
|
TEModifyExample.postLoad();
|
||||||
|
TEFullReplacementExample.postLoad();
|
||||||
|
SimpleTransformationExample.postLoad();
|
||||||
|
ComplexBlockTransformer.postLoad();
|
||||||
|
ComplexItemTransformer.postLoad();
|
||||||
|
FMLReMappingExample.postLoad();
|
||||||
|
VersionedExample.postLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class TEToBlockExample {
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// it's with great shame that we do admit that gregtech ores used to be tile entities.
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world, chunk) -> {
|
||||||
|
if (world.provider.dimensionId == -1) {
|
||||||
|
// nether gets orange wool
|
||||||
|
return new BlockInfo(Blocks.wool, 1);
|
||||||
|
}
|
||||||
|
if (world.provider.dimensionId == 1) {
|
||||||
|
// the end gets magenta wool
|
||||||
|
return new BlockInfo(Blocks.wool, 2);
|
||||||
|
}
|
||||||
|
// all other dimensions get light blue wool
|
||||||
|
return new BlockInfo(Blocks.wool, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class TEModifyExample {
|
||||||
|
|
||||||
|
private static int reedsId = -1;
|
||||||
|
private static int diamondId = -1;
|
||||||
|
private static int stoneId = -1;
|
||||||
|
private static int record11Id = -1;
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// pre caching ids like this will lead to faster transformers
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:reeds", i -> reedsId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:diamond", i -> diamondId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:stone", i -> stoneId = i);
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world, chunk) -> {
|
||||||
|
// This transformer replaces all sugar cane stacks inside a chest with
|
||||||
|
// stone, unless it's in the 13th slot at which point it's replaced with
|
||||||
|
// diamonds. All transformations are done without affecting the stack size.
|
||||||
|
NBTTagList slots = tag.getTagList("Items", 10);
|
||||||
|
for (int i = 0; i < slots.tagCount(); i++) {
|
||||||
|
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||||
|
// only target the removed item
|
||||||
|
if (IDExtenderCompat.getItemStackID(slot) != reedsId) continue;
|
||||||
|
if (slot.getByte("Slot") == 13) {
|
||||||
|
// replace it with diamonds if it's in slot 13
|
||||||
|
IDExtenderCompat.setItemStackID(slot, diamondId);
|
||||||
|
} else {
|
||||||
|
// else replace it with stone.
|
||||||
|
IDExtenderCompat.setItemStackID(slot, stoneId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// this tile entity transformer also executes because the other transformer returned null
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:record_11", i -> record11Id = i);
|
||||||
|
byte targetSLot = (byte) 12;
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("Chest", (tag, world, chunk) -> {
|
||||||
|
// This transformer looks for the 12th slot of the chest and replaces
|
||||||
|
// or sets it's content to a new stack of record 11 with a stack size of 1.
|
||||||
|
NBTTagList slots = tag.getTagList("Items", 10);
|
||||||
|
NBTTagCompound toEdit = null;
|
||||||
|
for (int i = 0; i < slots.tagCount(); i++) {
|
||||||
|
NBTTagCompound slot = slots.getCompoundTagAt(i);
|
||||||
|
if (slot.getByte("Slot") != targetSLot) continue;
|
||||||
|
toEdit = slot;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (toEdit == null) {
|
||||||
|
toEdit = new NBTTagCompound();
|
||||||
|
toEdit.setByte("Slot", targetSLot);
|
||||||
|
slots.appendTag(toEdit);
|
||||||
|
}
|
||||||
|
toEdit.setByte("Count", (byte) 1);
|
||||||
|
toEdit.setShort("Damage", (short) 0);
|
||||||
|
IDExtenderCompat.setItemStackID(toEdit, record11Id);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class TEFullReplacementExample {
|
||||||
|
|
||||||
|
public static int litFurnaceId = -1;
|
||||||
|
public static int unlitFurnaceId = -1;
|
||||||
|
public static int fireChargeId = -1;
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
BlockReplacementManager.registerIDResolver("minecraft:lit_furnace", i -> litFurnaceId = i);
|
||||||
|
BlockReplacementManager.registerIDResolver("minecraft:furnace", i -> unlitFurnaceId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:fire_charge", i -> fireChargeId = i);
|
||||||
|
TileEntityReplacementManager.tileEntityTransformer("Furnace", TEFullReplacementExample::transformFurnace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This transformer transforms a furnace into a chest, and adds a fire charge in the 4th slot of the chest if
|
||||||
|
* the block where the tile entity once stood was a lit furnace. If it's not either a lit or unlit furnace,
|
||||||
|
* the block is simply transformed into air.
|
||||||
|
*
|
||||||
|
* @param tag The NBT data of the tile entity being transformed.
|
||||||
|
* @param world The world in which the tile entity is located.
|
||||||
|
* @param chunk The chunk in which the tile entity is located.
|
||||||
|
* @return Null if we didn't update the block, else a BlockInfo with the transformation data you wish to
|
||||||
|
* execute.
|
||||||
|
*/
|
||||||
|
private static BlockInfo transformFurnace(NBTTagCompound tag, World world, Chunk chunk) {
|
||||||
|
int[] blockIdAndMeta = BlockAccessCompat.getBlockIDAndMetaAtTE(tag, chunk);
|
||||||
|
int blockId = blockIdAndMeta[0];
|
||||||
|
int meta = blockIdAndMeta[1];
|
||||||
|
// we return a value this time because we are actually replacing the block and tile entity.
|
||||||
|
// we copy the meta value since that preserves the orientation for these blocks.
|
||||||
|
return new BlockInfo(Blocks.chest, meta, oldTag -> transformFurnaceNBT(oldTag, blockId));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the content of the furnace to the chest and adds a fire charge in the 4th slot if the furnace was lit.
|
||||||
|
*
|
||||||
|
* @param oldTag The current NBT data ofthe tile entity being transformed.
|
||||||
|
* @return null if we want the tile entity to be erased.
|
||||||
|
*/
|
||||||
|
private static NBTTagCompound transformFurnaceNBT(NBTTagCompound oldTag, int blockId) {
|
||||||
|
// if the block wasn't a furnace, clear the current tile entity and let the chest spawn a new one.
|
||||||
|
if (blockId != litFurnaceId && blockId != unlitFurnaceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// use this function to create a new tile entity tag with the same positional data as the old one.
|
||||||
|
NBTTagCompound newTag = TileEntityReplacementManager.createTETagAtSamePosition("Chest", oldTag);
|
||||||
|
NBTTagList newSlots = (NBTTagList) oldTag.getTagList("Items", 10)
|
||||||
|
.copy();
|
||||||
|
// if the block used to be a lit furnace add a fire charge in the 4th slot.
|
||||||
|
if (blockId == litFurnaceId) {
|
||||||
|
NBTTagCompound fireChargeStack = new NBTTagCompound();
|
||||||
|
IDExtenderCompat.setItemStackID(fireChargeStack, fireChargeId);
|
||||||
|
fireChargeStack.setByte("Slot", (byte) 4);
|
||||||
|
fireChargeStack.setByte("Count", (byte) 1);
|
||||||
|
fireChargeStack.setShort("Damage", (short) 0);
|
||||||
|
newSlots.appendTag(fireChargeStack);
|
||||||
|
}
|
||||||
|
newTag.setTag("Items", newSlots);
|
||||||
|
return newTag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class SimpleTransformationExample {
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// item/block -> item/block, preserving the Meta/Damage value.
|
||||||
|
//
|
||||||
|
// remap all block and items of colored stone blocks with wool of the same color
|
||||||
|
BlockReplacementManager.addSimpleReplacement("ExtraUtilities:colorStoneBrick", Blocks.wool);
|
||||||
|
|
||||||
|
// Item/Block with meta -> Item/Block, meta preserved
|
||||||
|
//
|
||||||
|
// angel ring:3 to disk 11
|
||||||
|
ItemStackReplacementManager
|
||||||
|
.addSimpleReplacement("ExtraUtilities:angelRing", 3, new ItemStack(Items.record_11));
|
||||||
|
ItemStackReplacementManager
|
||||||
|
.addSimpleReplacement("ExtraUtilities:angelRing", 4, new ItemStack(Items.record_13));
|
||||||
|
|
||||||
|
// Item/Block with meta -> Item/Block with specific meta
|
||||||
|
//
|
||||||
|
// remap all compressed cobble to oak planks
|
||||||
|
//
|
||||||
|
// When using a stack as a target the passed stack size is ignored, only the contained item and meta value
|
||||||
|
// are kept.
|
||||||
|
ItemStackReplacementManager
|
||||||
|
.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", 0, new ItemStack(Blocks.planks, 0, 0));
|
||||||
|
|
||||||
|
// block only with meta -> block with specific meta value.
|
||||||
|
//
|
||||||
|
// remap blocks of double compressed cobble to cobble.
|
||||||
|
BlockReplacementManager
|
||||||
|
.addSimpleReplacement("ExtraUtilities:cobblestone_compressed", 1, Blocks.cobblestone, 0, true);
|
||||||
|
// item only with damage -> item only with specific damage value.
|
||||||
|
//
|
||||||
|
// remap stacks of double compressed cobble to oak saplings.
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement(
|
||||||
|
"ExtraUtilities:cobblestone_compressed",
|
||||||
|
1,
|
||||||
|
new ItemStack(Blocks.sapling, 1, 0),
|
||||||
|
true);
|
||||||
|
|
||||||
|
// Block/Item with any Meta/Damage -> Block/Item with specific Meta/Damage value.
|
||||||
|
//
|
||||||
|
// Using OreDictionary.WILDCARD_VALUE will tell postea to use this mapping as a fallback when there is no
|
||||||
|
// transformer targeting the specific meta/damage value of the block/item.
|
||||||
|
//
|
||||||
|
// remap all other instances of compressed blocks to endstone
|
||||||
|
BlockReplacementManager.addSimpleReplacement(
|
||||||
|
"ExtraUtilities:cobblestone_compressed",
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
Blocks.end_stone,
|
||||||
|
0);
|
||||||
|
|
||||||
|
// Block/Item with any Meta/Damage -> Block/Item, preserving the Meta/Damage value.
|
||||||
|
//
|
||||||
|
// When passing OreDictionary.WILDCARD_VALUE as the target Meta/Damage value, Postea will preserve any
|
||||||
|
// existing
|
||||||
|
// Meta/Damage value. This is also the default value when you don't specify a target meta value.
|
||||||
|
//
|
||||||
|
// remap all other instances of compressed blocks to endstone
|
||||||
|
BlockReplacementManager.addSimpleReplacement(
|
||||||
|
"ExtraUtilities:cobblestone_compressed",
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
Blocks.end_stone,
|
||||||
|
OreDictionary.WILDCARD_VALUE);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class ComplexBlockTransformer {
|
||||||
|
|
||||||
|
private static int woolId = -1;
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// This transformer replaces all grass blocks with even x-coordinates with orange wool.
|
||||||
|
BlockReplacementManager.registerIDResolver("minecraft:wool", i -> woolId = i);
|
||||||
|
BlockReplacementManager
|
||||||
|
.addTransformationHandler("minecraft:grass", ComplexBlockTransformer::transformGrass);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean transformGrass(BlockConversionInfo info) {
|
||||||
|
// only affect blocks that are on even x coordinates
|
||||||
|
if (info.x % 2 != 0) return false;
|
||||||
|
// transform all these blocks into orange wool.
|
||||||
|
info.blockID = woolId;
|
||||||
|
info.metadata = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class ComplexItemTransformer {
|
||||||
|
|
||||||
|
private static int writableBookId = -1;
|
||||||
|
private static int woolId = -1;
|
||||||
|
|
||||||
|
private static void postLoad() {
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:writable_book", i -> writableBookId = i);
|
||||||
|
ItemStackReplacementManager.registerIDResolver("minecraft:wool", i -> woolId = i);
|
||||||
|
ItemStackReplacementManager
|
||||||
|
.addTransformationHandler("minecraft:written_book", ComplexItemTransformer::unsignBook);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This transformer transforms a written book into either an unsigned book or orange wool depending on it's
|
||||||
|
* title.
|
||||||
|
*
|
||||||
|
* @param name The name of the item being transformed, even if that item doesn't exist anymore.
|
||||||
|
* @param nbt The NBT data of the stack item being transformed.
|
||||||
|
* @return True if we've actually transformed the item.
|
||||||
|
*/
|
||||||
|
private static boolean unsignBook(String name, NBTTagCompound nbt) {
|
||||||
|
// check if the book has a title.
|
||||||
|
if (!nbt.hasKey("tag", 10)) return false;
|
||||||
|
NBTTagCompound tag = nbt.getCompoundTag("tag");
|
||||||
|
if (!tag.hasKey("title", 8)) return false;
|
||||||
|
String title = tag.getString("title");
|
||||||
|
if (title.equalsIgnoreCase("unsign me")) {
|
||||||
|
// unsign the book
|
||||||
|
IDExtenderCompat.setItemStackID(nbt, writableBookId);
|
||||||
|
nbt.setShort("Damage", (short) 0);
|
||||||
|
nbt.setByte("Count", (byte) 1);
|
||||||
|
// clear the signed book nbt
|
||||||
|
tag.removeTag("title");
|
||||||
|
tag.removeTag("author");
|
||||||
|
return true;
|
||||||
|
} else if (title.equalsIgnoreCase("orange wool")) {
|
||||||
|
// Transform it into orange wool.
|
||||||
|
IDExtenderCompat.setItemStackID(nbt, woolId);
|
||||||
|
nbt.setShort("Damage", (short) 1);
|
||||||
|
nbt.setByte("Count", (byte) 1);
|
||||||
|
// removes the NBT tag from the stack.
|
||||||
|
nbt.removeTag("tag");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class FMLReMappingExample {
|
||||||
|
|
||||||
|
// You have to make your own block class since the block constructor is protected.
|
||||||
|
public static class MyBlock extends Block {
|
||||||
|
|
||||||
|
protected MyBlock() {
|
||||||
|
super(Material.ground);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// this only works when the thing you're replacing with has never been registered to a world's
|
||||||
|
// id map. If you try to run this with a block that already exists (eg good old dirt), FML error out and
|
||||||
|
// you that your world is corrupted beyond repair, and advise you to undo what ever you just did.
|
||||||
|
//
|
||||||
|
// Postea Simple Transformers don't have that issue and are more lag friendly in the long term. Consider
|
||||||
|
// using them when ever possible, instead of FML mappings.
|
||||||
|
Item item = new Item();
|
||||||
|
GameRegistry.registerItem(item, "my_item");
|
||||||
|
ItemStackReplacementManager.replaceMissingMapping("IC2:itemFertilizer", item);
|
||||||
|
|
||||||
|
Block block = new MyBlock();
|
||||||
|
GameRegistry.registerBlock(block, "my_block");
|
||||||
|
BlockReplacementManager.replaceMissingMapping("IC2:blockCrop", block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static abstract class FMLIgnoreMissingMappingExample {
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
// It doesn't really matter which one you use, they both do the same thing under the hood.
|
||||||
|
ItemStackReplacementManager.ignoreMissingMapping("IC2:itemFertilizer");
|
||||||
|
BlockReplacementManager.ignoreMissingMapping("IC2:blockCrop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class VersionedExample implements IVersionedTransformer {
|
||||||
|
|
||||||
|
public static void postLoad() {
|
||||||
|
VersionedReplacementManager.register(new VersionedExample());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return "examplemod:gemIndex";
|
||||||
|
}
|
||||||
|
|
||||||
|
// The version the running mod writes gems under; bump it whenever the index assignment changes.
|
||||||
|
@Override
|
||||||
|
public int currentVersion() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transformChunk(ChunkTransformContext ctx) {
|
||||||
|
// Data saved before this transformer existed carries no stamp.
|
||||||
|
if (ctx.storedVersion() == ChunkTransformContext.UNSTAMPED || ctx.storedVersion() == 1) {
|
||||||
|
int gemBlockId = Block.getIdFromBlock(Blocks.wool);
|
||||||
|
ctx.forEachBlock((x, y, z, id, meta) -> { if (id == gemBlockId) ctx.setBlock(x, y, z, id, meta + 1); });
|
||||||
|
ctx.forEachItemStackTag(stack -> {
|
||||||
|
if (IDExtenderCompat.getItemStackID(stack) == Item.getIdFromItem(Items.dye)) {
|
||||||
|
stack.setShort("Damage", (short) (stack.getShort("Damage") + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void transformPlayer(PlayerDataTransformContext ctx) {
|
||||||
|
if (ctx.storedVersion() == PlayerDataTransformContext.UNSTAMPED || ctx.storedVersion() == 1) {
|
||||||
|
ctx.forEachItemStackTag(stack -> {
|
||||||
|
if (IDExtenderCompat.getItemStackID(stack) == Item.getIdFromItem(Items.dye)) {
|
||||||
|
stack.setShort("Damage", (short) (stack.getShort("Damage") + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package com.gtnewhorizons.postea;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.world.ChunkEvent;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||||
|
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.MissingMappingHandler;
|
||||||
|
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.TransformerRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionedTransformerLog;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import cpw.mods.fml.common.Mod;
|
||||||
|
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLModIdMappingEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||||
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
|
@Mod(
|
||||||
|
modid = Postea.MODID,
|
||||||
|
version = Tags.VERSION,
|
||||||
|
name = Postea.MODNAME,
|
||||||
|
acceptedMinecraftVersions = "[1.7.10]",
|
||||||
|
dependencies = " required-after:gtnhlib@[0.6.21,);")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class Postea {
|
||||||
|
|
||||||
|
public static final String MODID = "postea";
|
||||||
|
public static final String MODNAME = "Postea";
|
||||||
|
|
||||||
|
public static final Logger LOG = LogManager.getLogger(MODNAME);
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void postsLoad(FMLPostInitializationEvent event) {
|
||||||
|
// TestUIEMigrator.postLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void chunkLoaded(ChunkEvent.Load event) {
|
||||||
|
ChunkFixerUtility.onChunkLoaded(event.getChunk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
|
||||||
|
IDRegistry.beginWorld(
|
||||||
|
new File(
|
||||||
|
FMLCommonHandler.instance()
|
||||||
|
.getSavesDirectory(),
|
||||||
|
event.getServer()
|
||||||
|
.getFolderName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void serverStopped(FMLServerStoppedEvent event) {
|
||||||
|
IDRegistry.endWorld();
|
||||||
|
VersionedTransformerLog.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onIdMappingsChanged(FMLModIdMappingEvent event) {
|
||||||
|
SimpleTransformationRegistry.onIdMappingsChanged();
|
||||||
|
TransformerRegistry.onIdMappingsChanged();
|
||||||
|
IDRegistry.onMappingUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onMissingMapping(FMLMissingMappingsEvent event) {
|
||||||
|
MissingMappingHandler.onMissingMapping(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onLoadCompleted(FMLLoadCompleteEvent event) {
|
||||||
|
SimpleTransformationRegistry.onLoadCompleted();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.compat.Compat;
|
||||||
|
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API for accessing information related to a block located at the location of a tile entity inside a
|
||||||
|
* tile entity transformer registered via
|
||||||
|
* {@link TileEntityReplacementManager#tileEntityTransformer(String, TriFunction)}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public abstract class BlockAccessCompat {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the id of the block that is (or used to be) at the position of the TE stored in the given tag.
|
||||||
|
*
|
||||||
|
* @apiNote This method is intended for use withing TileEntityTransformers declared via
|
||||||
|
* {@link TileEntityReplacementManager#tileEntityTransformer(String, TriFunction)}
|
||||||
|
*
|
||||||
|
* @param tag The tag for the tile entity
|
||||||
|
* @param chunk The chunk containing the tile entity
|
||||||
|
* @return The id of the block that exists (or used to exist) at that location.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static int getBlockIDAtTE(NBTTagCompound tag, Chunk chunk) {
|
||||||
|
// fetch the block accessor
|
||||||
|
ExtendedBlockStorage[] ebsArray = chunk.getBlockStorageArray();
|
||||||
|
// abort if y is oob
|
||||||
|
int y = tag.getInteger("y");
|
||||||
|
if (y >> 4 >= ebsArray.length) return 0;
|
||||||
|
SubChunkAccess access = Compat.getSubChunkAccess(ebsArray[y >> 4]);
|
||||||
|
|
||||||
|
// identify the block
|
||||||
|
int x = tag.getInteger("x") & 0xf;
|
||||||
|
y &= 0xf;
|
||||||
|
int z = tag.getInteger("z") & 0xf;
|
||||||
|
return access.getBlockId(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the meta of the block that is (or used to be) at the position of the TE stored in the given tag.
|
||||||
|
*
|
||||||
|
* @apiNote This method is intended for use withing TileEntityTransformers declared via
|
||||||
|
* {@link TileEntityReplacementManager#tileEntityTransformer(String, TriFunction)}
|
||||||
|
*
|
||||||
|
* @param tag The tag for the tile entity
|
||||||
|
* @param chunk The chunk containing the tile entity
|
||||||
|
* @return The id of the block that exists (or used to exist) at that location.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static int getBlockMetaAtTE(NBTTagCompound tag, Chunk chunk) {
|
||||||
|
// fetch the block accessor
|
||||||
|
ExtendedBlockStorage[] ebsArray = chunk.getBlockStorageArray();
|
||||||
|
// abort if y is oob
|
||||||
|
int y = tag.getInteger("y");
|
||||||
|
if (y >> 4 >= ebsArray.length) return 0;
|
||||||
|
SubChunkAccess access = Compat.getSubChunkAccess(ebsArray[y >> 4]);
|
||||||
|
|
||||||
|
// identify the block
|
||||||
|
int x = tag.getInteger("x") & 0xf;
|
||||||
|
y &= 0xf;
|
||||||
|
int z = tag.getInteger("z") & 0xf;
|
||||||
|
return access.getMeta(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the id and meta of the block that is (or used to be) at the position of the TE stored in the given tag.
|
||||||
|
*
|
||||||
|
* @apiNote This method is intended for use withing TileEntityTransformers declared via
|
||||||
|
* {@link TileEntityReplacementManager#tileEntityTransformer(String, TriFunction)}
|
||||||
|
*
|
||||||
|
* @param tag The tag for the tile entity
|
||||||
|
* @param chunk The chunk containing the tile entity
|
||||||
|
* @return An array with th eid of the block that exists (or used to exist) at that location.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static int[] getBlockIDAndMetaAtTE(NBTTagCompound tag, Chunk chunk) {
|
||||||
|
// fetch the block accessor
|
||||||
|
ExtendedBlockStorage[] ebsArray = chunk.getBlockStorageArray();
|
||||||
|
// abort if y is oob
|
||||||
|
int y = tag.getInteger("y");
|
||||||
|
if (y >> 4 >= ebsArray.length) return new int[] { 0, 0 };
|
||||||
|
SubChunkAccess access = Compat.getSubChunkAccess(ebsArray[y >> 4]);
|
||||||
|
|
||||||
|
// identify the block
|
||||||
|
int x = tag.getInteger("x") & 0xf;
|
||||||
|
y &= 0xf;
|
||||||
|
int z = tag.getInteger("z") & 0xf;
|
||||||
|
return new int[] { access.getBlockId(x, y, z), access.getMeta(x, y, z) };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A block referenced by its namespaced id, together with a meta value. Returned by
|
||||||
|
* {@link BlockReplacementManager#transformBlock(String, int)}.
|
||||||
|
*/
|
||||||
|
public final class BlockNameAndMeta {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The namespaced id of the block.
|
||||||
|
*/
|
||||||
|
public final String name;
|
||||||
|
/**
|
||||||
|
* The meta value of the block.
|
||||||
|
*/
|
||||||
|
public final int metadata;
|
||||||
|
|
||||||
|
public BlockNameAndMeta(String name, int metadata) {
|
||||||
|
this.name = name;
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.MissingMappingHandler;
|
||||||
|
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.TransformerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API used to register block transformers via postea's handler system.<br>
|
||||||
|
* <br>
|
||||||
|
* Block transformers are executed after Tile Entity transformers, when chunks being loading into the world.
|
||||||
|
*/
|
||||||
|
public abstract class BlockReplacementManager {
|
||||||
|
|
||||||
|
// region custom transformer registration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom transformer for a given id.
|
||||||
|
*
|
||||||
|
* @apiNote When the transformer function passed to this function returns a null, value Postea will assume that
|
||||||
|
* the transformer has failed to identify and run the handler on any other handler function registered
|
||||||
|
* to the given ID.
|
||||||
|
* <br>
|
||||||
|
* If you need to perform a simple transformations consider using the following methods instead:
|
||||||
|
* <ul>
|
||||||
|
* <li>block -> block (with same meta): {@link #addSimpleReplacement(String, Block)}</li>
|
||||||
|
* <li>block -> block with specific meta: {@link #addSimpleReplacement(String, Block, int)}</li>
|
||||||
|
* <li>block with meta -> block (with same meta): {@link #addSimpleReplacement(String, int, Block)}</li>
|
||||||
|
* <li>block with meta -> block with specific meta:
|
||||||
|
* {@link #addSimpleReplacement(String, int, Block, int)}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @implNote For performance reasons, Postea assumes that the BlockConversionInfo that was passed to the handler
|
||||||
|
* hasn't been modified if your handler return false. This isn't enforced though since returning false
|
||||||
|
* after doing some modifications has a couple niche uses. eg: having separate handlers for different
|
||||||
|
* migrations of a single thing that can be sunset at different times down the line.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to transform.
|
||||||
|
* @param transformer The transformer to apply.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addTransformationHandler(String originalId, IBlockTransformationHandler transformer) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (transformer == null) throw new IllegalArgumentException("transformer is null");
|
||||||
|
TransformerRegistry.addBlockTransformer(originalId, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion custom transformer registration
|
||||||
|
|
||||||
|
// region lookup
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the block transformers registered for the given id on a block that isn't placed in the world, and returns
|
||||||
|
* what it would be transformed into.<br>
|
||||||
|
* <br>
|
||||||
|
* This is meant for mods that store blocks by their namespaced id inside their own NBT (e.g.: blocks that are
|
||||||
|
* made out of other blocks), which Postea can't reach while converting chunks. Calling this when such a block is
|
||||||
|
* loaded applies every migration registered to Postea to it.
|
||||||
|
*
|
||||||
|
* @apiNote Only call this while a world is loaded, transformers rely on the numeric ids resolved for that world.
|
||||||
|
* The transformers are given a {@link com.gtnewhorizons.postea.utility.BlockConversionInfo} without a
|
||||||
|
* world, and with all coordinates set to 0. Tile entity transformers are not run.
|
||||||
|
*
|
||||||
|
* @param name The namespaced id of the block.
|
||||||
|
* @param metadata The meta value of the block.
|
||||||
|
* @return The namespaced id and meta value of the block to use instead, or null if no transformer applies.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static @Nullable BlockNameAndMeta transformBlock(@Nonnull String name, int metadata) {
|
||||||
|
if (name == null) throw new NullPointerException("name cannot be null");
|
||||||
|
return TransformerRegistry.transformBlock(name, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion lookup
|
||||||
|
|
||||||
|
// region id resolving
|
||||||
|
|
||||||
|
// spotless:off
|
||||||
|
/**
|
||||||
|
* Registers a callback function that will be provided the numeric ID of the given namespaced ID when a world is
|
||||||
|
* first loaded. Since forge doesn't remap missing block IDs to 0 when loading a world for performance reasons,
|
||||||
|
* instead opting to treat any block ID as Air, you can store that value into a static field, and use it to
|
||||||
|
* compare against an id provided to you during the execution of a transformation handler.<br>
|
||||||
|
* <br>
|
||||||
|
* This function is mostly intended to be used in partnership with tile entity transformers, and is intended to
|
||||||
|
* overcome the need to create dummy blocks and items in order to identify blocks inside a custom transformer.<br>
|
||||||
|
* <br>
|
||||||
|
* For compatibility reasons, it's better not to register dummies to take the place of dummy items. If one mod was
|
||||||
|
* to only convert blocks with a specific meta while another handled the rest, the other mod would either need
|
||||||
|
* additional work to detect your own dummy blocks or even worst, fail to identify the original blocks as it's not
|
||||||
|
* aware of your dummy blocks.
|
||||||
|
*
|
||||||
|
* @apiNote Here is an example implementation:
|
||||||
|
* <pre>{@code
|
||||||
|
* import net.minecraft.block.Block;
|
||||||
|
* import net.minecraft.block.material.Material;
|
||||||
|
* import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
* import net.minecraft.world.World;
|
||||||
|
* import net.minecraft.world.chunk.Chunk;
|
||||||
|
*
|
||||||
|
* import com.gtnewhorizons.postea.api.BlockAccessCompat;
|
||||||
|
* import com.gtnewhorizons.postea.api.BlockReplacementManager;
|
||||||
|
* import com.gtnewhorizons.postea.api.TileEntityReplacementManager;
|
||||||
|
* import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||||
|
* import com.gtnewhorizons.postea.utility.PosteaUtilities;
|
||||||
|
*
|
||||||
|
* import cpw.mods.fml.common.Mod;
|
||||||
|
* import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
|
* import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
* import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
*
|
||||||
|
* @Mod(
|
||||||
|
* modid = "mymod",
|
||||||
|
* version = "1.0.0",
|
||||||
|
* name = "Example Mod",
|
||||||
|
* acceptedMinecraftVersions = "[1.7.10]",
|
||||||
|
* dependencies = " after:otherMod;")
|
||||||
|
* @SuppressWarnings("unused")
|
||||||
|
* public class ExampleMod {
|
||||||
|
*
|
||||||
|
* private static int targetBlock1 = -1;
|
||||||
|
* private static int targetBlock2 = -1;
|
||||||
|
* private static int targetBlock3 = -1;
|
||||||
|
*
|
||||||
|
* private static class MyBlocks {
|
||||||
|
* public static Block block1;
|
||||||
|
* public static Block block2;
|
||||||
|
* public static Block block3;
|
||||||
|
* public static Block block4;
|
||||||
|
* public static Block block5;
|
||||||
|
* public static Block block6;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* private static class TestBlock extends Block {
|
||||||
|
* public TestBlock(String id) {
|
||||||
|
* super(Material.ground);
|
||||||
|
* GameRegistry.registerBlock(this, id);
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Mod.EventHandler
|
||||||
|
* @SuppressWarnings("unused")
|
||||||
|
* public static void preInit(FMLPreInitializationEvent event) {
|
||||||
|
* MyBlocks.block1 = new TestBlock("block1");
|
||||||
|
* MyBlocks.block2 = new TestBlock("block2");
|
||||||
|
* MyBlocks.block3 = new TestBlock("block3");
|
||||||
|
* MyBlocks.block4 = new TestBlock("block4");
|
||||||
|
* MyBlocks.block5 = new TestBlock("block5");
|
||||||
|
* MyBlocks.block6 = new TestBlock("block6");
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Mod.EventHandler
|
||||||
|
* @SuppressWarnings("unused")
|
||||||
|
* public static void postLoad(FMLPostInitializationEvent event) {
|
||||||
|
* BlockReplacementManager.registerIDResolver("otherMod:block1", i -> targetBlock1 = i);
|
||||||
|
* BlockReplacementManager.registerIDResolver("otherMod:block2", i -> targetBlock2 = i);
|
||||||
|
* BlockReplacementManager.registerIDResolver("otherMod:block3", i -> targetBlock3 = i);
|
||||||
|
* TileEntityReplacementManager.tileEntityTransformer("otherModTE", ExampleMod::transform);
|
||||||
|
* // If you were to have all of these in one mod,
|
||||||
|
* // the general recommendation would be to merge the handlers,
|
||||||
|
* // but let's pretend that these are set up by other mods
|
||||||
|
* // for the sake of example.
|
||||||
|
* TileEntityReplacementManager.tileEntityTransformer("otherModTE", ExampleMod::transformOther);
|
||||||
|
* BlockReplacementManager.addBlockReplacement("otherMod:block1", 0, MyBlocks.block1, 0);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public static BlockInfo transform(NBTTagCompound tag, World world, Chunk chunk) {
|
||||||
|
* int oldBlock = BlockAccessCompat.getBlockIDAtTE(tag, chunk);
|
||||||
|
* int x = tag.getInteger("x") & 0xF;
|
||||||
|
* int y = tag.getInteger("y");
|
||||||
|
* int z = tag.getInteger("z") & 0xF;
|
||||||
|
* int meta = chunk.getBlockMetadata(x, y, z);
|
||||||
|
* Block newBlock;
|
||||||
|
* String targetType;
|
||||||
|
* if (oldBlock == targetBlock1) {
|
||||||
|
* // block transformer executes after TE transformers
|
||||||
|
* // so we sill need to check for meta 0
|
||||||
|
* if (meta == 0) return null;
|
||||||
|
* newBlock = MyBlocks.block2;
|
||||||
|
* targetType = "stone";
|
||||||
|
* } else if (oldBlock == targetBlock2) {
|
||||||
|
* // another mod would be handling the transformation for 0
|
||||||
|
* if (meta != 1 && meta != 2) return null;
|
||||||
|
* newBlock = meta == 1 ? MyBlocks.block3 : MyBlocks.block4;
|
||||||
|
* targetType = "iron";
|
||||||
|
* } else {
|
||||||
|
* // Return null to tell postea that you can't handle via this transformer.
|
||||||
|
* // Maybe another transformer can handle it.
|
||||||
|
* return null;
|
||||||
|
* }
|
||||||
|
* return new BlockInfo(newBlock, 0, originalNBT -> {
|
||||||
|
* NBTTagCompound newNBT = PosteaUtilities.cleanseNBT("myTE", originalNBT);
|
||||||
|
* newNBT.setString("type", targetType);
|
||||||
|
* newNBT.setInteger("level", meta);
|
||||||
|
* newNBT.setInteger("fuelLevel", originalNBT.getInteger("storage") * 20);
|
||||||
|
* return newNBT;
|
||||||
|
* });
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* public static BlockInfo transformOther(NBTTagCompound tag, World world, Chunk chunk) {
|
||||||
|
* int oldBlock = BlockAccessCompat.getBlockIDAtTE(tag, chunk);
|
||||||
|
* int x = tag.getInteger("x") & 0xF;
|
||||||
|
* int y = tag.getInteger("y");
|
||||||
|
* int z = tag.getInteger("z") & 0xF;
|
||||||
|
* int meta = chunk.getBlockMetadata(x, y, z);
|
||||||
|
* if (oldBlock == targetBlock2) {
|
||||||
|
* if (meta != 3) return null;
|
||||||
|
* // that doesn't need to be a TE anymore.
|
||||||
|
* return new BlockInfo(MyBlocks.block5, 0, null);
|
||||||
|
* } else if (oldBlock == targetBlock3) {
|
||||||
|
* // transfer the TE correctly
|
||||||
|
* return new BlockInfo(MyBlocks.block6, meta, originalNBT -> {
|
||||||
|
* NBTTagCompound newNBT = PosteaUtilities.cleanseNBT("myOtherTE", originalNBT);
|
||||||
|
* newNBT.setInteger("remaining", originalNBT.getInteger("storage"));
|
||||||
|
* return newNBT;
|
||||||
|
* });
|
||||||
|
* }
|
||||||
|
* // can't handle this
|
||||||
|
* return null;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced ID of a block you wish to identify in one of your transformers.
|
||||||
|
* @param resolver The callback executed to provide the numeric ID of the given namespaced ID.
|
||||||
|
*/
|
||||||
|
// spotless:on
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void registerIDResolver(String originalId, Consumer<Integer> resolver) {
|
||||||
|
if (originalId == null) throw new NullPointerException("originalId cannot be null");
|
||||||
|
if (resolver == null) throw new NullPointerException("resolver cannot be null");
|
||||||
|
IDRegistry.registerBlockIDResolver(originalId, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion id resolving
|
||||||
|
|
||||||
|
// region missing mapping replacements
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks and block instances of a specific removed block to the given block whilst, whilst
|
||||||
|
* maintaining its meta value.<br>
|
||||||
|
* <br>
|
||||||
|
* <b><u>IMPORTANT: This only works if the world does not have an existing id set for the target block. If you need
|
||||||
|
* to transform a missing block into something that was previously given an id (e.g.: Transforming a removed block
|
||||||
|
* into dirt), use {@link #addSimpleReplacement(String, Block)} with both meta parameters set to
|
||||||
|
* OreDictionary.WILDCARD_VALUE.</u></b>
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void replaceMissingMapping(String originalId, Block block) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (block == null) throw new IllegalArgumentException("block is null");
|
||||||
|
MissingMappingHandler.addBlockMapping(originalId, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suppresses any missing mapping warning for the given id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block or item to suppress the warning for.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void ignoreMissingMapping(@Nonnull String originalId) {
|
||||||
|
MissingMappingHandler.addIgnore(originalId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion missing mapping replacements
|
||||||
|
|
||||||
|
// region simple replacements
|
||||||
|
|
||||||
|
// block -> block
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block to another block, whilst maintaining its
|
||||||
|
* meta value. This also adds a matching item stack replacement.
|
||||||
|
*
|
||||||
|
* @apiNote Use this if you are replacing a block with something that was already registered to a world's id
|
||||||
|
* mappings,
|
||||||
|
* (e.g.: Transforming a removed block into dirt)
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Block block) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, block, OreDictionary.WILDCARD_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block to another block, whilst maintaining its
|
||||||
|
* meta value.
|
||||||
|
*
|
||||||
|
* @apiNote Use this if you are replacing an item with something that was already registered to a world's id
|
||||||
|
* mappings,
|
||||||
|
* (e.g.: Transforming a removed block into dirt)
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param skipStackRemap Set to true to skip auto-adding an item stack remapper.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Block block, boolean skipStackRemap) {
|
||||||
|
addSimpleReplacement(
|
||||||
|
originalId,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
block,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
skipStackRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// block+meta -> block
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block and damage/meta value to another block,
|
||||||
|
* whilst maintaining its meta value. This also adds a matching item stack replacement.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param originalMeta The meta of the block to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Block block) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, block, OreDictionary.WILDCARD_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block and damage/meta value to another block,,
|
||||||
|
* whilst maintaining its meta value.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param originalMeta The meta of the block to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param skipStackRemap Set to true to skip auto-adding an item stack remapper.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Block block,
|
||||||
|
boolean skipStackRemap) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, block, OreDictionary.WILDCARD_VALUE, skipStackRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// block -> block+meta
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block to another block with a given damage/meta
|
||||||
|
* value. This also adds a matching item stack replacement.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param newMeta The meta of the block to remap to. OreDictionary.WILDCARD_VALUE maintains the existing value.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Block block, int newMeta) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, block, newMeta, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block to another block with a given damage/meta
|
||||||
|
* value.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param newMeta The meta of the block to remap to. OreDictionary.WILDCARD_VALUE maintains the existing
|
||||||
|
* value.
|
||||||
|
* @param skipStackRemap Set to true to skip auto-adding an item stack remapper.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Block block, int newMeta,
|
||||||
|
boolean skipStackRemap) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, block, newMeta, skipStackRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// block+meta -> block+meta
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block and damage/meta value to another block
|
||||||
|
* with a given damage/meta value. This also adds a matching item stack replacement.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param originalMeta The meta of the block to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param newMeta The meta of the block to remap to. OreDictionary.WILDCARD_VALUE maintains the existing value.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Block block,
|
||||||
|
int newMeta) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, block, newMeta, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks and block instances of a given block and damage/meta value to another block
|
||||||
|
* with a given damage/meta value.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block to remap.
|
||||||
|
* @param originalMeta The meta of the block to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param block The block to remap to.
|
||||||
|
* @param newMeta The meta of the block to remap to. OreDictionary.WILDCARD_VALUE maintains the existing
|
||||||
|
* value.
|
||||||
|
* @param skipStackRemap Set to true to skip auto-adding an item stack remapper.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(String originalId, int originalMeta, Block block, int newMeta,
|
||||||
|
boolean skipStackRemap) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (block == null) throw new IllegalArgumentException("block is null");
|
||||||
|
SimpleTransformationRegistry.addSimpleTransformer(originalId, originalMeta, block, newMeta, skipStackRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion simple replacements
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,166 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.compat.Compat;
|
||||||
|
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||||
|
import com.gtnewhorizons.postea.utility.NbtItemStacks;
|
||||||
|
import com.gtnewhorizons.postea.utility.NbtLists;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A chunk as handed to {@link IVersionedTransformer#transformChunk}: its block storage and the raw {@code Level}
|
||||||
|
* tag as read from disk, before tile entities and entities are parsed. Coordinates are chunk-local
|
||||||
|
* ({@code 0..15}, {@code y 0..255}); block ids and metadata are the world's numeric values at full EndlessIDs
|
||||||
|
* width. The world is not loaded yet: block access through {@link #world()} is not possible. When a transformer
|
||||||
|
* changed a block id, Postea recomputes the height map and flags the chunk for a relight once all transformers ran.
|
||||||
|
*/
|
||||||
|
public final class ChunkTransformContext {
|
||||||
|
|
||||||
|
public static final int UNSTAMPED = VersionStamps.UNSTAMPED;
|
||||||
|
|
||||||
|
private final Chunk chunk;
|
||||||
|
private final World world;
|
||||||
|
private final NBTTagCompound levelTag;
|
||||||
|
private final int storedVersion;
|
||||||
|
private final int currentVersion;
|
||||||
|
private final SubChunkAccess[] sections = new SubChunkAccess[16];
|
||||||
|
private boolean blockIdsChanged;
|
||||||
|
|
||||||
|
public ChunkTransformContext(Chunk chunk, World world, NBTTagCompound levelTag, int storedVersion,
|
||||||
|
int currentVersion) {
|
||||||
|
this.chunk = chunk;
|
||||||
|
this.world = world;
|
||||||
|
this.levelTag = levelTag;
|
||||||
|
this.storedVersion = storedVersion;
|
||||||
|
this.currentVersion = currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chunk chunk() {
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World world() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int chunkX() {
|
||||||
|
return chunk.xPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int chunkZ() {
|
||||||
|
return chunk.zPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The chunk's {@code Level} tag. Changes to its {@code TileEntities} and {@code Entities} lists are loaded by
|
||||||
|
* the game.
|
||||||
|
*/
|
||||||
|
public NBTTagCompound levelTag() {
|
||||||
|
return levelTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagList tileEntityTags() {
|
||||||
|
return NbtLists.compoundList(levelTag, "TileEntities");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagList entityTags() {
|
||||||
|
return NbtLists.compoundList(levelTag, "Entities");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version this transformer's key was stamped with when the chunk was saved, or {@link #UNSTAMPED}.
|
||||||
|
*/
|
||||||
|
public int storedVersion() {
|
||||||
|
return storedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int currentVersion() {
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The block id at a chunk-local position; 0 for a missing section.
|
||||||
|
*/
|
||||||
|
public int getBlockId(int x, int y, int z) {
|
||||||
|
SubChunkAccess access = section(y >> 4, false);
|
||||||
|
return access == null ? 0 : access.getBlockId(x, y & 15, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMetadata(int x, int y, int z) {
|
||||||
|
SubChunkAccess access = section(y >> 4, false);
|
||||||
|
return access == null ? 0 : access.getMeta(x, y & 15, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the block at a chunk-local position, creating the section when a non-air block goes into a missing one.
|
||||||
|
*/
|
||||||
|
public void setBlock(int x, int y, int z, int blockId, int metadata) {
|
||||||
|
SubChunkAccess access = section(y >> 4, blockId != 0);
|
||||||
|
if (access == null) return;
|
||||||
|
if (access.getBlockId(x, y & 15, z) != blockId) blockIdsChanged = true;
|
||||||
|
access.setBlockId(x, y & 15, z, blockId);
|
||||||
|
access.setMeta(x, y & 15, z, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits every non-air block of every present section.
|
||||||
|
*/
|
||||||
|
public void forEachBlock(BlockVisitor visitor) {
|
||||||
|
ExtendedBlockStorage[] storage = chunk.getBlockStorageArray();
|
||||||
|
for (int index = 0; index < storage.length; index++) {
|
||||||
|
if (storage[index] == null) continue;
|
||||||
|
SubChunkAccess access = section(index, false);
|
||||||
|
int base = index << 4;
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
int id = access.getBlockId(x, y, z);
|
||||||
|
if (id != 0) visitor.visit(x, base + y, z, id, access.getMeta(x, y, z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits every serialized item stack held by the chunk's tile entities and entities; see
|
||||||
|
* {@link NbtItemStacks#forEach}.
|
||||||
|
*/
|
||||||
|
public void forEachItemStackTag(Consumer<NBTTagCompound> visitor) {
|
||||||
|
NbtItemStacks.forEach(tileEntityTags(), visitor);
|
||||||
|
NbtItemStacks.forEach(entityTags(), visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a block id (not only metadata) was rewritten.
|
||||||
|
*/
|
||||||
|
public boolean blockIdsChanged() {
|
||||||
|
return blockIdsChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SubChunkAccess section(int index, boolean create) {
|
||||||
|
if (index < 0 || index >= sections.length) return null;
|
||||||
|
if (sections[index] == null) {
|
||||||
|
ExtendedBlockStorage[] storage = chunk.getBlockStorageArray();
|
||||||
|
if (storage[index] == null) {
|
||||||
|
if (!create) return null;
|
||||||
|
storage[index] = new ExtendedBlockStorage(index << 4, !world.provider.hasNoSky);
|
||||||
|
}
|
||||||
|
sections[index] = Compat.getSubChunkAccess(storage[index]);
|
||||||
|
}
|
||||||
|
return sections[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface BlockVisitor {
|
||||||
|
|
||||||
|
void visit(int x, int y, int z, int blockId, int metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.Postea;
|
||||||
|
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||||
|
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionedTransformerLog;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages applying an {@link IVersionedTransformer} to mods' custom storage files.
|
||||||
|
* <ul>
|
||||||
|
* <li>Call {@link #transform} once on the root read from disk, before consuming it, and persist that root (stamps
|
||||||
|
* included) when writing the storage back.</li>
|
||||||
|
* <li>A save path that rebuilds its NBT from scratch calls {@link #stamp} on the fresh root instead.</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
public abstract class CustomDataReplacementManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code root} in place through every registered transformer whose stamp differs from its current
|
||||||
|
* version, then writes the updated stamps onto {@code root}. Does nothing without a running server. Throws
|
||||||
|
* {@link IllegalStateException} when called before the world's saved id mappings were applied.
|
||||||
|
*/
|
||||||
|
public static void transform(String storageId, NBTTagCompound root) {
|
||||||
|
// Not the effective side: mods save their storage from worker threads, which 1.7.10 reports as client.
|
||||||
|
if (FMLCommonHandler.instance()
|
||||||
|
.getMinecraftServerInstance() == null) return;
|
||||||
|
if (!IDRegistry.isMappingApplied()) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Custom data " + storageId
|
||||||
|
+ " was offered for transformation before the world's id mappings were applied");
|
||||||
|
}
|
||||||
|
NBTTagCompound stamps = VersionStamps.read(root);
|
||||||
|
for (IVersionedTransformer transformer : VersionedReplacementManager.transformers()) {
|
||||||
|
int current = transformer.currentVersion();
|
||||||
|
int stored = VersionStamps.stored(stamps, transformer.key());
|
||||||
|
if (stored == current) continue;
|
||||||
|
VersionedTransformerLog.announce(transformer, stored, current);
|
||||||
|
Postea.LOG.debug("{}: custom data {} from version {} to {}", transformer.key(), storageId, stored, current);
|
||||||
|
try {
|
||||||
|
transformer.transformCustomData(new CustomDataTransformContext(storageId, root, stored, current));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new ReportedException(
|
||||||
|
ChunkFixerUtility.describe(t, transformer, stored, current, "Custom data", storageId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VersionStamps.write(root, stamps, VersionedReplacementManager.transformers());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stamps a freshly built root about to be written to disk with every registered transformer's current version.
|
||||||
|
* Does nothing without a running server.
|
||||||
|
*/
|
||||||
|
public static void stamp(NBTTagCompound root) {
|
||||||
|
if (FMLCommonHandler.instance()
|
||||||
|
.getMinecraftServerInstance() == null) return;
|
||||||
|
VersionStamps.write(root, VersionStamps.read(root), VersionedReplacementManager.transformers());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.NbtItemStacks;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context for a mod's custom world storage, used by {@link IVersionedTransformer#transformCustomData}. Stacks here
|
||||||
|
* may have string {@code id}s instead of numeric ones; {@link #forEachItemStackTag} visits both.
|
||||||
|
*/
|
||||||
|
public final class CustomDataTransformContext {
|
||||||
|
|
||||||
|
public static final int UNSTAMPED = VersionStamps.UNSTAMPED;
|
||||||
|
|
||||||
|
private final String storageId;
|
||||||
|
private final NBTTagCompound root;
|
||||||
|
private final int storedVersion;
|
||||||
|
private final int currentVersion;
|
||||||
|
|
||||||
|
public CustomDataTransformContext(String storageId, NBTTagCompound root, int storedVersion, int currentVersion) {
|
||||||
|
this.storageId = storageId;
|
||||||
|
this.root = root;
|
||||||
|
this.storedVersion = storedVersion;
|
||||||
|
this.currentVersion = currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The storage's identity as its owner registered it, e.g. {@code "betterquesting:questDatabase"}.
|
||||||
|
*/
|
||||||
|
public String storageId() {
|
||||||
|
return storageId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound root() {
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version this transformer's key was stamped with when the storage was written, or {@link #UNSTAMPED}.
|
||||||
|
*/
|
||||||
|
public int storedVersion() {
|
||||||
|
return storedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int currentVersion() {
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits every serialized item stack in the storage, including stacks whose {@code id} is a string name; see
|
||||||
|
* {@link NbtItemStacks#forEach}.
|
||||||
|
*/
|
||||||
|
public void forEachItemStackTag(Consumer<NBTTagCompound> visitor) {
|
||||||
|
NbtItemStacks.forEach(root, visitor, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,16 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IComplexBlockTransformer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom transformer for blocks.
|
||||||
|
*
|
||||||
|
* @param info The information about the block.
|
||||||
|
* @return True if the block was replaced and no other block transformation handler should be executed for the
|
||||||
|
* associated original id;
|
||||||
|
*/
|
||||||
|
boolean transformBlock(BlockConversionInfo info);
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IComplexStackTransformer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom transformer for items.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced id of the stack being passed to this transformer.
|
||||||
|
* @param tag The raw nbt data of the stack being transformed.
|
||||||
|
* @return A non-null value to prevent any future handlers from executing or if the stack was replaced.
|
||||||
|
*/
|
||||||
|
boolean transformStack(String originalId, NBTTagCompound tag);
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_SHORT;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API used to query and update stack item IDs inside Postea transformers.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class IDExtenderCompat {
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static int getItemStackID(NBTTagCompound tag) {
|
||||||
|
if (tag.hasKey("idExt", TAG_INT)) return tag.getInteger("idExt");
|
||||||
|
else if (tag.hasKey("id", TAG_INT)) return tag.getInteger("id");
|
||||||
|
else if (tag.hasKey("id", TAG_SHORT)) return tag.getShort("id");
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void setItemStackID(NBTTagCompound tag, int id) {
|
||||||
|
if (id < 32000) {
|
||||||
|
tag.setShort("id", (short) id);
|
||||||
|
} else {
|
||||||
|
tag.setShort("id", (short) 0);
|
||||||
|
tag.setInteger("idExt", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface IItemStackTransformationHandler {
|
||||||
|
|
||||||
|
boolean apply(String originalId, NBTTagCompound stack);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
|
public interface ISimpleBlockTransformer {
|
||||||
|
|
||||||
|
Block getTargetBlock();
|
||||||
|
|
||||||
|
int getTargetBlockMeta();
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
|
public interface ISimpleItemTransformer {
|
||||||
|
|
||||||
|
Item getTargetItem();
|
||||||
|
|
||||||
|
int getTargetItemMeta();
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public interface ISimpleStackTransformer {
|
||||||
|
|
||||||
|
ItemStack getTargetStack();
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A transformer that brings saved data written under an older version of its owner's content up to the current
|
||||||
|
* version. Postea stamps every chunk and every player it saves with {@link #currentVersion()} under {@link #key()}
|
||||||
|
* and, when reading, invokes the transformer only for data whose stamp differs, so each chunk and player is seen
|
||||||
|
* exactly once per version change no matter how many sessions passed in between. Data saved before the transformer
|
||||||
|
* existed reads as {@link ChunkTransformContext#UNSTAMPED}; the transformer decides what that means.
|
||||||
|
* <p>
|
||||||
|
* Register through {@link VersionedReplacementManager#register(IVersionedTransformer)} during mod loading, postInit
|
||||||
|
* at the latest. Transformers run in registration order and before every other Postea pass, so a transformer whose
|
||||||
|
* output depends on another mod's versioned data (for example one that writes that mod's indices) must register
|
||||||
|
* after that mod; FML's dependency ordering guarantees this when both register in the same lifecycle phase.
|
||||||
|
* <p>
|
||||||
|
* Chunk transformers may run on a chunk I/O thread, several concurrently for different chunks. They must not touch
|
||||||
|
* world state beyond the context and their own state must be safe to read concurrently.
|
||||||
|
* <p>
|
||||||
|
* Mods that keep item stacks in their own world storage offer it through {@link CustomDataReplacementManager};
|
||||||
|
* such storage is stamped the same way and reaches the transformer through {@link #transformCustomData}.
|
||||||
|
*/
|
||||||
|
public interface IVersionedTransformer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stamp key, unique across all registered transformers, e.g. {@code "examplemod:idList"}.
|
||||||
|
*/
|
||||||
|
String key();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version the transformer's output is written under. Sampled at every read and every save.
|
||||||
|
*/
|
||||||
|
int currentVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings a chunk stamped at {@link ChunkTransformContext#storedVersion()} to {@link #currentVersion()}.
|
||||||
|
*/
|
||||||
|
default void transformChunk(ChunkTransformContext ctx) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings a player's saved data stamped at {@link PlayerDataTransformContext#storedVersion()} to
|
||||||
|
* {@link #currentVersion()}.
|
||||||
|
*/
|
||||||
|
default void transformPlayer(PlayerDataTransformContext ctx) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Brings a mod's custom world storage stamped at {@link CustomDataTransformContext#storedVersion()} to
|
||||||
|
* {@link #currentVersion()}. Stacks in such storage may carry a string {@code id} instead of a numeric one.
|
||||||
|
*/
|
||||||
|
default void transformCustomData(CustomDataTransformContext ctx) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,373 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.MissingMappingHandler;
|
||||||
|
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
|
||||||
|
import com.gtnewhorizons.postea.utility.TransformerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API used to register item stack transformers via postea's handler system.<br>
|
||||||
|
* <br>
|
||||||
|
* Item stack transformers are applied when something tries to convert any NBT that has an "id" field into an item
|
||||||
|
* stack.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public abstract class ItemStackReplacementManager {
|
||||||
|
|
||||||
|
// region custom transformer registration
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom transformer for a given id.
|
||||||
|
*
|
||||||
|
* @apiNote When the transformer function passed to this function returns a null, value Postea will assume that
|
||||||
|
* the transformer has failed to identify and run the handler on any other handler function registered
|
||||||
|
* to the given ID.
|
||||||
|
* <p>
|
||||||
|
* If you need to perform a simple transformations consider using the following methods instead:
|
||||||
|
* <ul>
|
||||||
|
* <li>item -> item (with same meta): {@link #addSimpleReplacement(String, Item)}</li>
|
||||||
|
* <li>item -> item with specific meta: {@link #addSimpleReplacement(String, Item, int)}</li>
|
||||||
|
* <li>item with meta -> item (with same meta): {@link #addSimpleReplacement(String, int, Item)}</li>
|
||||||
|
* <li>item with meta -> item with specific meta:
|
||||||
|
* {@link #addSimpleReplacement(String, int, Item, int)}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @implNote For performance reasons, Postea assumes that the tag that was passed to the handler hasn't been
|
||||||
|
* modified if you return false. This isn't enforced though since returning false after doing some
|
||||||
|
* modifications has a couple niche uses. eg: having separate handlers for different migrations of a
|
||||||
|
* single thing that can be sunset at different times down the line.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to transform.
|
||||||
|
* @param transformer The transformer to apply.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addTransformationHandler(String originalId, IItemStackTransformationHandler transformer) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (transformer == null) throw new IllegalArgumentException("transformer is null");
|
||||||
|
TransformerRegistry.addStackTransformer(originalId, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion custom transformer registration
|
||||||
|
|
||||||
|
// region id resolving
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback function that will be provided the numeric ID of the given namespaced ID when a world is
|
||||||
|
* first loaded. Since forge doesn't discard stacks associated with missing IDs when loading a world for
|
||||||
|
* performance reasons, instead opting to null the result of the nbt data read, you can store that value into a
|
||||||
|
* static field, and use it to compare against an id provided to you during the execution of a transformation
|
||||||
|
* handler.<br>
|
||||||
|
* <br>
|
||||||
|
* This function is mostly intended to speed up larger transformer handlers since resolving the string id of a
|
||||||
|
* removed id inside a transformer will be slower than simply matching for it. Regular item transformers are
|
||||||
|
* already provided the string ID of the item they are transforming so, there is no reason not to do a switch case
|
||||||
|
* on those. This also overcomes the need to create dummy blocks and items in order to identify
|
||||||
|
* items inside a custom stack transformer.<br>
|
||||||
|
* <br>
|
||||||
|
* For compatibility reasons, it's better not to register dummies to take the place of dummy items. If one mod was
|
||||||
|
* to only convert blocks with a specific meta while another handled the rest, the other mod would either need
|
||||||
|
* additional work to detect your own dummy blocks or even worst, fail to identify the original blocks as it's not
|
||||||
|
* aware of your dummy blocks.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced ID of a block you wish to identify in one of your transformers.
|
||||||
|
* @param resolver The callback executed to provide the numeric ID of the given namespaced ID.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void registerIDResolver(String originalId, Consumer<Integer> resolver) {
|
||||||
|
if (originalId == null) throw new NullPointerException("originalId cannot be null");
|
||||||
|
if (resolver == null) throw new NullPointerException("resolver cannot be null");
|
||||||
|
IDRegistry.registerItemIDResolver(originalId, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion id resolving
|
||||||
|
|
||||||
|
// region missing mapping replacements
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a specific removed item to the given item.<br>
|
||||||
|
* <br>
|
||||||
|
* <b><u>IMPORTANT: This only works if the world does not have an existing id set for the target item. If you need
|
||||||
|
* to transform a missing item into something that was previously given an id (e.g.: Transforming a removed item
|
||||||
|
* into a stick), use {@link #addSimpleReplacement(String, int, Item, int)} with both meta values set to
|
||||||
|
* OreDictionary.WILDCARD_VALUE.</u></b>
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void replaceMissingMapping(String originalId, Item item) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (item == null) throw new IllegalArgumentException("item is null");
|
||||||
|
MissingMappingHandler.addItemMapping(originalId, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Suppresses any missing mapping warning for the given id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the block or item to suppress the warning for.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void ignoreMissingMapping(@Nonnull String originalId) {
|
||||||
|
MissingMappingHandler.addIgnore(originalId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion missing mapping replacements
|
||||||
|
|
||||||
|
// region simple replacements
|
||||||
|
|
||||||
|
// item -> item
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item, whilst maintaining its damage/meta value. This
|
||||||
|
* also adds a matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
*
|
||||||
|
* @apiNote Use this if you are replacing an item with something that was already registered to a world's id
|
||||||
|
* mappings,
|
||||||
|
* (e.g.: Transforming a removed item into a stick)
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Item item) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, item, OreDictionary.WILDCARD_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item, whilst maintaining its damage/meta value.
|
||||||
|
*
|
||||||
|
* @apiNote Use this if you are replacing an item with something that was already registered to a world's id
|
||||||
|
* mappings,
|
||||||
|
* (e.g.: Transforming a removed item into a stick)
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a block remapper if the item happens to be an ItemBlock.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Item item, boolean skipBlockRemap) {
|
||||||
|
addSimpleReplacement(
|
||||||
|
originalId,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
item,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// item -> item+meta
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item with a given damage/meta value. This also adds a
|
||||||
|
* matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param newMeta The meta of the item to remap to. OreDictionary.WILDCARD_VALUE maintains the existing value.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Item item, int newMeta) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, item, newMeta, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item with a given damage/meta value.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param newMeta The meta of the item to remap to. OreDictionary.WILDCARD_VALUE maintains the existing
|
||||||
|
* value.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a block remapper if the item happens to be an ItemBlock.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull Item item, int newMeta,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
addSimpleReplacement(originalId, OreDictionary.WILDCARD_VALUE, item, newMeta, skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// item -> stack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item with a given damage/meta value. This also adds a
|
||||||
|
* matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
* <br>
|
||||||
|
* DOES NOT COPY NBT FROM STACK.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param stack The item to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull ItemStack stack) {
|
||||||
|
addSimpleReplacement(
|
||||||
|
originalId,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
stack.getItem(),
|
||||||
|
Items.feather.getDamage(stack),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap stacks of a given item to another item with a given damage/meta value.
|
||||||
|
* <br>
|
||||||
|
* DOES NOT COPY NBT FROM STACK.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param stack A stack of the item to replace to.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a block remapper if the item happens to be an ItemBlock.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, @Nonnull ItemStack stack,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
addSimpleReplacement(
|
||||||
|
originalId,
|
||||||
|
OreDictionary.WILDCARD_VALUE,
|
||||||
|
stack.getItem(),
|
||||||
|
Items.feather.getDamage(stack),
|
||||||
|
skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// item+meta -> item
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item, whilst maintaining its
|
||||||
|
* damage/meta value. This also adds a matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Item item) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, item, OreDictionary.WILDCARD_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item, whilst maintaining its
|
||||||
|
* damage/meta value.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a item remapper if the .
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Item item,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, item, OreDictionary.WILDCARD_VALUE, skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// item+meta -> stack
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item with a
|
||||||
|
* given damage/meta value. This also adds a matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
* <br>
|
||||||
|
* DOES NOT COPY NBT FROM STACK.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param stack A stack of the item to replace to.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull ItemStack stack) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, stack, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item with a
|
||||||
|
* given damage/meta value.
|
||||||
|
* <br>
|
||||||
|
* DOES NOT COPY NBT FROM STACK.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param stack A stack of the item to replace to.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a block remapper if the item happens to be an ItemBlock.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull ItemStack stack,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, stack.getItem(), Items.feather.getDamage(stack), skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// item+meta -> item+meta
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item with a
|
||||||
|
* given damage/meta value. This also adds a matching block replacement if this item happens to be an ItemBlock.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param newMeta The meta of the item to remap to. OreDictionary.WILDCARD_VALUE maintains the existing value.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(@Nonnull String originalId, int originalMeta, @Nonnull Item item,
|
||||||
|
int newMeta) {
|
||||||
|
addSimpleReplacement(originalId, originalMeta, item, newMeta, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mapping to remap all stacks of a given item and damage/meta value to another item with a
|
||||||
|
* given damage/meta value.
|
||||||
|
*
|
||||||
|
* @implNote All transformations registered using this handler are executed in constant time regardless of how many
|
||||||
|
* transformations are registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The id of the item to remap.
|
||||||
|
* @param originalMeta The meta of the item to remap. OreDictionary.WILDCARD_VALUE acts as a wildcard.
|
||||||
|
* @param item The item to remap to.
|
||||||
|
* @param newMeta The meta of the item to remap to. OreDictionary.WILDCARD_VALUE maintains the existing
|
||||||
|
* value.
|
||||||
|
* @param skipBlockRemap Set to true to skip auto-adding a item remapper if the .
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static void addSimpleReplacement(String originalId, int originalMeta, Item item, int newMeta,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
if (originalId == null) throw new IllegalArgumentException("original id is null");
|
||||||
|
if (item == null) throw new IllegalArgumentException("item is null");
|
||||||
|
SimpleTransformationRegistry.addSimpleTransformer(originalId, originalMeta, item, newMeta, skipBlockRemap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion simple replacements
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.NbtItemStacks;
|
||||||
|
import com.gtnewhorizons.postea.utility.VersionStamps;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A player's saved data as handed to {@link IVersionedTransformer#transformPlayer}: the root tag about to be
|
||||||
|
* loaded into the player, which holds the inventory, ender chest, {@code ForgeData}, and every extended-properties
|
||||||
|
* compound. The player object is constructed but not yet loaded from the tag.
|
||||||
|
*/
|
||||||
|
public final class PlayerDataTransformContext {
|
||||||
|
|
||||||
|
public static final int UNSTAMPED = VersionStamps.UNSTAMPED;
|
||||||
|
|
||||||
|
private final EntityPlayerMP player;
|
||||||
|
private final NBTTagCompound playerTag;
|
||||||
|
private final int storedVersion;
|
||||||
|
private final int currentVersion;
|
||||||
|
|
||||||
|
public PlayerDataTransformContext(EntityPlayerMP player, NBTTagCompound playerTag, int storedVersion,
|
||||||
|
int currentVersion) {
|
||||||
|
this.player = player;
|
||||||
|
this.playerTag = playerTag;
|
||||||
|
this.storedVersion = storedVersion;
|
||||||
|
this.currentVersion = currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityPlayerMP player() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound playerTag() {
|
||||||
|
return playerTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int storedVersion() {
|
||||||
|
return storedVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int currentVersion() {
|
||||||
|
return currentVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits every serialized item stack anywhere in the player's data; see {@link NbtItemStacks#forEach}.
|
||||||
|
*/
|
||||||
|
public void forEachItemStackTag(Consumer<NBTTagCompound> visitor) {
|
||||||
|
NbtItemStacks.forEach(playerTag, visitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.BlockConversionInfo;
|
||||||
|
|
||||||
|
public abstract class PosteaBlockStackTransformer {
|
||||||
|
|
||||||
|
public String originalId;
|
||||||
|
public int originalMeta;
|
||||||
|
|
||||||
|
public PosteaBlockStackTransformer(String originalId) {
|
||||||
|
this(originalId, OreDictionary.WILDCARD_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PosteaBlockStackTransformer(String originalId, int originalMeta) {
|
||||||
|
this.originalId = originalId;
|
||||||
|
this.originalMeta = originalMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register() {
|
||||||
|
if (this instanceof IComplexStackTransformer cst) {
|
||||||
|
if (this.originalMeta == OreDictionary.WILDCARD_VALUE) {
|
||||||
|
ItemStackReplacementManager.addTransformationHandler(
|
||||||
|
this.originalId,
|
||||||
|
(originalId, tag) -> complexStackTransformerCheckMeta(originalId, tag, cst));
|
||||||
|
} else {
|
||||||
|
ItemStackReplacementManager.addTransformationHandler(this.originalId, cst::transformStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this instanceof IComplexBlockTransformer cbt) {
|
||||||
|
if (this.originalMeta == OreDictionary.WILDCARD_VALUE) {
|
||||||
|
BlockReplacementManager
|
||||||
|
.addTransformationHandler(this.originalId, (info) -> complexBlockTransformerCheckMeta(info, cbt));
|
||||||
|
} else {
|
||||||
|
BlockReplacementManager.addTransformationHandler(this.originalId, cbt::transformBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this instanceof ISimpleBlockTransformer sbt) {
|
||||||
|
BlockReplacementManager.addSimpleReplacement(
|
||||||
|
this.originalId,
|
||||||
|
this.originalMeta,
|
||||||
|
sbt.getTargetBlock(),
|
||||||
|
sbt.getTargetBlockMeta(),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
if (this instanceof ISimpleItemTransformer sit) {
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement(
|
||||||
|
this.originalId,
|
||||||
|
this.originalMeta,
|
||||||
|
sit.getTargetItem(),
|
||||||
|
sit.getTargetItemMeta(),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
if (this instanceof ISimpleStackTransformer sst) {
|
||||||
|
ItemStack stack = sst.getTargetStack();
|
||||||
|
ItemStackReplacementManager.addSimpleReplacement(
|
||||||
|
this.originalId,
|
||||||
|
this.originalMeta,
|
||||||
|
stack.getItem(),
|
||||||
|
Items.feather.getDamage(stack),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean complexStackTransformerCheckMeta(String originalId, NBTTagCompound tag,
|
||||||
|
IComplexStackTransformer st) {
|
||||||
|
if (tag.getShort("Damage") != originalMeta) return false;
|
||||||
|
return st.transformStack(originalId, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean complexBlockTransformerCheckMeta(BlockConversionInfo info, IComplexBlockTransformer bt) {
|
||||||
|
if (info.metadata != originalMeta) return false;
|
||||||
|
return bt.transformBlock(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.BlockInfo;
|
||||||
|
import com.gtnewhorizons.postea.utility.PosteaUtilities;
|
||||||
|
import com.gtnewhorizons.postea.utility.TransformerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public API used to register tile entity transformers via postea's handler system.<br>
|
||||||
|
* <br>
|
||||||
|
* Tile entity transformers are executed before any block transformers, when chunks being loading into the world.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public abstract class TileEntityReplacementManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
* If you return a null value instead of a block info, Postea will assume that you don't want to replace the block
|
||||||
|
* and/or tile entity and look for any other compatible handlers that may be able to do a replacement.<br>
|
||||||
|
* <br>
|
||||||
|
* Note that the callback will be called before the world is fully loaded, and {@code world.getBlock} will throw an
|
||||||
|
* error. If you need to identify a block, consider using
|
||||||
|
* {@link BlockReplacementManager#registerIDResolver(String, Consumer)}
|
||||||
|
* and {@link BlockAccessCompat#getBlockIDAtTE(NBTTagCompound, Chunk)} instead. If you need to identify the meta
|
||||||
|
* value, consider using {@code Chunk.getBlockMetadata(x & 15, y, z & 15)} or the other functions inside of
|
||||||
|
* {@link BlockReplacementManager}.<br>
|
||||||
|
* <br>
|
||||||
|
* {@code BlockReplacementManager.registerIDResolver} registers a simple callback that will be executed just after
|
||||||
|
* the game resolves all numeric ID conflicts when loading a save. The provided value is the numeric ID of the
|
||||||
|
* block linked provided string ID or -1 if the block has <em>never</em> been registered while the currently
|
||||||
|
* loading world.<br>
|
||||||
|
* <br>
|
||||||
|
* {@code BlockAccessCompat.getBlockIDAtTE} lets you fetch the ID of the block where the current tile entity is
|
||||||
|
* located. Since forge doesn't actually replace the id of missing blocks for performance reasons, opting to treat
|
||||||
|
* them like air instead; You can use the value given to the resolver you registered using
|
||||||
|
* {@code BlockReplacementManager.registerIDResolver} to identify the block directly.<br>
|
||||||
|
* <br>
|
||||||
|
* Using these 2 methods skips the need to register dummy blocks or items to identify blocks when migrating things,
|
||||||
|
* which will improve the overall performance and compatibility of your migrations.
|
||||||
|
*
|
||||||
|
* @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) {
|
||||||
|
if (transformerFunction == null) throw new NullPointerException("transformer is null");
|
||||||
|
if (tileEntityId == null) throw new NullPointerException("transformer is null");
|
||||||
|
TransformerRegistry.addTileEntityTransformer(tileEntityId, transformerFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a bare-bones tile entity tag for the provided ID that clones all the positional information of the
|
||||||
|
* provided tile entity NBT Tag. The passed NBT tag is never modified.
|
||||||
|
*
|
||||||
|
* @param tag The tag of the tile entity at the current position.
|
||||||
|
* @param newId The ID of the new tile entity.
|
||||||
|
* @return A bare-bones tile entity tag for the provided id at ths same position as the passed tile entity tag.
|
||||||
|
*/
|
||||||
|
public static NBTTagCompound createTETagAtSamePosition(String newId, NBTTagCompound tag) {
|
||||||
|
if (tag == null) throw new NullPointerException("tag was null");
|
||||||
|
if (newId == null) throw new NullPointerException("tag was null");
|
||||||
|
return PosteaUtilities.cleanseNBT(newId, tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple function interface for functions with 3 parameters that must return a value.
|
||||||
|
*
|
||||||
|
* @param <T> The first parameter type.
|
||||||
|
* @param <U> The second parameter type.
|
||||||
|
* @param <O> The third parameter type.
|
||||||
|
* @param <R> The return type.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface TriFunction<T, U, O, R> {
|
||||||
|
|
||||||
|
R apply(T t, U u, O o);
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.gtnewhorizons.postea.api;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registration of {@link IVersionedTransformer}s. See that interface for the execution contract.
|
||||||
|
*/
|
||||||
|
public abstract class VersionedReplacementManager {
|
||||||
|
|
||||||
|
private static final List<IVersionedTransformer> TRANSFORMERS = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a transformer. Throws {@link IllegalArgumentException} when its key is empty or already registered.
|
||||||
|
*/
|
||||||
|
public static void register(IVersionedTransformer transformer) {
|
||||||
|
String key = Objects.requireNonNull(transformer.key(), "key must not be null");
|
||||||
|
if (key.isEmpty()) throw new IllegalArgumentException("Versioned transformer key must not be empty");
|
||||||
|
for (IVersionedTransformer existing : TRANSFORMERS) {
|
||||||
|
if (existing.key()
|
||||||
|
.equals(key)) {
|
||||||
|
throw new IllegalArgumentException("A versioned transformer is already registered for " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TRANSFORMERS.add(transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The registered transformers in registration order.
|
||||||
|
*/
|
||||||
|
public static List<IVersionedTransformer> transformers() {
|
||||||
|
return Collections.unmodifiableList(TRANSFORMERS);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package com.gtnewhorizons.postea.compat;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
|
import net.minecraft.world.chunk.NibbleArray;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.falsepattern.endlessids.mixin.helpers.SubChunkBlockHook;
|
||||||
|
import com.gtnewhorizons.neid.mixins.interfaces.IExtendedBlockStorageMixin;
|
||||||
|
|
||||||
|
import codechicken.nei.api.API;
|
||||||
|
|
||||||
|
public class Compat {
|
||||||
|
|
||||||
|
private static Boolean endlessids = null;
|
||||||
|
private static Boolean neid = null;
|
||||||
|
private static Boolean nei = null;
|
||||||
|
|
||||||
|
public static boolean endlessidsPresent() {
|
||||||
|
if (endlessids == null) {
|
||||||
|
boolean present = false;
|
||||||
|
try {
|
||||||
|
present = Launch.classLoader.getClassBytes("com.falsepattern.endlessids.asm.EndlessIDsCore") != null;
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
endlessids = present;
|
||||||
|
}
|
||||||
|
return endlessids;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean neidPresent() {
|
||||||
|
if (neid == null) {
|
||||||
|
boolean present = false;
|
||||||
|
try {
|
||||||
|
present = Launch.classLoader.getClassBytes("com.gtnewhorizons.neid.core.NEIDCore") != null;
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
neid = present;
|
||||||
|
}
|
||||||
|
return neid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean neiPresent() {
|
||||||
|
if (nei == null) {
|
||||||
|
boolean present = false;
|
||||||
|
try {
|
||||||
|
present = Launch.classLoader.getClassBytes("codechicken.nei.api.API") != null;
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
nei = present;
|
||||||
|
}
|
||||||
|
return nei;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
|
||||||
|
if (endlessidsPresent()) {
|
||||||
|
return EndlessIDSCompat.getSubChunkAccess(subChunk);
|
||||||
|
} else if (neidPresent()) {
|
||||||
|
return NEIDCompat.getSubChunkAccess(subChunk);
|
||||||
|
} else {
|
||||||
|
return VanillaCompat.getSubChunkAccess(subChunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class VanillaCompat {
|
||||||
|
|
||||||
|
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
|
||||||
|
final byte[] lsb = subChunk.getBlockLSBArray();
|
||||||
|
return new SubChunkAccess() {
|
||||||
|
|
||||||
|
private NibbleArray msb = subChunk.getBlockMSBArray();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBlockId(int x, int y, int z) {
|
||||||
|
int i = toIndex(x, y, z);
|
||||||
|
int id = lsb[i] & 0xFF;
|
||||||
|
if (msb != null) {
|
||||||
|
id |= msb.get(x, y, z) << 8;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlockId(int x, int y, int z, int id) {
|
||||||
|
int i = toIndex(x, y, z);
|
||||||
|
int l = id & 0xFF;
|
||||||
|
int h = (id >>> 8) & 0xF;
|
||||||
|
lsb[i] = (byte) l;
|
||||||
|
if (h == 0 && msb == null) return;
|
||||||
|
if (msb == null) {
|
||||||
|
msb = new NibbleArray(lsb.length, 4);
|
||||||
|
subChunk.setBlockMSBArray(msb);
|
||||||
|
}
|
||||||
|
msb.set(x, y, z, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMeta(int x, int y, int z) {
|
||||||
|
return subChunk.getExtBlockMetadata(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMeta(int x, int y, int z, int meta) {
|
||||||
|
subChunk.setExtBlockMetadata(x, y, z, meta);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class EndlessIDSCompat {
|
||||||
|
|
||||||
|
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
|
||||||
|
final SubChunkBlockHook bh = (SubChunkBlockHook) subChunk;
|
||||||
|
return new SubChunkAccess() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBlockId(int x, int y, int z) {
|
||||||
|
return bh.eid$getID(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlockId(int x, int y, int z, int id) {
|
||||||
|
bh.eid$setID(x, y, z, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMeta(int x, int y, int z) {
|
||||||
|
return bh.eid$getMetadata(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMeta(int x, int y, int z, int meta) {
|
||||||
|
bh.eid$setMetadata(x, y, z, meta);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class NEIDCompat {
|
||||||
|
|
||||||
|
public static SubChunkAccess getSubChunkAccess(ExtendedBlockStorage subChunk) {
|
||||||
|
final IExtendedBlockStorageMixin bh = (IExtendedBlockStorageMixin) subChunk;
|
||||||
|
final short[] blockArray = bh.getBlock16BArray();
|
||||||
|
final short[] metaArray = bh.getBlock16BMetaArray();
|
||||||
|
return new SubChunkAccess() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBlockId(int x, int y, int z) {
|
||||||
|
return blockArray[toIndex(x, y, z)];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlockId(int x, int y, int z, int id) {
|
||||||
|
blockArray[toIndex(x, y, z)] = (short) id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMeta(int x, int y, int z) {
|
||||||
|
return metaArray[toIndex(x, y, z)];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMeta(int x, int y, int z, int meta) {
|
||||||
|
metaArray[toIndex(x, y, z)] = (short) meta;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void hideItemFromNEI(Item item) {
|
||||||
|
if (!neiPresent()) return;
|
||||||
|
NEICompat.hideItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class NEICompat {
|
||||||
|
|
||||||
|
public static void hideItem(Item item) {
|
||||||
|
API.hideItem(new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int toIndex(int x, int y, int z) {
|
||||||
|
return y << 8 | z << 4 | x;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.gtnewhorizons.postea.compat;
|
||||||
|
|
||||||
|
public interface SubChunkAccess {
|
||||||
|
|
||||||
|
int getBlockId(int x, int y, int z);
|
||||||
|
|
||||||
|
void setBlockId(int x, int y, int z, int id);
|
||||||
|
|
||||||
|
int getMeta(int x, int y, int z);
|
||||||
|
|
||||||
|
void setMeta(int x, int y, int z, int meta);
|
||||||
|
}
|
||||||
+4
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.colen.postea.mixins;
|
package com.gtnewhorizons.postea.mixins;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -45,7 +45,10 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
|
|||||||
final List<String> mixins = new ArrayList<>();
|
final List<String> mixins = new ArrayList<>();
|
||||||
mixins.add("MixinItemStack");
|
mixins.add("MixinItemStack");
|
||||||
mixins.add("MixinChunk");
|
mixins.add("MixinChunk");
|
||||||
|
mixins.add("MixinEntity");
|
||||||
|
mixins.add("MixinEntityPlayer");
|
||||||
mixins.add("MixinAnvilChunkLoader");
|
mixins.add("MixinAnvilChunkLoader");
|
||||||
|
mixins.add("MixinNBTTagList");
|
||||||
return mixins;
|
return mixins;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||||
|
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||||
|
|
||||||
|
public final class PosteaPreInitLoadingPlugin implements IMixinConfigPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad(String mixinPackage) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRefMapperConfig() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMixins() {
|
||||||
|
List<String> mixins = new ArrayList<>();
|
||||||
|
mixins.add("MixinGameData");
|
||||||
|
return mixins;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postApply(String s, ClassNode classNode, String s1, IMixinInfo iMixinInfo) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
|
||||||
|
|
||||||
|
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.ChunkFixerUtility;
|
||||||
|
|
||||||
|
@Mixin(value = AnvilChunkLoader.class, priority = 1100)
|
||||||
|
public abstract class MixinAnvilChunkLoader {
|
||||||
|
|
||||||
|
// Forge-added funnel for sync and async loads; runs after relocation fix-ups and after ChunkAPI's own
|
||||||
|
// readChunkFromNBT replacement, so covers vanilla, NEID, EndlessIDs, and ChunkAPI.
|
||||||
|
@Inject(method = "checkedReadChunkFromNBT__Async", at = @At("RETURN"), remap = false, require = 1)
|
||||||
|
private void postea$chunkHook(CallbackInfoReturnable<Object[]> cir) {
|
||||||
|
Object[] data = cir.getReturnValue();
|
||||||
|
if (data == null) return;
|
||||||
|
Chunk chunk = (Chunk) data[0];
|
||||||
|
ChunkFixerUtility.onChunkRead(chunk, chunk.worldObj, ((NBTTagCompound) data[1]).getCompoundTag("Level"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "loadChunk", at = @At("RETURN"))
|
||||||
|
private void postea$updatePosteaChunkCode(World world, int i, int j, CallbackInfoReturnable<Chunk> cir) {
|
||||||
|
ChunkFixerUtility.onChunkLoaded(cir.getReturnValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "writeChunkToNBT", at = @At("HEAD"), order = 900)
|
||||||
|
private void postea$writePosteaChunkCode(Chunk chunk, World world, NBTTagCompound nbtTagCompound, CallbackInfo ci) {
|
||||||
|
ChunkFixerUtility.onChunkWrite(chunk, nbtTagCompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
||||||
|
|
||||||
|
@Mixin(Chunk.class)
|
||||||
|
public class MixinChunk implements IChunkMixin {
|
||||||
|
|
||||||
|
// This new field will store the hash of mod name + versions. We use this to check
|
||||||
|
// if we need to reprocess this chunk.
|
||||||
|
@Unique
|
||||||
|
private long postea_GTNH$posteaID;
|
||||||
|
|
||||||
|
// The stamps the chunk was read with; null for a chunk generated this session.
|
||||||
|
@Unique
|
||||||
|
private NBTTagCompound postea$versionStamps;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private boolean postea$versionedDirty;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public long Postea$getPosteaCode() {
|
||||||
|
return postea_GTNH$posteaID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public void Postea$setPosteaCode(long POSTEA_ID) {
|
||||||
|
this.postea_GTNH$posteaID = POSTEA_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public NBTTagCompound Postea$getVersionStamps() {
|
||||||
|
return postea$versionStamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public void Postea$setVersionStamps(NBTTagCompound stamps) {
|
||||||
|
this.postea$versionStamps = stamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public boolean Postea$isVersionedDirty() {
|
||||||
|
return postea$versionedDirty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public void Postea$setVersionedDirty(boolean dirty) {
|
||||||
|
this.postea$versionedDirty = dirty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.mixins.interfaces.IPlayerStampsMixin;
|
||||||
|
import com.gtnewhorizons.postea.utility.PlayerDataFixerUtility;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public abstract class MixinEntity implements IPlayerStampsMixin {
|
||||||
|
|
||||||
|
// The stamps a server player's data was read with; carried across respawns by MixinEntityPlayer.
|
||||||
|
@Unique
|
||||||
|
private NBTTagCompound postea$versionStamps;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public NBTTagCompound Postea$getVersionStamps() {
|
||||||
|
return postea$versionStamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
public void Postea$setVersionStamps(NBTTagCompound stamps) {
|
||||||
|
this.postea$versionStamps = stamps;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "readFromNBT", at = @At("HEAD"), require = 1)
|
||||||
|
private void postea$transformPlayerData(NBTTagCompound tag, CallbackInfo ci) {
|
||||||
|
if ((Object) this instanceof EntityPlayerMP player) {
|
||||||
|
postea$versionStamps = PlayerDataFixerUtility.onPlayerRead(player, tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "writeToNBT", at = @At("RETURN"), require = 1)
|
||||||
|
private void postea$stampPlayerData(NBTTagCompound tag, CallbackInfo ci) {
|
||||||
|
if ((Object) this instanceof EntityPlayerMP) {
|
||||||
|
PlayerDataFixerUtility.onPlayerWrite(tag, postea$versionStamps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
|
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.gtnewhorizons.postea.mixins.interfaces.IPlayerStampsMixin;
|
||||||
|
|
||||||
|
@Mixin(EntityPlayer.class)
|
||||||
|
public abstract class MixinEntityPlayer {
|
||||||
|
|
||||||
|
// A respawned player is a fresh entity built from the old one without going through NBT.
|
||||||
|
@Inject(method = "clonePlayer", at = @At("RETURN"), require = 1)
|
||||||
|
private void postea$carryVersionStamps(EntityPlayer oldPlayer, boolean respawn, CallbackInfo ci) {
|
||||||
|
((IPlayerStampsMixin) this).Postea$setVersionStamps(((IPlayerStampsMixin) oldPlayer).Postea$getVersionStamps());
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-4
@@ -1,6 +1,4 @@
|
|||||||
package com.colen.postea.mixins.early;
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
import static com.colen.postea.Utility.ItemFixerUtility.fixItemStack;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
@@ -10,6 +8,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.TransformerRegistry;
|
||||||
|
|
||||||
@Mixin(ItemStack.class)
|
@Mixin(ItemStack.class)
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public abstract class MixinItemStack {
|
public abstract class MixinItemStack {
|
||||||
@@ -17,7 +17,7 @@ public abstract class MixinItemStack {
|
|||||||
@Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("HEAD"))
|
@Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("HEAD"))
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void onReadFromNBTReturn(NBTTagCompound tag, CallbackInfo ci) {
|
private void onReadFromNBTReturn(NBTTagCompound tag, CallbackInfo ci) {
|
||||||
fixItemStack(tag);
|
TransformerRegistry.transformItem(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.early;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.mixins.interfaces.IMixinNBTTagList;
|
||||||
|
|
||||||
|
@Mixin(NBTTagList.class)
|
||||||
|
public class MixinNBTTagList implements IMixinNBTTagList {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
@Final
|
||||||
|
private List tagList = new ArrayList();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Unique
|
||||||
|
public void Postea$replaceCompoundTagAt(int index, NBTTagCompound tag) {
|
||||||
|
tagList.set(index, tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.interfaces;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public interface IChunkMixin {
|
||||||
|
|
||||||
|
long Postea$getPosteaCode();
|
||||||
|
|
||||||
|
void Postea$setPosteaCode(long posteaID);
|
||||||
|
|
||||||
|
NBTTagCompound Postea$getVersionStamps();
|
||||||
|
|
||||||
|
void Postea$setVersionStamps(NBTTagCompound stamps);
|
||||||
|
|
||||||
|
boolean Postea$isVersionedDirty();
|
||||||
|
|
||||||
|
void Postea$setVersionedDirty(boolean dirty);
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.interfaces;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public interface IMixinNBTTagList {
|
||||||
|
|
||||||
|
void Postea$replaceCompoundTagAt(int index, NBTTagCompound tag);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.interfaces;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public interface IPlayerStampsMixin {
|
||||||
|
|
||||||
|
NBTTagCompound Postea$getVersionStamps();
|
||||||
|
|
||||||
|
void Postea$setVersionStamps(NBTTagCompound stamps);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.gtnewhorizons.postea.mixins.preinit;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
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.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.registry.GameData;
|
||||||
|
|
||||||
|
@Mixin(value = GameData.class, remap = false)
|
||||||
|
public abstract class MixinGameData {
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "injectWorldIDMap(Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;Ljava/util/Map;Ljava/util/Set;Ljava/util/Set;ZZ)Ljava/util/List;",
|
||||||
|
at = @At("HEAD"),
|
||||||
|
require = 1)
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static void Postea$injectWorldIDMap(Map<String, Integer> dataList, Set<Integer> blockedIds,
|
||||||
|
Map<String, String> blockAliases, Map<String, String> itemAliases, Set<String> blockSubstitutions,
|
||||||
|
Set<String> itemSubstitutions, boolean injectFrozenData, boolean isLocalWorld,
|
||||||
|
CallbackInfoReturnable<List<String>> cir) {
|
||||||
|
IDRegistry.registerWorldSpecificIDs(dataList);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public final class BlockConversionInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The namespaced ID of the block being converted.
|
||||||
|
*/
|
||||||
|
public final String blockName;
|
||||||
|
/**
|
||||||
|
* The numeric ID of the block currently being replaced, or of the block you want it replaced with.
|
||||||
|
*/
|
||||||
|
public int blockID;
|
||||||
|
/**
|
||||||
|
* The meta value of the block currently being replaced, or value you want it replaced with.
|
||||||
|
*/
|
||||||
|
public int metadata;
|
||||||
|
/**
|
||||||
|
* The x coordinate of the block being replaced.
|
||||||
|
*/
|
||||||
|
public final int x;
|
||||||
|
/**
|
||||||
|
* The y coordinate of the block being replaced.
|
||||||
|
*/
|
||||||
|
public final int y;
|
||||||
|
/**
|
||||||
|
* The z coordinate of the block being replaced.
|
||||||
|
*/
|
||||||
|
public final int z;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world containing the block being replaced. It won't be loaded fully when a block transformer is executed, so
|
||||||
|
* any call to something like world.getBlock() will throw an error.
|
||||||
|
*/
|
||||||
|
public final World world;
|
||||||
|
|
||||||
|
public BlockConversionInfo(String blockName, int blockID, int metadata, int x, int y, int z, World world) {
|
||||||
|
this.blockName = blockName;
|
||||||
|
this.blockID = blockID;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
public final class BlockInfo {
|
||||||
|
|
||||||
|
public final Block block;
|
||||||
|
public final int metadata;
|
||||||
|
public final Function<NBTTagCompound, NBTTagCompound> tileTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to notify postea that you wish to update a tile entity, and the block situated at that same location.
|
||||||
|
*
|
||||||
|
* @param block The block that should replace the block currently stored at the tile entity's location.
|
||||||
|
* @param metadata The meta value of the block being placed where the tile entity used to exist.
|
||||||
|
* @param tileTransformer A transformer function for the NBT data of the tile entity. (you can just edit the one
|
||||||
|
* passed to the transformer instead, it's executed right after you return this block info,
|
||||||
|
* just make sure to provide a pass though function otherwise we won't know you want to keep
|
||||||
|
* the tile entity alive.)
|
||||||
|
*/
|
||||||
|
public BlockInfo(Block block, int metadata, Function<NBTTagCompound, NBTTagCompound> tileTransformer) {
|
||||||
|
this.block = block;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.tileTransformer = tileTransformer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to replace a tile entity with a block that does not need any tile entity data. Any existing data will be
|
||||||
|
* erased when returning a block info created with this constructor.
|
||||||
|
*
|
||||||
|
* @param block The block that should replace the block currently stored at the tile entity's location.
|
||||||
|
* @param metadata The meta value of the block being placed where the tile entity used to exist.
|
||||||
|
*/
|
||||||
|
public BlockInfo(Block block, int metadata) {
|
||||||
|
this.block = block;
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.tileTransformer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static com.gtnewhorizons.postea.utility.TransformerRegistry.getBlockReplacement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import net.minecraft.crash.CrashReport;
|
||||||
|
import net.minecraft.crash.CrashReportCategory;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.ChunkTransformContext;
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
import com.gtnewhorizons.postea.api.TriFunction;
|
||||||
|
import com.gtnewhorizons.postea.api.VersionedReplacementManager;
|
||||||
|
import com.gtnewhorizons.postea.compat.Compat;
|
||||||
|
import com.gtnewhorizons.postea.compat.SubChunkAccess;
|
||||||
|
import com.gtnewhorizons.postea.mixins.interfaces.IChunkMixin;
|
||||||
|
import com.gtnewhorizons.postea.mixins.interfaces.IMixinNBTTagList;
|
||||||
|
|
||||||
|
public class ChunkFixerUtility {
|
||||||
|
|
||||||
|
// This will not change between runs, unless a mod is updated or added.
|
||||||
|
public static final int POSTEA_UPDATE_CODE = PosteaUtilities.getModListHash();
|
||||||
|
|
||||||
|
public static boolean hasChunkBeenUpdated(long chunkHash) {
|
||||||
|
// We are in a dev env.
|
||||||
|
if (POSTEA_UPDATE_CODE == -1) return false;
|
||||||
|
return chunkHash == POSTEA_UPDATE_CODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int AIR_ID = 0;
|
||||||
|
|
||||||
|
public static void onChunkRead(Chunk chunk, World world, NBTTagCompound tag) {
|
||||||
|
IChunkMixin chunkMixin = (IChunkMixin) chunk;
|
||||||
|
runVersionedTransformers(chunk, world, tag);
|
||||||
|
chunkMixin.Postea$setPosteaCode(tag.hasKey("POSTEA", 4) ? tag.getLong("POSTEA") : -1);
|
||||||
|
// This checks if the chunk has been run with the current POSTEA_UPDATE_CODE and skips it if so.
|
||||||
|
if (hasChunkBeenUpdated(chunkMixin.Postea$getPosteaCode())) return;
|
||||||
|
List<ConversionInfo> conversionInfoList = adjustTileEntities(tag.getTagList("TileEntities", 10), world, chunk);
|
||||||
|
|
||||||
|
for (ExtendedBlockStorage ebs : chunk.getBlockStorageArray()) {
|
||||||
|
if (ebs == null) continue;
|
||||||
|
int sectionY = ebs.getYLocation();
|
||||||
|
|
||||||
|
List<ConversionInfo> filteredList = conversionInfoList.stream()
|
||||||
|
.filter(info -> info.y >= sectionY && info.y < (sectionY + 16))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (ConversionInfo info : filteredList) {
|
||||||
|
int localX = info.x & 15;
|
||||||
|
int localY = info.y & 15;
|
||||||
|
int localZ = info.z & 15;
|
||||||
|
ebs.func_150818_a(localX, localY, localZ, info.blockInfo.block);
|
||||||
|
ebs.setExtBlockMetadata(localX, localY, localZ, info.blockInfo.metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
transformNormalBlocksInSubChunk(chunk, ebs, world);
|
||||||
|
}
|
||||||
|
chunkMixin.Postea$setPosteaCode(ChunkFixerUtility.POSTEA_UPDATE_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void runVersionedTransformers(Chunk chunk, World world, NBTTagCompound tag) {
|
||||||
|
IChunkMixin chunkMixin = (IChunkMixin) chunk;
|
||||||
|
NBTTagCompound stamps = VersionStamps.read(tag);
|
||||||
|
chunkMixin.Postea$setVersionStamps(stamps == null ? null : (NBTTagCompound) stamps.copy());
|
||||||
|
boolean blockIdsChanged = false;
|
||||||
|
for (IVersionedTransformer transformer : VersionedReplacementManager.transformers()) {
|
||||||
|
int current = transformer.currentVersion();
|
||||||
|
int stored = VersionStamps.stored(stamps, transformer.key());
|
||||||
|
if (stored == current) continue;
|
||||||
|
ChunkTransformContext ctx = new ChunkTransformContext(chunk, world, tag, stored, current);
|
||||||
|
VersionedTransformerLog.announce(transformer, stored, current);
|
||||||
|
try {
|
||||||
|
transformer.transformChunk(ctx);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new ReportedException(
|
||||||
|
describe(
|
||||||
|
t,
|
||||||
|
transformer,
|
||||||
|
stored,
|
||||||
|
current,
|
||||||
|
"Chunk",
|
||||||
|
chunk.xPosition + "," + chunk.zPosition + " in dimension " + world.provider.dimensionId));
|
||||||
|
}
|
||||||
|
chunkMixin.Postea$setVersionedDirty(true);
|
||||||
|
blockIdsChanged |= ctx.blockIdsChanged();
|
||||||
|
}
|
||||||
|
if (!blockIdsChanged) return;
|
||||||
|
// A section's block count is what decides whether it is saved at all, and writing through SubChunkAccess
|
||||||
|
// bypasses the bookkeeping ExtendedBlockStorage does in its own setters.
|
||||||
|
for (ExtendedBlockStorage section : chunk.getBlockStorageArray()) {
|
||||||
|
if (section != null) section.removeInvalidBlocks();
|
||||||
|
}
|
||||||
|
regenerateHeightMap(chunk);
|
||||||
|
chunk.isLightPopulated = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chunk.generateHeightMap is client-only and generateSkylightMap reaches into the world, so the height map is
|
||||||
|
// rebuilt here from the chunk's own storage, which is safe on the chunk I/O thread.
|
||||||
|
private static void regenerateHeightMap(Chunk chunk) {
|
||||||
|
int top = chunk.getTopFilledSegment() + 16 - 1;
|
||||||
|
chunk.heightMapMinimum = Integer.MAX_VALUE;
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
chunk.precipitationHeightMap[x + (z << 4)] = -999;
|
||||||
|
int y = top;
|
||||||
|
while (y > 0 && chunk.func_150808_b(x, y - 1, z) == 0) {
|
||||||
|
y--;
|
||||||
|
}
|
||||||
|
if (y > 0) {
|
||||||
|
chunk.heightMap[z << 4 | x] = y;
|
||||||
|
chunk.heightMapMinimum = Math.min(chunk.heightMapMinimum, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CrashReport describe(Throwable cause, IVersionedTransformer transformer, int stored, int current,
|
||||||
|
String subjectName, String subject) {
|
||||||
|
CrashReport report = CrashReport.makeCrashReport(cause, "Running versioned transformer " + transformer.key());
|
||||||
|
CrashReportCategory category = report.makeCategory("Postea versioned transformer");
|
||||||
|
category.addCrashSection("Key", transformer.key());
|
||||||
|
category.addCrashSection("Stored version", stored);
|
||||||
|
category.addCrashSection("Current version", current);
|
||||||
|
category.addCrashSection(subjectName, subject);
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onChunkLoaded(Chunk chunk) {
|
||||||
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
|
boolean stale = !hasChunkBeenUpdated(iChunkMixin.Postea$getPosteaCode());
|
||||||
|
if (stale) iChunkMixin.Postea$setPosteaCode(ChunkFixerUtility.POSTEA_UPDATE_CODE);
|
||||||
|
if (stale || iChunkMixin.Postea$isVersionedDirty()) chunk.setChunkModified();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onChunkWrite(Chunk chunk, NBTTagCompound tag) {
|
||||||
|
if (chunk instanceof IChunkMixin iChunkMixin) {
|
||||||
|
tag.setLong("POSTEA", iChunkMixin.Postea$getPosteaCode());
|
||||||
|
VersionStamps.write(tag, iChunkMixin.Postea$getVersionStamps(), VersionedReplacementManager.transformers());
|
||||||
|
iChunkMixin.Postea$setVersionedDirty(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void transformNormalBlocksInSubChunk(Chunk chunk, ExtendedBlockStorage ebs, World world) {
|
||||||
|
|
||||||
|
int chunkXPos = chunk.xPosition * 16;
|
||||||
|
int chunkZPos = chunk.zPosition * 16;
|
||||||
|
|
||||||
|
int sectionY = ebs.getYLocation();
|
||||||
|
|
||||||
|
SubChunkAccess access = Compat.getSubChunkAccess(ebs);
|
||||||
|
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
int blockId = access.getBlockId(x, y, z);
|
||||||
|
int metadata = access.getMeta(x, y, z);
|
||||||
|
|
||||||
|
// Skip air.
|
||||||
|
if (blockId == AIR_ID) continue;
|
||||||
|
|
||||||
|
BlockConversionInfo output = getBlockReplacement(
|
||||||
|
blockId,
|
||||||
|
metadata,
|
||||||
|
world,
|
||||||
|
x + chunkXPos + 1,
|
||||||
|
y + sectionY,
|
||||||
|
z + chunkZPos + 1);
|
||||||
|
|
||||||
|
if (output != null) {
|
||||||
|
access.setBlockId(x, y, z, output.blockID);
|
||||||
|
access.setMeta(x, y, z, output.metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<ConversionInfo> adjustTileEntities(NBTTagList tileEntities, World world, Chunk chunk) {
|
||||||
|
List<ConversionInfo> conversionInfo = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < tileEntities.tagCount(); i++) {
|
||||||
|
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
|
||||||
|
String tileEntityId = tileEntity.getString("id");
|
||||||
|
|
||||||
|
// Check if we have a transformer registered for this tile entity ID
|
||||||
|
for (TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformationFunction : TransformerRegistry
|
||||||
|
.getTileEntityToNormalBlockTransformerFunction(tileEntityId)) {
|
||||||
|
|
||||||
|
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) continue;
|
||||||
|
|
||||||
|
NBTTagCompound newTag;
|
||||||
|
if (blockInfo.tileTransformer != null
|
||||||
|
&& (newTag = blockInfo.tileTransformer.apply(tileEntity)) != null) {
|
||||||
|
((IMixinNBTTagList) tileEntities).Postea$replaceCompoundTagAt(i, newTag);
|
||||||
|
} else {
|
||||||
|
tileEntities.removeTag(i--);
|
||||||
|
}
|
||||||
|
|
||||||
|
conversionInfo.add(new ConversionInfo(x, y, z, blockInfo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return conversionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConversionInfo {
|
||||||
|
|
||||||
|
public final int x;
|
||||||
|
public final int y;
|
||||||
|
public final int z;
|
||||||
|
public final BlockInfo blockInfo;
|
||||||
|
|
||||||
|
public ConversionInfo(int x, int y, int z, BlockInfo blockInfo) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.blockInfo = blockInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,253 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
|
import com.gtnewhorizons.postea.Postea;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
import cpw.mods.fml.common.LoaderState;
|
||||||
|
import cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry;
|
||||||
|
import cpw.mods.fml.common.registry.GameData;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a namespaced id to the numeric ids it holds or held in the active world: the live registry id, the id
|
||||||
|
* the world's own saved map assigns it, and the ids recorded in the world's {@link WorldIdTable} for content that
|
||||||
|
* has since been removed. A retired id counts only while FML still blocks it and no live content occupies it.
|
||||||
|
*/
|
||||||
|
public abstract class IDRegistry {
|
||||||
|
|
||||||
|
// Part of a bi-map for lookups between block namespaced ids and numeric ids
|
||||||
|
private static final Object2IntOpenHashMap<String> BLOCK_NAME_TO_ID = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
|
// Part of a bi-map for lookups between item namespaced ids and numeric ids
|
||||||
|
private static final Object2IntOpenHashMap<String> ITEM_NAME_TO_ID = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
|
private static final LinkedHashMultimap<String, Consumer<Integer>> BLOCK_ID_RESOLVERS = LinkedHashMultimap.create();
|
||||||
|
private static final LinkedHashMultimap<String, Consumer<Integer>> ITEM_ID_RESOLVERS = LinkedHashMultimap.create();
|
||||||
|
|
||||||
|
private static File tableFile;
|
||||||
|
private static WorldIdTable table = new WorldIdTable();
|
||||||
|
private static IntSet blockedIds;
|
||||||
|
private static volatile boolean mappingApplied;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the retired id table of the world about to load. Until {@link #endWorld()} the saved id map is captured
|
||||||
|
* and its missing names merged into it.
|
||||||
|
*/
|
||||||
|
public static void beginWorld(File worldDirectory) {
|
||||||
|
tableFile = new File(new File(worldDirectory, Postea.MODID), WorldIdTable.FILE_NAME);
|
||||||
|
table = WorldIdTable.load(tableFile);
|
||||||
|
// A world without a level.dat has no saved id map: the live registries already are its mapping, and
|
||||||
|
// FML fires no remap event on its first session.
|
||||||
|
mappingApplied = !new File(worldDirectory, "level.dat").exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void endWorld() {
|
||||||
|
tableFile = null;
|
||||||
|
table = new WorldIdTable();
|
||||||
|
blockedIds = null;
|
||||||
|
mappingApplied = false;
|
||||||
|
BLOCK_NAME_TO_ID.clear();
|
||||||
|
ITEM_NAME_TO_ID.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether FML has applied the loading world's saved id map in this session.
|
||||||
|
*/
|
||||||
|
public static boolean isMappingApplied() {
|
||||||
|
return mappingApplied;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers all the callbacks registered by other mods that wish to identify a block that may no longer exist.
|
||||||
|
* These callbacks effectively remove the need for dummies, and should help improve performance at runtime.
|
||||||
|
*/
|
||||||
|
public static void onMappingUpdated() {
|
||||||
|
// this event is fired on server startup and shutdown. On shutdown, we just need to clear the mappings to save
|
||||||
|
// some space memory we can just ignore adding stuff safely.
|
||||||
|
if (!Loader.instance()
|
||||||
|
.isInState(LoaderState.SERVER_ABOUT_TO_START)) return;
|
||||||
|
mappingApplied = true;
|
||||||
|
for (Map.Entry<String, Collection<Consumer<Integer>>> kv : BLOCK_ID_RESOLVERS.asMap()
|
||||||
|
.entrySet()) {
|
||||||
|
int id = getBlockId(kv.getKey());
|
||||||
|
for (Consumer<Integer> resolver : kv.getValue()) {
|
||||||
|
resolver.accept(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Collection<Consumer<Integer>>> kv : ITEM_ID_RESOLVERS.asMap()
|
||||||
|
.entrySet()) {
|
||||||
|
int id = getItemId(kv.getKey());
|
||||||
|
for (Consumer<Integer> resolver : kv.getValue()) {
|
||||||
|
resolver.accept(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by {@link com.gtnewhorizons.postea.mixins.preinit.MixinGameData}, this function captures the world's
|
||||||
|
* saved name-to-id map before FML remaps the live registries onto it, and records the names no registered
|
||||||
|
* content answers to in the world's retired id table. Ignored outside a server world and off the server thread,
|
||||||
|
* since the client side of the FML handshake also injects a map.
|
||||||
|
*/
|
||||||
|
public static void registerWorldSpecificIDs(Map<String, Integer> map) {
|
||||||
|
if (tableFile == null || !FMLCommonHandler.instance()
|
||||||
|
.getEffectiveSide()
|
||||||
|
.isServer()) return;
|
||||||
|
BLOCK_NAME_TO_ID.clear();
|
||||||
|
ITEM_NAME_TO_ID.clear();
|
||||||
|
blockedIds = null;
|
||||||
|
Map<String, Integer> missing = new LinkedHashMap<>();
|
||||||
|
for (Map.Entry<String, Integer> kv : map.entrySet()) {
|
||||||
|
String name = kv.getKey()
|
||||||
|
.substring(1);
|
||||||
|
boolean block = kv.getKey()
|
||||||
|
.charAt(0) == WorldIdTable.BLOCK_PREFIX;
|
||||||
|
if (block) {
|
||||||
|
BLOCK_NAME_TO_ID.put(name, (int) kv.getValue());
|
||||||
|
} else {
|
||||||
|
ITEM_NAME_TO_ID.put(name, (int) kv.getValue());
|
||||||
|
}
|
||||||
|
FMLControlledNamespacedRegistry<?> registry = block ? GameData.getBlockRegistry()
|
||||||
|
: GameData.getItemRegistry();
|
||||||
|
if (registry.getId(name) < 0) missing.put(kv.getKey(), kv.getValue());
|
||||||
|
}
|
||||||
|
if (table.merge(missing)) table.save(tableFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The block id {@code name} currently holds in this world: the live registry id, or the id it held before its
|
||||||
|
* content was removed, or -1 when the world never mapped it.
|
||||||
|
*/
|
||||||
|
public static int getBlockId(String name) {
|
||||||
|
int id = liveBlockId(name);
|
||||||
|
if (id >= 0) return id;
|
||||||
|
IntList retired = retiredBlockIds(name, id);
|
||||||
|
return retired.isEmpty() ? -1 : retired.getInt(retired.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item id {@code name} currently holds in this world: the live registry id, or the id it held before its
|
||||||
|
* content was removed, or -1 when the world never mapped it.
|
||||||
|
*/
|
||||||
|
public static int getItemId(String name) {
|
||||||
|
int id = liveItemId(name);
|
||||||
|
if (id >= 0) return id;
|
||||||
|
IntList retired = retiredItemIds(name, id);
|
||||||
|
return retired.isEmpty() ? -1 : retired.getInt(retired.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every block id {@code name} holds or held in this world, live id first. Empty when the world never mapped
|
||||||
|
* the name.
|
||||||
|
*/
|
||||||
|
public static IntList getBlockIds(String name) {
|
||||||
|
int live = liveBlockId(name);
|
||||||
|
IntList ids = retiredBlockIds(name, live);
|
||||||
|
if (live >= 0) {
|
||||||
|
ids.add(0, live);
|
||||||
|
} else if (!ids.isEmpty()) {
|
||||||
|
Postea.LOG.info("Block {} is no longer registered; its transformers target retired id(s) {}", name, ids);
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every item id {@code name} holds or held in this world, live id first. Empty when the world never mapped
|
||||||
|
* the name.
|
||||||
|
*/
|
||||||
|
public static IntList getItemIds(String name) {
|
||||||
|
int live = liveItemId(name);
|
||||||
|
IntList ids = retiredItemIds(name, live);
|
||||||
|
if (live >= 0) {
|
||||||
|
ids.add(0, live);
|
||||||
|
} else if (!ids.isEmpty()) {
|
||||||
|
Postea.LOG.info("Item {} is no longer registered; its transformers target retired id(s) {}", name, ids);
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntList retiredBlockIds(String name, int live) {
|
||||||
|
IntList ids = new IntArrayList();
|
||||||
|
for (int id : table.blockIds(name)) {
|
||||||
|
if (id != live && blockedIds().contains(id)
|
||||||
|
&& GameData.getBlockRegistry()
|
||||||
|
.getRaw(id) == null) {
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntList retiredItemIds(String name, int live) {
|
||||||
|
IntList ids = new IntArrayList();
|
||||||
|
for (int id : table.itemIds(name)) {
|
||||||
|
if (id != live && blockedIds().contains(id)
|
||||||
|
&& GameData.getItemRegistry()
|
||||||
|
.getRaw(id) == null) {
|
||||||
|
ids.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntSet blockedIds() {
|
||||||
|
IntSet ids = blockedIds;
|
||||||
|
if (ids == null) {
|
||||||
|
ids = new IntOpenHashSet(GameData.getBlockedIds());
|
||||||
|
blockedIds = ids;
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int liveBlockId(String name) {
|
||||||
|
int id = BLOCK_NAME_TO_ID.getOrDefault(name, -1);
|
||||||
|
if (id < 0) {
|
||||||
|
id = GameData.getBlockRegistry()
|
||||||
|
.getId(name);
|
||||||
|
if (id >= 0) BLOCK_NAME_TO_ID.put(name, id);
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int liveItemId(String name) {
|
||||||
|
int id = ITEM_NAME_TO_ID.getOrDefault(name, -1);
|
||||||
|
if (id < 0) {
|
||||||
|
id = GameData.getItemRegistry()
|
||||||
|
.getId(name);
|
||||||
|
if (id >= 0) ITEM_NAME_TO_ID.put(name, id);
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback used by mods to identify the numeric ID of a namespaced ID when a world is loaded.
|
||||||
|
*
|
||||||
|
* @param name The namespaced ID to resolve.
|
||||||
|
* @param resolver The callback to call just after forge adjusts the ID mappings to prevent collisions.
|
||||||
|
*/
|
||||||
|
public static void registerBlockIDResolver(String name, Consumer<Integer> resolver) {
|
||||||
|
BLOCK_ID_RESOLVERS.put(name, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a callback used by mods to identify the numeric ID of a namespaced ID when a world is loaded.
|
||||||
|
*
|
||||||
|
* @param name The namespaced ID to resolve.
|
||||||
|
* @param resolver The callback to call just after forge adjusts the ID mappings to prevent collisions.
|
||||||
|
*/
|
||||||
|
public static void registerItemIDResolver(String name, Consumer<Integer> resolver) {
|
||||||
|
ITEM_ID_RESOLVERS.put(name, resolver);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||||
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple utility used to allow mods to register simple missing mapping migrations without having to set up a whole
|
||||||
|
* system themselves.
|
||||||
|
*/
|
||||||
|
public abstract class MissingMappingHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of String IDs that can safely be ignored.
|
||||||
|
*/
|
||||||
|
private static final Set<String> MISSING_IDS_TO_IGNORE = new ObjectOpenHashSet<>();
|
||||||
|
/**
|
||||||
|
* A set of string IDs and items they should map to.
|
||||||
|
*/
|
||||||
|
private static final Map<String, Item> MISSING_ITEM_MAPPINGS = new Object2ObjectOpenHashMap<>();
|
||||||
|
/**
|
||||||
|
* A set of string IDs and items they should map to.
|
||||||
|
*/
|
||||||
|
private static final Map<String, Block> MISSING_BLOCK_MAPPINGS = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
// region FML Life Cycle handlers
|
||||||
|
public static void onMissingMapping(FMLMissingMappingsEvent event) {
|
||||||
|
for (FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()) {
|
||||||
|
// ignore things that can be ignored safely, and our own dummy items for when a handler is removed.
|
||||||
|
if (MISSING_IDS_TO_IGNORE.contains(mapping.name)) {
|
||||||
|
mapping.ignore();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.type == GameRegistry.Type.BLOCK) {
|
||||||
|
Block remappedBlock = MISSING_BLOCK_MAPPINGS.get(mapping.name);
|
||||||
|
if (remappedBlock != null) {
|
||||||
|
mapping.remap(remappedBlock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (mapping.type == GameRegistry.Type.ITEM) {
|
||||||
|
Block remappedBlock = MISSING_BLOCK_MAPPINGS.get(mapping.name);
|
||||||
|
if (remappedBlock != null) {
|
||||||
|
mapping.remap(Item.getItemFromBlock(remappedBlock));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Item remappedItem = MISSING_ITEM_MAPPINGS.get(mapping.name);
|
||||||
|
if (remappedItem != null) {
|
||||||
|
mapping.remap(MISSING_ITEM_MAPPINGS.get(mapping.name));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion FML Life Cycle handlers
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a direct mapping for a missing item mapping.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced id of the missing item.
|
||||||
|
* @param item The item it should be replaced with.
|
||||||
|
*/
|
||||||
|
public static void addItemMapping(String originalId, Item item) {
|
||||||
|
MISSING_ITEM_MAPPINGS.put(originalId, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a direct mapping for a missing block mapping.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced id of the missing block.
|
||||||
|
* @param block The block it should be replaced with.
|
||||||
|
*/
|
||||||
|
public static void addBlockMapping(String originalId, Block block) {
|
||||||
|
MISSING_BLOCK_MAPPINGS.put(originalId, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a notice that FML should silence any warning when loading a world telling the player that an ID
|
||||||
|
* is now missing.
|
||||||
|
*
|
||||||
|
* @param originalId The namespace ID to ignore.
|
||||||
|
*/
|
||||||
|
public static void addIgnore(String originalId) {
|
||||||
|
MISSING_IDS_TO_IGNORE.add(originalId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_ANY_NUMERIC;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_SHORT;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_STRING;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTBase;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Visits every serialized item stack in an NBT tree. A compound is a stack when it has a numeric {@code id} or an
|
||||||
|
* EndlessIDs {@code idExt} together with a {@code Count}; in string-id mode a string {@code id} (a registry name,
|
||||||
|
* as quest databases store) also qualifies. String-id mode must not be used on chunk or player trees, where tile
|
||||||
|
* entity compounds carry a string {@code id} of their own. The walk is pre-order and descends into every compound
|
||||||
|
* and every list of compounds, so stacks nested inside another stack's {@code tag} (backpacks, storage cells) are
|
||||||
|
* visited too. Lists of lists are not descended. A visitor may change or remove keys of the stack it is given; it
|
||||||
|
* must not touch other parts of the tree.
|
||||||
|
*/
|
||||||
|
public final class NbtItemStacks {
|
||||||
|
|
||||||
|
private NbtItemStacks() {}
|
||||||
|
|
||||||
|
public static void forEach(NBTBase root, Consumer<NBTTagCompound> visitor) {
|
||||||
|
forEach(root, visitor, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void forEach(NBTBase root, Consumer<NBTTagCompound> visitor, boolean stringIds) {
|
||||||
|
if (root instanceof NBTTagCompound compound) {
|
||||||
|
if (isStack(compound, stringIds)) visitor.accept(compound);
|
||||||
|
for (Object key : compound.func_150296_c()) {
|
||||||
|
forEach(compound.getTag((String) key), visitor, stringIds);
|
||||||
|
}
|
||||||
|
} else if (root instanceof NBTTagList list && list.func_150303_d() == TAG_COMPOUND) {
|
||||||
|
for (int i = 0; i < list.tagCount(); i++) {
|
||||||
|
forEach(list.getCompoundTagAt(i), visitor, stringIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isStack(NBTTagCompound compound) {
|
||||||
|
return isStack(compound, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isStack(NBTTagCompound compound, boolean stringIds) {
|
||||||
|
return compound.hasKey("Count", TAG_ANY_NUMERIC)
|
||||||
|
&& (compound.hasKey("id", TAG_SHORT) || compound.hasKey("id", TAG_INT)
|
||||||
|
|| compound.hasKey("idExt", TAG_INT)
|
||||||
|
|| (stringIds && compound.hasKey("id", TAG_STRING)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_LIST;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
public final class NbtLists {
|
||||||
|
|
||||||
|
private NbtLists() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of compounds stored under {@code key}, attached to {@code parent} first when absent so that tags
|
||||||
|
* appended to it are part of {@code parent}.
|
||||||
|
*/
|
||||||
|
public static NBTTagList compoundList(NBTTagCompound parent, String key) {
|
||||||
|
if (!parent.hasKey(key, TAG_LIST)) parent.setTag(key, new NBTTagList());
|
||||||
|
return parent.getTagList(key, TAG_COMPOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.ReportedException;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
import com.gtnewhorizons.postea.api.PlayerDataTransformContext;
|
||||||
|
import com.gtnewhorizons.postea.api.VersionedReplacementManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs versioned transformers over a server player's NBT as it is read, and stamps it as it is written. Hooked on
|
||||||
|
* {@code Entity.readFromNBT}/{@code writeToNBT} so both the {@code playerdata/<uuid>.dat} files and the
|
||||||
|
* single-player host's copy inside {@code level.dat} are covered.
|
||||||
|
*/
|
||||||
|
public final class PlayerDataFixerUtility {
|
||||||
|
|
||||||
|
private PlayerDataFixerUtility() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code tag} in place and returns a copy of the stamps it carried (null when unstamped).
|
||||||
|
*/
|
||||||
|
public static NBTTagCompound onPlayerRead(EntityPlayerMP player, NBTTagCompound tag) {
|
||||||
|
NBTTagCompound stamps = VersionStamps.read(tag);
|
||||||
|
for (IVersionedTransformer transformer : VersionedReplacementManager.transformers()) {
|
||||||
|
int current = transformer.currentVersion();
|
||||||
|
int stored = VersionStamps.stored(stamps, transformer.key());
|
||||||
|
if (stored == current) continue;
|
||||||
|
VersionedTransformerLog.announce(transformer, stored, current);
|
||||||
|
try {
|
||||||
|
transformer.transformPlayer(new PlayerDataTransformContext(player, tag, stored, current));
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new ReportedException(
|
||||||
|
ChunkFixerUtility.describe(
|
||||||
|
t,
|
||||||
|
transformer,
|
||||||
|
stored,
|
||||||
|
current,
|
||||||
|
"Player",
|
||||||
|
player.getCommandSenderName() + " (" + player.getUniqueID() + ")"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stamps == null ? null : (NBTTagCompound) stamps.copy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onPlayerWrite(NBTTagCompound tag, NBTTagCompound carried) {
|
||||||
|
VersionStamps.write(tag, carried, VersionedReplacementManager.transformers());
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-1
@@ -1,8 +1,9 @@
|
|||||||
package com.colen.postea.Utility;
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import net.minecraft.launchwrapper.Launch;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
@@ -30,6 +31,9 @@ public abstract class PosteaUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getModListHash() {
|
public static int getModListHash() {
|
||||||
|
// when in a dev env allow mutations to happen every time a chunk is loaded for testing purposes.
|
||||||
|
final Object deobfEnv = Launch.blackboard != null ? Launch.blackboard.get("fml.deobfuscatedEnvironment") : null;
|
||||||
|
if (deobfEnv != null && (boolean) deobfEnv) return -1;
|
||||||
|
|
||||||
// We iterate over every mod, get its version and put it into a giant list.
|
// We iterate over every mod, get its version and put it into a giant list.
|
||||||
// This is done so we can see if our mods have actually changed, if so, we
|
// This is done so we can see if our mods have actually changed, if so, we
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple mapping registry for quick access to simple transformations.<br>
|
||||||
|
* <br>
|
||||||
|
* It's essentially a 2 layer map.
|
||||||
|
* The first layer contains the namespaced ID of the thing that needs to be replaced.
|
||||||
|
* The second layer contains mappings for each meta/damage value of the namespaced ID.<br>
|
||||||
|
* <br>
|
||||||
|
* When registering something to the second/meta layer, Using {@link OreDictionary#WILDCARD_VALUE}
|
||||||
|
* will register a fallback for all meta/damage value of the namespaced ID.<br>
|
||||||
|
* <br>
|
||||||
|
* Here is an example of the typical structure of this map
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* ┌─ mod:name_one ─┬─ 1 -> {Stone, 0} : Transforms all mod:name_one with meta 1 into stone with meta 0
|
||||||
|
* │ └─ wildcard -> {Plank, Wildcard} : Transforms all other mod:name_one to planks of the same meta.
|
||||||
|
* │
|
||||||
|
* ├─ mod:name_two ─── 2 -> {Clay, 0} : transforms all mod:name_two with meta 2 to clay with meta 0
|
||||||
|
* │
|
||||||
|
* └─ mod:name_three ─┬─ 0 -> {Air, 0} : transforms all mod:name_three with meta 0 to air with meta 0
|
||||||
|
* ├─ 1 -> {Sand, 1} : transforms all mod:name_three with meta 1 to sand with meta 1
|
||||||
|
* └─ 5 -> {SandStone, Wildcard} : transforms all mod:name_three to sandstone with the same meta.
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param <T> Either {@link net.minecraft.block.Block} or {@link net.minecraft.item.Item}
|
||||||
|
*/
|
||||||
|
class SimpleTransformationMap<T> {
|
||||||
|
|
||||||
|
public static class Value<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The target block or item for the simple transformation
|
||||||
|
*/
|
||||||
|
public final T target;
|
||||||
|
/**
|
||||||
|
* The target meta/damage value for the transformation.
|
||||||
|
* If the value is {@link OreDictionary#WILDCARD_VALUE}, It maintains the old meta/damage value.
|
||||||
|
*/
|
||||||
|
public final int targetMeta;
|
||||||
|
/**
|
||||||
|
* The numeric id of the target block, updated during the FMLMappingUpdate event
|
||||||
|
*/
|
||||||
|
public int targetRuntimeId;
|
||||||
|
|
||||||
|
public Value(T target, int targetMeta) {
|
||||||
|
this.target = target;
|
||||||
|
this.targetMeta = targetMeta;
|
||||||
|
this.targetRuntimeId = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<String, Map<Integer, Value<T>>> registry = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Puts a mapping in this registry.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced ID of the item or block to replace.
|
||||||
|
* @param originalMeta The meta or damage value of the item or block to replace.
|
||||||
|
* {@link OreDictionary#WILDCARD_VALUE} can be used as a wildcard/fallback value.
|
||||||
|
* When querying, the value will be replaced, which will
|
||||||
|
* be used when ever no other specific meta match is found.
|
||||||
|
*/
|
||||||
|
public void put(String originalId, int originalMeta, T target, int targetMeta) {
|
||||||
|
if (originalMeta == -1) originalMeta = OreDictionary.WILDCARD_VALUE;
|
||||||
|
this.registry.computeIfAbsent(originalId, k -> new Int2ObjectOpenHashMap<>())
|
||||||
|
.put(originalMeta, new Value<>(target, targetMeta));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to query sub-maps at runtime since we capture the relevant sub-map into the transformation handler that is
|
||||||
|
* registered for simple transformations. This allows us to not re-query the first layer of this map while
|
||||||
|
* performing simple transformations, which should hopefully increase performance.
|
||||||
|
*
|
||||||
|
* @param subMap The sub-map to query.
|
||||||
|
* @param meta The meta/damage value of the block/item being transformed.
|
||||||
|
* @return The mapping if found, else null.
|
||||||
|
* @param <T> The type of the sub-map,
|
||||||
|
*/
|
||||||
|
public static <T> @Nullable Value<T> getFromSubMap(Map<Integer, Value<T>> subMap, int meta) {
|
||||||
|
Value<T> mapping = subMap.get(meta);
|
||||||
|
if (mapping != null) return mapping;
|
||||||
|
return subMap.get(OreDictionary.WILDCARD_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to update runtime IDs during the MappingUpdate event.
|
||||||
|
*
|
||||||
|
* @return The set of all registered item ids
|
||||||
|
*/
|
||||||
|
public Set<Map.Entry<String, Map<Integer, Value<T>>>> entrySet() {
|
||||||
|
return this.registry.entrySet();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
|
||||||
|
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.
|
||||||
|
* When replacing one mod with another in GTNH, we have to migrate most if not all the mod's items and this often means
|
||||||
|
* having to migrate almost every block and item from the original mod.
|
||||||
|
* <hr>
|
||||||
|
* If a mod uses metas to differentiate items (eg: GT5u) that will end up being migrated to separate items, this would
|
||||||
|
* usually result in potentially multiple handlers per item if they are destined to be split into separate mods,
|
||||||
|
* which increases the execution time linearly. The simple transformations uses a better algorithm for these
|
||||||
|
* which is executed in constant time regardless of how many transformations have been assigned to a given id. (mostly
|
||||||
|
* at the cost of higher memory usage due to caching)
|
||||||
|
*/
|
||||||
|
public class SimpleTransformationRegistry {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores simple block transformations (eg: if old id is # with meta # then turn into item with id # with meta #.)
|
||||||
|
*/
|
||||||
|
private static final SimpleTransformationMap<Block> SIMPLE_BLOCK_TRANSFORMATION_MAP = new SimpleTransformationMap<>();
|
||||||
|
/**
|
||||||
|
* Stores simple item transformations (eg: if old id is # with meta # then turn into item with id # with meta #.)
|
||||||
|
*/
|
||||||
|
private static final SimpleTransformationMap<Item> SIMPLE_ITEM_TRANSFORMATION_MAP = new SimpleTransformationMap<>();
|
||||||
|
|
||||||
|
// region FML Life Cycle handlers
|
||||||
|
/**
|
||||||
|
* Registers 1 handler per targeted ID to minimize the number of handlers. The meta-map is captured to reduce
|
||||||
|
* the execution time of the handlers. This is done at the load completed to hopefully always register these
|
||||||
|
* handlers last, allowing all other user made transformers to execute first.
|
||||||
|
*/
|
||||||
|
public static void onLoadCompleted() {
|
||||||
|
// add handlers for simple block remaps
|
||||||
|
for (Map.Entry<String, Map<Integer, SimpleTransformationMap.Value<Block>>> kv : SIMPLE_BLOCK_TRANSFORMATION_MAP
|
||||||
|
.entrySet()) {
|
||||||
|
TransformerRegistry.addBlockTransformer(kv.getKey(), new SimpleBlockTransformationHandler(kv.getValue()));
|
||||||
|
}
|
||||||
|
// add handlers for simple item remaps
|
||||||
|
for (Map.Entry<String, Map<Integer, SimpleTransformationMap.Value<Item>>> kv : SIMPLE_ITEM_TRANSFORMATION_MAP
|
||||||
|
.entrySet()) {
|
||||||
|
TransformerRegistry.addStackTransformer(kv.getKey(), new SimpleItemTransformationHandler(kv.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-caches updated block and item numeric IDs for any simple transformation to speed up the handlers.
|
||||||
|
*/
|
||||||
|
public static void onIdMappingsChanged() {
|
||||||
|
for (Map.Entry<String, Map<Integer, SimpleTransformationMap.Value<Block>>> kv : SIMPLE_BLOCK_TRANSFORMATION_MAP
|
||||||
|
.entrySet()) {
|
||||||
|
for (SimpleTransformationMap.Value<Block> mapping : kv.getValue()
|
||||||
|
.values()) {
|
||||||
|
mapping.targetRuntimeId = Block.getIdFromBlock(mapping.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Map<Integer, SimpleTransformationMap.Value<Item>>> kv : SIMPLE_ITEM_TRANSFORMATION_MAP
|
||||||
|
.entrySet()) {
|
||||||
|
for (SimpleTransformationMap.Value<Item> mapping : kv.getValue()
|
||||||
|
.values()) {
|
||||||
|
mapping.targetRuntimeId = Item.getIdFromItem(mapping.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion FML Life Cycle handlers
|
||||||
|
|
||||||
|
// region block transformations
|
||||||
|
/**
|
||||||
|
* Registers a simple Block transformation for a simple 1:1 transformation:
|
||||||
|
* <ul>
|
||||||
|
* <li>block -> block (with same meta)</li>
|
||||||
|
* <li>block -> block with specific meta</li>
|
||||||
|
* <li>block with meta -> block (with same meta)</li>
|
||||||
|
* <li>block with meta -> block with specific meta</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @implNote With these simple transformers, it doesn't matter how many transformations are registered to a single
|
||||||
|
* id, only a single handler will be registered per id during the FMLLoadCompleted event. Replacements
|
||||||
|
* are by using hash-table lookups so the execution of the transformation should be constant-time
|
||||||
|
* regardless of how many handlers were registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The original namespaced id of the block to replace.
|
||||||
|
* @param originalMeta The meta value of the block to replace. OreDictionary.WILDCARD_VALUE acts as a wildcard
|
||||||
|
* and fallback if there isn't simple transformation registered for a given meta.
|
||||||
|
* @param newBlock What block to replace with.
|
||||||
|
* @param newMeta The meta value of the transformed block. OreDictionary.WILDCARD_VALUE preserves the
|
||||||
|
* existing value.
|
||||||
|
* @param skipStackRemap Set to true to skip registering an identical simple item transformation.
|
||||||
|
*/
|
||||||
|
public static void addSimpleTransformer(String originalId, int originalMeta, Block newBlock, int newMeta,
|
||||||
|
boolean skipStackRemap) {
|
||||||
|
if (newMeta == -1) newMeta = OreDictionary.WILDCARD_VALUE;
|
||||||
|
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, newBlock, newMeta);
|
||||||
|
if (!skipStackRemap) {
|
||||||
|
Item item = Item.getItemFromBlock(newBlock);
|
||||||
|
if (item != null) {
|
||||||
|
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, item, newMeta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The handler for the simple block transformation.
|
||||||
|
*
|
||||||
|
* @implNote This implementation has constant-time runtime.
|
||||||
|
*/
|
||||||
|
private static class SimpleBlockTransformationHandler implements IBlockTransformationHandler {
|
||||||
|
|
||||||
|
private final Map<Integer, SimpleTransformationMap.Value<Block>> metaMap;
|
||||||
|
|
||||||
|
SimpleBlockTransformationHandler(Map<Integer, SimpleTransformationMap.Value<Block>> metaMap) {
|
||||||
|
this.metaMap = metaMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(BlockConversionInfo info) {
|
||||||
|
SimpleTransformationMap.Value<Block> mapping = SimpleTransformationMap
|
||||||
|
.getFromSubMap(metaMap, info.metadata);
|
||||||
|
if (mapping == null || mapping.targetRuntimeId <= -1) return false;
|
||||||
|
info.blockID = mapping.targetRuntimeId;
|
||||||
|
if (mapping.targetMeta != OreDictionary.WILDCARD_VALUE) {
|
||||||
|
info.metadata = mapping.targetMeta;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion block transformations
|
||||||
|
|
||||||
|
// region item transformations
|
||||||
|
/**
|
||||||
|
* Registers a simple Block transformation for a simple 1:1 transformation:
|
||||||
|
* <ul>
|
||||||
|
* <li>item -> item (with same meta)</li>
|
||||||
|
* <li>item -> item with specific meta</li>
|
||||||
|
* <li>item with meta/damage -> item (with same meta/damage)</li>
|
||||||
|
* <li>item with meta/damage -> item with specific meta/damage</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @implNote With these simple transformers, it doesn't matter how many transformations are registered to a single
|
||||||
|
* id, only a single handler will be registered per id during the FMLLoadCompleted event. Replacements
|
||||||
|
* are by using hash-table lookups so the execution of the transformation should be constant-time
|
||||||
|
* regardless of how many handlers were registered to a single id.
|
||||||
|
*
|
||||||
|
* @param originalId The original namespaced id of the item to replace.
|
||||||
|
* @param originalMeta The meta/damage value of the item to replace. OreDictionary.WILDCARD_VALUE acts as a
|
||||||
|
* wildcard
|
||||||
|
* and fallback if there isn't simple transformation registered for a given meta.
|
||||||
|
* @param newItem What item to replace with.
|
||||||
|
* @param newMeta The meta/damage value of the transformed item. OreDictionary.WILDCARD_VALUE preserves the
|
||||||
|
* existing
|
||||||
|
* value.
|
||||||
|
* @param skipBlockRemap Set to true to skip registering an identical block transformation if the item is an
|
||||||
|
* ItemBlock.
|
||||||
|
*/
|
||||||
|
public static void addSimpleTransformer(String originalId, int originalMeta, Item newItem, int newMeta,
|
||||||
|
boolean skipBlockRemap) {
|
||||||
|
if (newMeta == -1) newMeta = OreDictionary.WILDCARD_VALUE;
|
||||||
|
if (!skipBlockRemap && newItem instanceof ItemBlock ib) {
|
||||||
|
SIMPLE_BLOCK_TRANSFORMATION_MAP.put(originalId, originalMeta, ib.field_150939_a, newMeta);
|
||||||
|
}
|
||||||
|
SIMPLE_ITEM_TRANSFORMATION_MAP.put(originalId, originalMeta, newItem, newMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The handler for the simple item transformation.
|
||||||
|
*
|
||||||
|
* @implNote This implementation has constant-time runtime.
|
||||||
|
*/
|
||||||
|
private static class SimpleItemTransformationHandler implements IItemStackTransformationHandler {
|
||||||
|
|
||||||
|
private final Map<Integer, SimpleTransformationMap.Value<Item>> metaMap;
|
||||||
|
|
||||||
|
SimpleItemTransformationHandler(Map<Integer, SimpleTransformationMap.Value<Item>> metaMap) {
|
||||||
|
this.metaMap = metaMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean apply(String originalId, NBTTagCompound tag) {
|
||||||
|
short meta = tag.getShort("Damage");
|
||||||
|
SimpleTransformationMap.Value<Item> mapping = SimpleTransformationMap.getFromSubMap(metaMap, meta);
|
||||||
|
if (mapping == null || mapping.targetRuntimeId <= -1) return false;
|
||||||
|
IDExtenderCompat.setItemStackID(tag, mapping.targetRuntimeId);
|
||||||
|
if (mapping.targetMeta != OreDictionary.WILDCARD_VALUE) {
|
||||||
|
// Damage is a vanilla short NBT field, unrelated to EndlessIDs block metadata width.
|
||||||
|
tag.setShort("Damage", (short) mapping.targetMeta);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion item transformations
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
|
import com.gtnewhorizons.postea.Postea;
|
||||||
|
import com.gtnewhorizons.postea.api.BlockNameAndMeta;
|
||||||
|
import com.gtnewhorizons.postea.api.IBlockTransformationHandler;
|
||||||
|
import com.gtnewhorizons.postea.api.IDExtenderCompat;
|
||||||
|
import com.gtnewhorizons.postea.api.IItemStackTransformationHandler;
|
||||||
|
import com.gtnewhorizons.postea.api.TriFunction;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
|
import cpw.mods.fml.common.LoaderState;
|
||||||
|
import cpw.mods.fml.common.registry.GameData;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A registry for all transformer functions
|
||||||
|
*/
|
||||||
|
public class TransformerRegistry {
|
||||||
|
|
||||||
|
private static final LinkedListMultimap<String, IItemStackTransformationHandler> ITEM_REPLACEMENT_MAP = LinkedListMultimap
|
||||||
|
.create();
|
||||||
|
public static final LinkedListMultimap<String, IBlockTransformationHandler> BLOCK_REPLACEMENT_MAP = LinkedListMultimap
|
||||||
|
.create();
|
||||||
|
private static final LinkedListMultimap<String, TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> TILE_ENTITY_REPLACEMENT_MAP = LinkedListMultimap
|
||||||
|
.create();
|
||||||
|
/**
|
||||||
|
* Map of itemID -> originalName+transformationHandler.
|
||||||
|
* 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. An id carries several names when
|
||||||
|
* content that once held it has been removed.
|
||||||
|
*/
|
||||||
|
private static final Int2ObjectOpenHashMap<List<Pair<String, List<IItemStackTransformationHandler>>>> RUNTIME_ITEM_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||||
|
/**
|
||||||
|
* Map of blockID -> originalName+transformationHandler.
|
||||||
|
* 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. An id carries several names when
|
||||||
|
* content that once held it has been removed.
|
||||||
|
*/
|
||||||
|
private static final Int2ObjectOpenHashMap<List<Pair<String, List<IBlockTransformationHandler>>>> RUNTIME_BLOCK_REPLACEMENT_MAP = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
// region FML Life Cycle handlers
|
||||||
|
/**
|
||||||
|
* When FML loads a world, it remaps certain IDs if the IDs it registered during the load period do not match the
|
||||||
|
* IDs that were previously registered when the world was last loaded.
|
||||||
|
* <br>
|
||||||
|
* We use this opportunity to fetch the "world specific" IDs of all the blocks and items that have a
|
||||||
|
* transformation registered to them so we can pivot using the numeric IDs when we're doing replacements.
|
||||||
|
* <br>
|
||||||
|
* This is because pivoting on the numeric ids is significantly faster than pivoting on string or object hashes.
|
||||||
|
*/
|
||||||
|
public static void onIdMappingsChanged() {
|
||||||
|
RUNTIME_BLOCK_REPLACEMENT_MAP.clear();
|
||||||
|
RUNTIME_ITEM_REPLACEMENT_MAP.clear();
|
||||||
|
// this event is fired on server startup and shutdown. On shutdown, we just need to clear the mappings to save
|
||||||
|
// some space memory we can just ignore adding stuff safely.
|
||||||
|
if (!Loader.instance()
|
||||||
|
.isInState(LoaderState.SERVER_ABOUT_TO_START)) return;
|
||||||
|
// create a lookup for source block ids.
|
||||||
|
for (String key : BLOCK_REPLACEMENT_MAP.keySet()) {
|
||||||
|
IntList ids = IDRegistry.getBlockIds(key);
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
Postea.LOG.debug("Block {} has no id in this world; its transformers stay inactive", key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int id : ids) {
|
||||||
|
RUNTIME_BLOCK_REPLACEMENT_MAP.computeIfAbsent(id, unused -> new ArrayList<>())
|
||||||
|
.add(Pair.of(key, BLOCK_REPLACEMENT_MAP.get(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// create a lookup for source item ids.
|
||||||
|
for (String key : ITEM_REPLACEMENT_MAP.keySet()) {
|
||||||
|
IntList ids = IDRegistry.getItemIds(key);
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
Postea.LOG.debug("Item {} has no id in this world; its transformers stay inactive", key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int id : ids) {
|
||||||
|
RUNTIME_ITEM_REPLACEMENT_MAP.computeIfAbsent(id, unused -> new ArrayList<>())
|
||||||
|
.add(Pair.of(key, ITEM_REPLACEMENT_MAP.get(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// endregion FML Life Cycle handlers
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a block transformation handler function for the given id.
|
||||||
|
*
|
||||||
|
* @implNote The id may name content that no longer exists: Postea resolves it through the world's saved id map
|
||||||
|
* and its retired-id table, so the handler runs on every numeric id the content held in this world.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced id of the block to transform.
|
||||||
|
* @param transformer The transformation handler that will execute a transformation on the block.
|
||||||
|
*/
|
||||||
|
public static void addBlockTransformer(@Nonnull String originalId,
|
||||||
|
@Nonnull IBlockTransformationHandler transformer) {
|
||||||
|
BLOCK_REPLACEMENT_MAP.put(originalId, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers an item transformation handler function for the given id.
|
||||||
|
*
|
||||||
|
* @implNote The id may name content that no longer exists: Postea resolves it through the world's saved id map
|
||||||
|
* and its retired-id table, so the handler runs on every numeric id the content held in this world.
|
||||||
|
*
|
||||||
|
* @param originalId The namespaced id of the item to transform.
|
||||||
|
* @param transformer The transformation handler that will execute a transformation on the stack.
|
||||||
|
*/
|
||||||
|
public static void addStackTransformer(@Nonnull String originalId,
|
||||||
|
@Nonnull IItemStackTransformationHandler transformer) {
|
||||||
|
ITEM_REPLACEMENT_MAP.put(originalId, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a tile entity transformation handler function for the given id.
|
||||||
|
*
|
||||||
|
* @implNote Keyed by the tile entity's saved {@code id}; handlers run in registration order until one returns a
|
||||||
|
* non-null {@link BlockInfo}.
|
||||||
|
*
|
||||||
|
* @param originalId The saved id of the tile entity to transform.
|
||||||
|
* @param transformer The transformation handler that will execute a transformation on the tile entity.
|
||||||
|
*/
|
||||||
|
public static void addTileEntityTransformer(@Nonnull String originalId,
|
||||||
|
@Nonnull TriFunction<NBTTagCompound, World, Chunk, BlockInfo> transformer) {
|
||||||
|
TILE_ENTITY_REPLACEMENT_MAP.put(originalId, transformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// region transformation handlers
|
||||||
|
public static @Nullable BlockConversionInfo getBlockReplacement(int blockId, int metadata, World world, int x,
|
||||||
|
int y, int z) {
|
||||||
|
List<Pair<String, List<IBlockTransformationHandler>>> candidates = RUNTIME_BLOCK_REPLACEMENT_MAP.get(blockId);
|
||||||
|
if (candidates == null) return null;
|
||||||
|
for (Pair<String, List<IBlockTransformationHandler>> data : candidates) {
|
||||||
|
BlockConversionInfo info = new BlockConversionInfo(data.getKey(), blockId, metadata, x, y, z, world);
|
||||||
|
for (IBlockTransformationHandler transformer : data.getValue()) {
|
||||||
|
if (transformer.apply(info)) return info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable BlockNameAndMeta transformBlock(@Nonnull String name, int metadata) {
|
||||||
|
List<IBlockTransformationHandler> handlers = BLOCK_REPLACEMENT_MAP.get(name);
|
||||||
|
if (handlers.isEmpty()) return null;
|
||||||
|
// there is no position nor world, the block isn't placed anywhere
|
||||||
|
BlockConversionInfo blockConversionInfo = new BlockConversionInfo(
|
||||||
|
name,
|
||||||
|
IDRegistry.getBlockId(name),
|
||||||
|
metadata,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
null);
|
||||||
|
for (IBlockTransformationHandler transformer : handlers) {
|
||||||
|
if (transformer.apply(blockConversionInfo)) {
|
||||||
|
Block block = GameData.getBlockRegistry()
|
||||||
|
.getRaw(blockConversionInfo.blockID);
|
||||||
|
if (block == null) return null;
|
||||||
|
return new BlockNameAndMeta(
|
||||||
|
GameData.getBlockRegistry()
|
||||||
|
.getNameForObject(block),
|
||||||
|
blockConversionInfo.metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void transformItem(NBTTagCompound tag) {
|
||||||
|
// abort early if tag is bad.
|
||||||
|
if (tag.hasNoTags() || !tag.hasKey("id")) return;
|
||||||
|
List<Pair<String, List<IItemStackTransformationHandler>>> candidates = RUNTIME_ITEM_REPLACEMENT_MAP
|
||||||
|
.get(IDExtenderCompat.getItemStackID(tag));
|
||||||
|
if (candidates == null) return;
|
||||||
|
for (Pair<String, List<IItemStackTransformationHandler>> data : candidates) {
|
||||||
|
for (IItemStackTransformationHandler transformer : data.getValue()) {
|
||||||
|
if (transformer.apply(data.getKey(), tag)) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<TriFunction<NBTTagCompound, World, Chunk, BlockInfo>> getTileEntityToNormalBlockTransformerFunction(
|
||||||
|
String tileEntityId) {
|
||||||
|
return TILE_ENTITY_REPLACEMENT_MAP.get(tileEntityId);
|
||||||
|
}
|
||||||
|
// endregion transformation handlers
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
|
||||||
|
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@code POSTEA_VERSIONS} compound Postea keeps on data handled by {@link IVersionedTransformer}s, one
|
||||||
|
* int per registered transformer key. Keys of transformers that are not registered in the running session are
|
||||||
|
* carried through unchanged so a mod that is temporarily absent does not lose its stamps.
|
||||||
|
*/
|
||||||
|
public final class VersionStamps {
|
||||||
|
|
||||||
|
public static final String KEY = "POSTEA_VERSIONS";
|
||||||
|
public static final int UNSTAMPED = -1;
|
||||||
|
|
||||||
|
private VersionStamps() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stamps stored on {@code container}, or null when it carries none.
|
||||||
|
*/
|
||||||
|
public static NBTTagCompound read(NBTTagCompound container) {
|
||||||
|
return container.hasKey(KEY, TAG_COMPOUND) ? container.getCompoundTag(KEY) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version stored for {@code key} in {@code stamps} (which may be null), or {@link #UNSTAMPED}.
|
||||||
|
*/
|
||||||
|
public static int stored(NBTTagCompound stamps, String key) {
|
||||||
|
return stamps != null && stamps.hasKey(key, TAG_INT) ? stamps.getInteger(key) : UNSTAMPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the stamps onto {@code container}: {@code carried} (the stamps the data was read with, or null) with
|
||||||
|
* every registered transformer's key set to its current version.
|
||||||
|
*/
|
||||||
|
public static void write(NBTTagCompound container, NBTTagCompound carried,
|
||||||
|
Iterable<IVersionedTransformer> transformers) {
|
||||||
|
NBTTagCompound stamps = carried == null ? new NBTTagCompound() : (NBTTagCompound) carried.copy();
|
||||||
|
for (IVersionedTransformer transformer : transformers) {
|
||||||
|
stamps.setInteger(transformer.key(), transformer.currentVersion());
|
||||||
|
}
|
||||||
|
container.setTag(KEY, stamps);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.Postea;
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Announces each version span a transformer is bringing data across once per world, instead of once per chunk.
|
||||||
|
*/
|
||||||
|
public final class VersionedTransformerLog {
|
||||||
|
|
||||||
|
private static final Set<String> ANNOUNCED = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
|
private VersionedTransformerLog() {}
|
||||||
|
|
||||||
|
public static void announce(IVersionedTransformer transformer, int stored, int current) {
|
||||||
|
if (ANNOUNCED.add(transformer.key() + ' ' + stored + ' ' + current)) {
|
||||||
|
Postea.LOG.info(
|
||||||
|
"{} is bringing saved data from version {} to {}",
|
||||||
|
transformer.key(),
|
||||||
|
stored == VersionStamps.UNSTAMPED ? "unstamped" : String.valueOf(stored),
|
||||||
|
current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clear() {
|
||||||
|
ANNOUNCED.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntLists;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Every namespaced block and item name whose content was missing when a world loaded, with every id it held,
|
||||||
|
* oldest first. FML drops a missing name from {@code level.dat} on the first save after its content disappears;
|
||||||
|
* this table keeps the name so transformers keyed on it keep resolving in later sessions. Persisted as
|
||||||
|
* {@code <world>/postea/known-ids.json}, format version 1:
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
* { "version": 1, "blocks": { "mod:block": [300, 301] }, "items": { "mod:item": [4200] } }
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public final class WorldIdTable {
|
||||||
|
|
||||||
|
static final String FILE_NAME = "known-ids.json";
|
||||||
|
/** FML prefixes block names with this character in a saved id map; items get U+0002. */
|
||||||
|
static final char BLOCK_PREFIX = 1;
|
||||||
|
private static final int FORMAT_VERSION = 1;
|
||||||
|
|
||||||
|
private final Map<String, IntList> blocks = new TreeMap<>();
|
||||||
|
private final Map<String, IntList> items = new TreeMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads {@code file}; an absent file yields an empty table. Throws {@link IllegalStateException} on a file that
|
||||||
|
* cannot be read or parsed.
|
||||||
|
*/
|
||||||
|
public static WorldIdTable load(File file) {
|
||||||
|
WorldIdTable table = new WorldIdTable();
|
||||||
|
if (!file.exists()) return table;
|
||||||
|
try {
|
||||||
|
JsonObject root = new JsonParser()
|
||||||
|
.parse(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8))
|
||||||
|
.getAsJsonObject();
|
||||||
|
if (root.get("version")
|
||||||
|
.getAsInt() != FORMAT_VERSION) {
|
||||||
|
throw new IllegalStateException(file + " has an unsupported format version");
|
||||||
|
}
|
||||||
|
read(root.getAsJsonObject("blocks"), table.blocks);
|
||||||
|
read(root.getAsJsonObject("items"), table.items);
|
||||||
|
} catch (IOException | RuntimeException e) {
|
||||||
|
throw new IllegalStateException("Cannot read the retired id table " + file, e);
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void read(JsonObject object, Map<String, IntList> into) {
|
||||||
|
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
|
||||||
|
IntList ids = new IntArrayList();
|
||||||
|
for (JsonElement id : entry.getValue()
|
||||||
|
.getAsJsonArray()) {
|
||||||
|
ids.add(id.getAsInt());
|
||||||
|
}
|
||||||
|
into.put(entry.getKey(), ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the table through a temporary file so a crash mid-write never truncates it.
|
||||||
|
*/
|
||||||
|
public void save(File file) {
|
||||||
|
JsonObject root = new JsonObject();
|
||||||
|
root.addProperty("version", FORMAT_VERSION);
|
||||||
|
root.add("blocks", write(blocks));
|
||||||
|
root.add("items", write(items));
|
||||||
|
File temp = new File(file.getPath() + ".tmp");
|
||||||
|
try {
|
||||||
|
Files.createDirectories(
|
||||||
|
file.toPath()
|
||||||
|
.getParent());
|
||||||
|
Files.write(
|
||||||
|
temp.toPath(),
|
||||||
|
new GsonBuilder().create()
|
||||||
|
.toJson(root)
|
||||||
|
.getBytes(StandardCharsets.UTF_8));
|
||||||
|
Files.move(temp.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Cannot write the retired id table " + file, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject write(Map<String, IntList> from) {
|
||||||
|
JsonObject object = new JsonObject();
|
||||||
|
for (Map.Entry<String, IntList> entry : from.entrySet()) {
|
||||||
|
JsonArray ids = new JsonArray();
|
||||||
|
for (int id : entry.getValue()) {
|
||||||
|
ids.add(new JsonPrimitive(id));
|
||||||
|
}
|
||||||
|
object.add(entry.getKey(), ids);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Records entries of a world's saved name-to-id map, whose names FML prefixes with U+0001 for a block and
|
||||||
|
* U+0002 for an item. Returns whether any pair was new.
|
||||||
|
*/
|
||||||
|
public boolean merge(Map<String, Integer> dataList) {
|
||||||
|
boolean changed = false;
|
||||||
|
for (Map.Entry<String, Integer> entry : dataList.entrySet()) {
|
||||||
|
String prefixed = entry.getKey();
|
||||||
|
Map<String, IntList> into = prefixed.charAt(0) == BLOCK_PREFIX ? blocks : items;
|
||||||
|
IntList ids = into.computeIfAbsent(prefixed.substring(1), name -> new IntArrayList());
|
||||||
|
if (!ids.contains((int) entry.getValue())) {
|
||||||
|
ids.add((int) entry.getValue());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntList blockIds(String name) {
|
||||||
|
return blocks.getOrDefault(name, IntLists.EMPTY_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntList itemIds(String name) {
|
||||||
|
return items.getOrDefault(name, IntLists.EMPTY_LIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8.5-GTNH",
|
"minVersion": "0.8.5-GTNH",
|
||||||
"package": "com.colen.postea.mixins.early",
|
"package": "com.gtnewhorizons.postea.mixins.early",
|
||||||
"refmap": "mixins.postea.refmap.json",
|
"refmap": "mixins.postea.refmap.json",
|
||||||
"target": "@env(DEFAULT)",
|
"target": "@env(DEFAULT)",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"MixinAnvilChunkLoader",
|
"MixinAnvilChunkLoader",
|
||||||
"MixinChunk",
|
"MixinChunk",
|
||||||
"MixinItemStack"
|
"MixinEntity",
|
||||||
|
"MixinEntityPlayer",
|
||||||
|
"MixinItemStack",
|
||||||
|
"MixinNBTTagList"
|
||||||
],
|
],
|
||||||
"client": [],
|
"client": [],
|
||||||
"server": []
|
"server": []
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
{
|
{
|
||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8.5-GTNH",
|
"minVersion": "0.8.5-GTNH",
|
||||||
|
"package": "com.gtnewhorizons.postea.mixins.preinit",
|
||||||
|
"plugin": "com.gtnewhorizons.postea.mixins.PosteaPreInitLoadingPlugin",
|
||||||
"refmap": "mixins.postea.refmap.json",
|
"refmap": "mixins.postea.refmap.json",
|
||||||
"target": "@env(DEFAULT)",
|
"target": "@env(PREINIT)",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [],
|
"mixins": [],
|
||||||
"client": [],
|
"client": [],
|
||||||
|
|||||||
@@ -0,0 +1,116 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NbtItemStacksTest {
|
||||||
|
|
||||||
|
private static NBTTagCompound stack(int id, int damage) {
|
||||||
|
NBTTagCompound stack = new NBTTagCompound();
|
||||||
|
stack.setShort("id", (short) id);
|
||||||
|
stack.setByte("Count", (byte) 1);
|
||||||
|
stack.setShort("Damage", (short) damage);
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<NBTTagCompound> visited(NBTTagCompound root) {
|
||||||
|
List<NBTTagCompound> stacks = new ArrayList<>();
|
||||||
|
NbtItemStacks.forEach(root, stacks::add);
|
||||||
|
return stacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void visitsStacksInInventoryListsAndStacksNestedInsideAStacksTag() {
|
||||||
|
NBTTagCompound nested = stack(2, 0);
|
||||||
|
NBTTagCompound backpack = stack(1, 0);
|
||||||
|
NBTTagCompound backpackTag = new NBTTagCompound();
|
||||||
|
NBTTagList contents = new NBTTagList();
|
||||||
|
contents.appendTag(nested);
|
||||||
|
backpackTag.setTag("Items", contents);
|
||||||
|
backpack.setTag("tag", backpackTag);
|
||||||
|
NBTTagList items = new NBTTagList();
|
||||||
|
items.appendTag(backpack);
|
||||||
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||||
|
tileEntity.setString("id", "Chest");
|
||||||
|
tileEntity.setTag("Items", items);
|
||||||
|
NBTTagList tileEntities = new NBTTagList();
|
||||||
|
tileEntities.appendTag(tileEntity);
|
||||||
|
NBTTagCompound level = new NBTTagCompound();
|
||||||
|
level.setTag("TileEntities", tileEntities);
|
||||||
|
|
||||||
|
assertEquals(Arrays.asList(backpack, nested), visited(level));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ignoresCompoundsThatAreNotStacks() {
|
||||||
|
NBTTagCompound enchantment = new NBTTagCompound();
|
||||||
|
enchantment.setShort("id", (short) 3);
|
||||||
|
enchantment.setShort("lvl", (short) 1);
|
||||||
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
||||||
|
tileEntity.setString("id", "Chest");
|
||||||
|
tileEntity.setInteger("Count", 1);
|
||||||
|
NBTTagCompound root = new NBTTagCompound();
|
||||||
|
root.setTag("ench", enchantment);
|
||||||
|
root.setTag("te", tileEntity);
|
||||||
|
|
||||||
|
assertEquals(Collections.emptyList(), visited(root));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void recognisesExtendedIdStacksWithoutADamageKey() {
|
||||||
|
NBTTagCompound extended = new NBTTagCompound();
|
||||||
|
extended.setShort("id", (short) 0);
|
||||||
|
extended.setInteger("idExt", 40000);
|
||||||
|
extended.setByte("Count", (byte) 3);
|
||||||
|
NBTTagCompound root = new NBTTagCompound();
|
||||||
|
root.setTag("Item", extended);
|
||||||
|
|
||||||
|
assertEquals(Collections.singletonList(extended), visited(root));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pins the split that keeps chunk and player walks safe: a string id with a Count is a stack only in
|
||||||
|
// string-id mode, which custom data uses and tile entity trees never do.
|
||||||
|
@Test
|
||||||
|
void stringIdStacksAreVisitedOnlyInStringIdMode() {
|
||||||
|
NBTTagCompound quest = new NBTTagCompound();
|
||||||
|
quest.setString("id", "examplemod:gem");
|
||||||
|
quest.setInteger("Count", 3);
|
||||||
|
quest.setShort("Damage", (short) 7);
|
||||||
|
NBTTagCompound root = new NBTTagCompound();
|
||||||
|
root.setTag("requiredItems", quest);
|
||||||
|
List<NBTTagCompound> wide = new ArrayList<>();
|
||||||
|
|
||||||
|
NbtItemStacks.forEach(root, wide::add, true);
|
||||||
|
|
||||||
|
assertEquals(Collections.emptyList(), visited(root));
|
||||||
|
assertEquals(Collections.singletonList(quest), wide);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aVisitorMayInvalidateTheStackItIsGiven() {
|
||||||
|
NBTTagCompound first = stack(5, 1);
|
||||||
|
NBTTagCompound second = stack(5, 2);
|
||||||
|
NBTTagList items = new NBTTagList();
|
||||||
|
items.appendTag(first);
|
||||||
|
items.appendTag(second);
|
||||||
|
NBTTagCompound root = new NBTTagCompound();
|
||||||
|
root.setTag("Items", items);
|
||||||
|
List<NBTTagCompound> seen = new ArrayList<>();
|
||||||
|
|
||||||
|
NbtItemStacks.forEach(root, tag -> {
|
||||||
|
seen.add(tag);
|
||||||
|
tag.removeTag("id");
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals(Arrays.asList(first, second), seen);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class NbtListsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void anAbsentListIsCreatedAndAttachedSoAppendedTagsAreKept() {
|
||||||
|
NBTTagCompound level = new NBTTagCompound();
|
||||||
|
|
||||||
|
NbtLists.compoundList(level, "TileEntities")
|
||||||
|
.appendTag(new NBTTagCompound());
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
1,
|
||||||
|
level.getTagList("TileEntities", 10)
|
||||||
|
.tagCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void anExistingListIsReturnedAsIs() {
|
||||||
|
NBTTagCompound level = new NBTTagCompound();
|
||||||
|
NBTTagList existing = new NBTTagList();
|
||||||
|
existing.appendTag(new NBTTagCompound());
|
||||||
|
level.setTag("Entities", existing);
|
||||||
|
|
||||||
|
assertSame(existing, NbtLists.compoundList(level, "Entities"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gtnewhorizons.postea.api.IVersionedTransformer;
|
||||||
|
|
||||||
|
class VersionStampsTest {
|
||||||
|
|
||||||
|
private static IVersionedTransformer transformer(String key, int version) {
|
||||||
|
return new IVersionedTransformer() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int currentVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void anUnstampedContainerReadsAsUnstamped() {
|
||||||
|
NBTTagCompound container = new NBTTagCompound();
|
||||||
|
|
||||||
|
assertNull(VersionStamps.read(container));
|
||||||
|
assertEquals(VersionStamps.UNSTAMPED, VersionStamps.stored(null, "mod:key"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeStampsRegisteredKeysAtTheirCurrentVersionAndCarriesUnknownKeys() {
|
||||||
|
NBTTagCompound carried = new NBTTagCompound();
|
||||||
|
carried.setInteger("absentmod:key", 7);
|
||||||
|
carried.setInteger("mod:key", 2);
|
||||||
|
NBTTagCompound container = new NBTTagCompound();
|
||||||
|
|
||||||
|
VersionStamps.write(container, carried, Collections.singletonList(transformer("mod:key", 3)));
|
||||||
|
|
||||||
|
NBTTagCompound stamps = VersionStamps.read(container);
|
||||||
|
assertEquals(3, VersionStamps.stored(stamps, "mod:key"));
|
||||||
|
assertEquals(7, VersionStamps.stored(stamps, "absentmod:key"));
|
||||||
|
assertEquals(2, carried.getInteger("mod:key"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeWithoutCarriedStampsWritesOnlyRegisteredKeys() {
|
||||||
|
NBTTagCompound container = new NBTTagCompound();
|
||||||
|
|
||||||
|
VersionStamps.write(container, null, Collections.singletonList(transformer("mod:key", 1)));
|
||||||
|
|
||||||
|
assertEquals(1, VersionStamps.stored(VersionStamps.read(container), "mod:key"));
|
||||||
|
assertEquals(VersionStamps.UNSTAMPED, VersionStamps.stored(VersionStamps.read(container), "other:key"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package com.gtnewhorizons.postea.utility;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
|
|
||||||
|
class WorldIdTableTest {
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
File dir;
|
||||||
|
|
||||||
|
private File file() {
|
||||||
|
return new File(dir, "known-ids.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntList ids(int... ids) {
|
||||||
|
return IntArrayList.wrap(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, Integer> savedIds(Object... namesAndIds) {
|
||||||
|
Map<String, Integer> map = new HashMap<>();
|
||||||
|
for (int i = 0; i < namesAndIds.length; i += 2) {
|
||||||
|
map.put((String) namesAndIds[i], (Integer) namesAndIds[i + 1]);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mergeRecordsEveryIdANameHeldInObservationOrderAndReportsChanges() {
|
||||||
|
WorldIdTable table = new WorldIdTable();
|
||||||
|
|
||||||
|
assertTrue(table.merge(savedIds("\u0001mod:block", 300, "\u0002mod:item", 4200)));
|
||||||
|
assertFalse(table.merge(savedIds("\u0001mod:block", 300, "\u0002mod:item", 4200)));
|
||||||
|
assertTrue(table.merge(savedIds("\u0001mod:block", 301)));
|
||||||
|
|
||||||
|
assertEquals(ids(300, 301), table.blockIds("mod:block"));
|
||||||
|
assertEquals(ids(4200), table.itemIds("mod:item"));
|
||||||
|
assertEquals(ids(), table.blockIds("mod:item"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void saveAndLoadRoundTrip() {
|
||||||
|
WorldIdTable table = new WorldIdTable();
|
||||||
|
table.merge(savedIds("\u0001mod:block", 300, "\u0002mod:item", 4200));
|
||||||
|
table.merge(savedIds("\u0001mod:block", 301));
|
||||||
|
|
||||||
|
table.save(file());
|
||||||
|
WorldIdTable loaded = WorldIdTable.load(file());
|
||||||
|
|
||||||
|
assertEquals(ids(300, 301), loaded.blockIds("mod:block"));
|
||||||
|
assertEquals(ids(4200), loaded.itemIds("mod:item"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void anAbsentFileLoadsEmptyAndAMalformedFileFailsLoudly() throws IOException {
|
||||||
|
assertEquals(
|
||||||
|
ids(),
|
||||||
|
WorldIdTable.load(file())
|
||||||
|
.blockIds("mod:block"));
|
||||||
|
|
||||||
|
Files.write(file().toPath(), "{\"version\":1,\"blocks\":5}".getBytes(StandardCharsets.UTF_8));
|
||||||
|
|
||||||
|
assertThrows(IllegalStateException.class, () -> WorldIdTable.load(file()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user