mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-12 16:37:38 +00:00
Spotless
This commit is contained in:
1 parent
b3896b40a4
commit
7f7cdacfbd
11 files changed
+79
-66
No files matched your search
@@ -1,24 +1,26 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import com.colen.postea.Utility.BlockConversionInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.colen.postea.Utility.BlockConversionInfo;
|
||||
|
||||
public class BlockReplacementManager {
|
||||
|
||||
private static final Map<String, Function<BlockConversionInfo, BlockConversionInfo>> blockReplacementMap = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void addBlockReplacement(String blockNameIn, Function<BlockConversionInfo, BlockConversionInfo> transformer) {
|
||||
public static void addBlockReplacement(String blockNameIn,
|
||||
Function<BlockConversionInfo, BlockConversionInfo> transformer) {
|
||||
blockReplacementMap.put(blockNameIn, transformer);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static BlockConversionInfo getBlockReplacement(BlockConversionInfo blockConversionInfo) {
|
||||
|
||||
Function<BlockConversionInfo, BlockConversionInfo> transformer = blockReplacementMap.getOrDefault(blockConversionInfo.blocKName, null);
|
||||
Function<BlockConversionInfo, BlockConversionInfo> transformer = blockReplacementMap
|
||||
.getOrDefault(blockConversionInfo.blocKName, null);
|
||||
|
||||
if (transformer == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
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<>();
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import com.colen.postea.Utility.BlockInfo;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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) {
|
||||
public static void tileEntityTransformer(String tileEntityId,
|
||||
BiFunction<NBTTagCompound, World, BlockInfo> transformerFunction) {
|
||||
tileEntityToNormalBlockTransformer.put(tileEntityId, transformerFunction);
|
||||
}
|
||||
|
||||
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(String tileEntityId) {
|
||||
public static BiFunction<NBTTagCompound, World, BlockInfo> getTileEntityToNormalBlockTransformerFunction(
|
||||
String tileEntityId) {
|
||||
return tileEntityToNormalBlockTransformer.getOrDefault(tileEntityId, null);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.colen.postea;
|
||||
|
||||
import com.colen.postea.API.BlockReplacementManager;
|
||||
import com.colen.postea.API.ItemStackReplacementManager;
|
||||
import com.colen.postea.API.TileEntityReplacementManager;
|
||||
import com.colen.postea.Utility.BlockConversionInfo;
|
||||
import com.colen.postea.Utility.BlockInfo;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import static com.colen.postea.Utility.PosteaUtilities.cleanseNBT;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -15,9 +11,14 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.colen.postea.API.BlockReplacementManager;
|
||||
import com.colen.postea.API.ItemStackReplacementManager;
|
||||
import com.colen.postea.API.TileEntityReplacementManager;
|
||||
import com.colen.postea.Utility.BlockConversionInfo;
|
||||
import com.colen.postea.Utility.BlockInfo;
|
||||
|
||||
import static com.colen.postea.Utility.PosteaUtilities.cleanseNBT;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
||||
@SuppressWarnings("unused")
|
||||
@@ -27,7 +28,8 @@ public class Postea {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
|
||||
// This is an example of replacing GT ore blocks depending on the dimension. Because BlockInfo has no TileEntity
|
||||
// transformer set, it will delete the underlying tile entity fully. This will essentially convert a TE block to a non-TE block.
|
||||
// transformer set, it will delete the underlying tile entity fully. This will essentially convert a TE block to
|
||||
// a non-TE block.
|
||||
// You can use the data in the tile to determine this conversion from the "tag" variable.
|
||||
TileEntityReplacementManager.tileEntityTransformer("GT_TileEntity_Ores", (tag, world) -> {
|
||||
if (world.provider.dimensionId == -1) {
|
||||
@@ -41,8 +43,8 @@ public class Postea {
|
||||
return new BlockInfo(Blocks.wool, 3);
|
||||
});
|
||||
|
||||
|
||||
// This is an example of how to replace another tile entity and it's block. Here we are replacing furnaces with chests.
|
||||
// This is an example of how to replace another tile entity and it's block. Here we are replacing furnaces with
|
||||
// chests.
|
||||
// It will then also replace the furnace block with a chest. Otherwise the Tile would not match the block.
|
||||
TileEntityReplacementManager.tileEntityTransformer("Furnace", (tag, world) -> {
|
||||
|
||||
@@ -102,7 +104,6 @@ public class Postea {
|
||||
return new BlockInfo(Blocks.chest, 0, chestTransformer);
|
||||
});
|
||||
|
||||
|
||||
// Example of how to replace a non-TE block with another non-TE block, this replaces grass with wool.
|
||||
// It converts every grass block with an even x coordinate to orange wool.
|
||||
Function<BlockConversionInfo, BlockConversionInfo> blockTransformer = (blockConversionInfoOld) -> {
|
||||
@@ -122,7 +123,6 @@ public class Postea {
|
||||
|
||||
BlockReplacementManager.addBlockReplacement("minecraft:grass", blockTransformer);
|
||||
|
||||
|
||||
// Example of how to replace an item, this replaces iron ingots with gold ingots.
|
||||
// You can manipulate stack size but it isn't recommended.
|
||||
// You can also use the tag associated with this ItemStack to determine the replacement.
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class BlockConversionInfo {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.colen.postea.Utility;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public final class BlockInfo {
|
||||
|
||||
public final Block block;
|
||||
public final int metadata;
|
||||
public final Function<NBTTagCompound, NBTTagCompound> tileTransformer;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.colen.postea.Utility;
|
||||
|
||||
import akka.japi.Pair;
|
||||
import com.colen.postea.API.BlockReplacementManager;
|
||||
import com.colen.postea.API.TileEntityReplacementManager;
|
||||
import com.colen.postea.Utility.BlockConversionInfo;
|
||||
import com.colen.postea.Utility.BlockInfo;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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) {
|
||||
@@ -27,8 +27,8 @@ public class ChunkFixerUtility {
|
||||
NBTTagCompound level = compound.getCompoundTag("Level");
|
||||
NBTTagList sections = level.getTagList("Sections", 10);
|
||||
|
||||
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
||||
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
||||
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
||||
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
||||
|
||||
for (int i = 0; i < sections.tagCount(); i++) {
|
||||
NBTTagCompound section = sections.getCompoundTagAt(i);
|
||||
@@ -38,10 +38,12 @@ public class ChunkFixerUtility {
|
||||
|
||||
for (int index = 0; index < blockArray.length / 2; index++) {
|
||||
int blockId = ((blockArray[index * 2] & 0xFF) << 8) | (blockArray[index * 2 + 1] & 0xFF);
|
||||
byte metadata = (byte) ((index & 1) == 0 ? (metadataArray[index / 2] & 0x0F) : ((metadataArray[index / 2] & 0xF0) >> 4));
|
||||
byte metadata = (byte) ((index & 1) == 0 ? (metadataArray[index / 2] & 0x0F)
|
||||
: ((metadataArray[index / 2] & 0xF0) >> 4));
|
||||
|
||||
Block block = Block.getBlockById(blockId);
|
||||
String blockName = GameRegistry.findUniqueIdentifierFor(block).toString();
|
||||
String blockName = GameRegistry.findUniqueIdentifierFor(block)
|
||||
.toString();
|
||||
|
||||
BlockConversionInfo blockConversionInfo = new BlockConversionInfo();
|
||||
blockConversionInfo.blocKName = blockName;
|
||||
@@ -50,11 +52,11 @@ public class ChunkFixerUtility {
|
||||
blockConversionInfo.world = world;
|
||||
|
||||
int x = index % 16;
|
||||
int y = (index / 256) + (sectionY * 16); // Add the offset of the current section in Y direction
|
||||
int y = (index / 256) + (sectionY * 16); // Add the offset of the current section in Y direction
|
||||
int z = (index / 16) % 16;
|
||||
|
||||
blockConversionInfo.x = x + chunkXPos;
|
||||
blockConversionInfo.y = y; // Y remains unchanged as it's already global
|
||||
blockConversionInfo.y = y; // Y remains unchanged as it's already global
|
||||
blockConversionInfo.z = z + chunkZPos;
|
||||
|
||||
BlockConversionInfo output = BlockReplacementManager.getBlockReplacement(blockConversionInfo);
|
||||
@@ -88,8 +90,8 @@ public class ChunkFixerUtility {
|
||||
level.setTag("TileEntities", tileEntities);
|
||||
}
|
||||
|
||||
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
||||
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
||||
int chunkXPos = level.getInteger("xPos") * 16; // Assuming each chunk is 16 blocks along x-axis
|
||||
int chunkZPos = level.getInteger("zPos") * 16; // Assuming each chunk is 16 blocks along z-axis
|
||||
|
||||
NBTTagList sections = level.getTagList("Sections", 10);
|
||||
for (int i = 0; i < sections.tagCount(); i++) {
|
||||
@@ -98,7 +100,8 @@ public class ChunkFixerUtility {
|
||||
}
|
||||
}
|
||||
|
||||
private static void processSection(NBTTagCompound section, List<ConversionInfo> conversionInfoList, int chunkXPos, int chunkZPos) {
|
||||
private static void processSection(NBTTagCompound section, List<ConversionInfo> conversionInfoList, int chunkXPos,
|
||||
int chunkZPos) {
|
||||
byte[] blockArray = section.getByteArray("Blocks16");
|
||||
byte[] metadataArray = section.getByteArray("Data");
|
||||
byte y = section.getByte("Y");
|
||||
@@ -123,7 +126,7 @@ public class ChunkFixerUtility {
|
||||
int tileX = info.x - chunkXPos;
|
||||
int tileY = info.y - y * 16;
|
||||
int tileZ = info.z - chunkZPos;
|
||||
return new int[]{tileX, tileY, tileZ};
|
||||
return new int[] { tileX, tileY, tileZ };
|
||||
}
|
||||
|
||||
private static int computeBlockIndex(int[] localCoords) {
|
||||
@@ -161,7 +164,8 @@ public class ChunkFixerUtility {
|
||||
String tileEntityId = tileEntity.getString("id");
|
||||
|
||||
// Check if we have a transformer registered for this tile entity ID
|
||||
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||
BiFunction<NBTTagCompound, World, BlockInfo> transformationFunction = TileEntityReplacementManager
|
||||
.getTileEntityToNormalBlockTransformerFunction(tileEntityId);
|
||||
|
||||
if (transformationFunction != null) {
|
||||
int x = tileEntity.getInteger("x");
|
||||
@@ -178,11 +182,9 @@ public class ChunkFixerUtility {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new Pair<>(conversionInfo, tileEntitiesCopy);
|
||||
}
|
||||
|
||||
|
||||
public static class ConversionInfo {
|
||||
|
||||
public final int x;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.colen.postea.Utility;
|
||||
|
||||
import com.colen.postea.API.ItemStackReplacementManager;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.function.Function;
|
||||
import com.colen.postea.API.ItemStackReplacementManager;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public abstract class ItemFixerUtility {
|
||||
|
||||
@@ -16,9 +18,11 @@ public abstract class ItemFixerUtility {
|
||||
if (tag.hasKey("id")) {
|
||||
short id = tag.getShort("id");
|
||||
Item item = Item.getItemById(id);
|
||||
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":" + GameRegistry.findUniqueIdentifierFor(item).name;
|
||||
String itemNameInternal = GameRegistry.findUniqueIdentifierFor(item).modId + ":"
|
||||
+ GameRegistry.findUniqueIdentifierFor(item).name;
|
||||
|
||||
Function<NBTTagCompound, NBTTagCompound> transformer = ItemStackReplacementManager.getItemReplacement(itemNameInternal);
|
||||
Function<NBTTagCompound, NBTTagCompound> transformer = ItemStackReplacementManager
|
||||
.getItemReplacement(itemNameInternal);
|
||||
|
||||
if (transformer != null) {
|
||||
transformer.apply(tag);
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.colen.postea.Utility;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class PosteaUtilities {
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package com.colen.postea.mixins.early;
|
||||
|
||||
import static com.colen.postea.Utility.ChunkFixerUtility.processChunkNBT;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
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.CallbackInfoReturnable;
|
||||
|
||||
import static com.colen.postea.Utility.ChunkFixerUtility.processChunkNBT;
|
||||
|
||||
@Mixin(AnvilChunkLoader.class)
|
||||
@SuppressWarnings("unused")
|
||||
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) {
|
||||
// Your injection code here
|
||||
private void onCheckedReadChunkFromNBT__Async(World world, int x, int z, NBTTagCompound compound,
|
||||
CallbackInfoReturnable<Object[]> cir) {
|
||||
processChunkNBT(compound, world);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.colen.postea.mixins.early;
|
||||
|
||||
import static com.colen.postea.Utility.ItemFixerUtility.fixItemStack;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
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 static com.colen.postea.Utility.ItemFixerUtility.fixItemStack;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class MixinItemStack {
|
||||
|
||||
Reference in new issue
Block a user