Progress with not enough IDs

This commit is contained in:
GTNH-Colen committed 2023-10-29 01:06:18 +01:00
1 parent f2080ab8b4
commit d41aff53e0
10 files changed
+226 -143

No files matched your search

@@ -1,6 +1,8 @@
package com.colen.postea.API;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
@@ -32,4 +34,24 @@ public class ChunkFixerUtility {
}
return chunk;
}
public static void processCode(NBTTagCompound compound) {
System.out.println(compound.toString());
swapTileEntities(compound);
}
private static void swapTileEntities(NBTTagCompound compound) {
NBTTagList tileEntities = compound.getCompoundTag("Level").getTagList("TileEntities", 10);
for (int i = 0; i < tileEntities.tagCount(); i++) {
NBTTagCompound tileEntity = tileEntities.getCompoundTagAt(i);
String tileEntityStringName = tileEntity.getString("id");
TileTransformer tileTransformer = TileEntityReplacementManager.getTileReplacementTransformer(tileEntityStringName);
if (tileTransformer != null) {
tileTransformer.modifyNBT(tileEntity);
}
}
}
}
@@ -8,8 +8,8 @@ public class TileEntityReplacementManager {
private static final Map<String, TileTransformer> replacementMap = new HashMap<>();
@SuppressWarnings("unused")
public static void tileEntityReplacement(String tileName , TileTransformer tileTransformer) {
replacementMap.put(tileName, tileTransformer);
public static void tileEntityReplacement(String tileName , TileTransformer tileReplacer) {
replacementMap.put(tileName, tileReplacer);
}
@SuppressWarnings("unused")
@@ -11,11 +11,12 @@ import java.util.function.Function;
public class TileTransformer {
private final Class<? extends TileEntity> tileClass;
private final Function<NBTTagCompound, NBTTagCompound> NBTModifierFunction;
public TileTransformer(Class<? extends TileEntity> tileClass, Function<NBTTagCompound, NBTTagCompound> NBTModifierFunction) {
this.tileClass = tileClass;
private final Function<NBTTagCompound, NBTTagCompound> NBTModifierFunction;
private final String tileName;
public TileTransformer(String tileName, Function<NBTTagCompound, NBTTagCompound> NBTModifierFunction) {
this.tileName = tileName;
this.NBTModifierFunction = NBTModifierFunction;
}
@@ -23,28 +24,16 @@ public class TileTransformer {
public boolean equals(Object o) {
if (o == null) return false;
if (o instanceof TileTransformer that) {
return (this.tileClass == that.tileClass);
return (this.tileName.equals(that.tileName));
} else return false;
}
@Override
public int hashCode() {
return Objects.hash(tileClass);
}
public void modifyNBT(NBTTagCompound nbt) {
NBTModifierFunction.apply(nbt);
}
public Class<? extends TileEntity> getTileClass() {
return tileClass;
public String getTileName() {
return tileName;
}
public void setBlock(NBTTagCompound nbt, World world) {
int x = nbt.getInteger("x");
int y = nbt.getInteger("y");
int z = nbt.getInteger("z");
Minecraft.getMinecraft().theWorld.setBlock(x, y, z, Blocks.chest);
}
}
+8 -4
View File
@@ -23,16 +23,20 @@ public class Postea {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
//ItemStackReplacementManager.addItemReplacement(Item.getItemFromBlock(Blocks.grass), 0, Item.getItemFromBlock(Blocks.coal_ore), 10);
BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 6, Blocks.emerald_ore, 0);
BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 16022, Blocks.nether_brick, 0);
BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 1018, Blocks.end_stone, 0);
// BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 6, Blocks.emerald_ore, 0);
// BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 16022, Blocks.nether_brick, 0);
// BlockReplacementManager.addBlockReplacement(GregTech_API.sBlockOres1, 1018, Blocks.end_stone, 0);
// Define the transformation function
Function<NBTTagCompound, NBTTagCompound> myTransformer = (tag) -> {
if (tag.getInteger("m") == 86) {
tag.setInteger("m", 323);
return tag;
}
return tag;
};
TileEntityReplacementManager.tileEntityReplacement("GT_TileEntity_Ores", new TileTransformer(TileEntityChest.class, myTransformer));
TileEntityReplacementManager.tileEntityReplacement("GT_TileEntity_Ores", new TileTransformer("GT_TileEntity_Ores", myTransformer));
}
@@ -1,31 +1,98 @@
package com.colen.postea.mixins.early;
import com.colen.postea.API.ChunkFixerUtility;
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.CallbackInfoReturnable;
import static com.colen.postea.API.ChunkFixerUtility.processCode;
@Mixin(AnvilChunkLoader.class)
@SuppressWarnings("unused")
public abstract class MixinAnvilChunkLoader {
@Inject(
method = "readChunkFromNBT(Lnet/minecraft/world/World;Lnet/minecraft/nbt/NBTTagCompound;)Lnet/minecraft/world/chunk/Chunk;",
at = @At("RETURN"),
cancellable = true
)
@SuppressWarnings("unused")
private void onChunkReloadFromWorldSaveData(World world, NBTTagCompound compound, CallbackInfoReturnable<Chunk> cir) {
Chunk chunk = cir.getReturnValue();
// @Unique
// private static Class<?> PendingChunkClass;
//
// static {
// try {
// for (Class<?> declaredClass : AnvilChunkLoader.class.getDeclaredClasses()) {
// if (declaredClass.getSimpleName().equals("PendingChunk")) {
// PendingChunkClass = declaredClass;
// break;
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// /**
// * @author Colen
// * @reason Reasons.
// */
// @Unique
// @Overwrite(remap = false)
// public Object[] loadChunk__Async(World p_75815_1_, int p_75815_2_, int p_75815_3_) throws IOException
// {
// NBTTagCompound nbttagcompound = null;
// ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(p_75815_2_, p_75815_3_);
// Object object = this.syncLockObject;
//
// synchronized (this.syncLockObject)
// {
// if (this.pendingAnvilChunksCoordinates.contains(chunkcoordintpair)) {
// Iterator iter = this.chunksToRemove.iterator();
// while (iter.hasNext()) {
// Object potentialPendingChunk = iter.next();
// if (PendingChunkClass.isInstance(potentialPendingChunk)) {
// try {
// Field chunkCoordinateField = PendingChunkClass.getDeclaredField("chunkCoordinate");
// chunkCoordinateField.setAccessible(true);
// ChunkCoordIntPair chunkCoordinate = (ChunkCoordIntPair) chunkCoordinateField.get(potentialPendingChunk);
//
// Field nbtTagsField = PendingChunkClass.getDeclaredField("nbtTags");
// nbtTagsField.setAccessible(true);
// NBTTagCompound nbtTags = (NBTTagCompound) nbtTagsField.get(potentialPendingChunk);
//
// if (chunkCoordinate.equals(chunkcoordintpair)) {
// nbttagcompound = nbtTags;
// break;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
// }
//
// }
//
// if (nbttagcompound == null)
// {
// DataInputStream datainputstream = RegionFileCache.getChunkInputStream(this.chunkSaveLocation, p_75815_2_, p_75815_3_);
//
// if (datainputstream == null)
// {
// return null;
// }
//
// nbttagcompound = CompressedStreamTools.read(datainputstream);
// }
//
// return this.checkedReadChunkFromNBT__Async(p_75815_1_, p_75815_2_, p_75815_3_, nbttagcompound);
// }
//
// @Unique
// protected native Object[] checkedReadChunkFromNBT__Async(World p_75822_1_, int p_75822_2_, int p_75822_3_, NBTTagCompound p_75822_4_);
Chunk fixedChunk = ChunkFixerUtility.fixChunk(chunk);
cir.setReturnValue(fixedChunk);
@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
processCode(compound);
}
}
@@ -12,18 +12,18 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@SuppressWarnings("unused")
public class MixinChunkProviderServer {
@Inject(
method = "originalLoadChunk(II)Lnet/minecraft/world/chunk/Chunk;",
at = @At("RETURN"),
remap=false,
cancellable = true
)
@SuppressWarnings("unused")
public void onChunkCreation(int chunkX, int chunkZ, CallbackInfoReturnable<Chunk> cir) {
Chunk chunk = cir.getReturnValue();
Chunk fixedChunk = ChunkFixerUtility.fixChunk(chunk);
cir.setReturnValue(fixedChunk);
}
// @Inject(
// method = "originalLoadChunk(II)Lnet/minecraft/world/chunk/Chunk;",
// at = @At("RETURN"),
// remap=false,
// cancellable = true
// )
// @SuppressWarnings("unused")
// public void onChunkCreation(int chunkX, int chunkZ, CallbackInfoReturnable<Chunk> cir) {
// Chunk chunk = cir.getReturnValue();
//
// Chunk fixedChunk = ChunkFixerUtility.fixChunk(chunk);
//
// cir.setReturnValue(fixedChunk);
// }
}
@@ -18,34 +18,34 @@ import com.colen.postea.API.ItemStackReplacementManager;
@SuppressWarnings("unused")
public abstract class MixinItemStack {
@Shadow
private int itemDamage; // Metadata
@Shadow
private Item field_151002_e;
@Inject(method = "<init>(Lnet/minecraft/item/Item;II)V", at = @At("RETURN"))
@SuppressWarnings("unused")
private void onConstructorReturn(Item item, int size, int metadata, CallbackInfo ci) {
ItemStackKey replacement = ItemStackReplacementManager.getItemReplacement(item, metadata);
if (replacement == null) return;
// Edit private variables here.
itemDamage = replacement.getDamage();
func_150996_a(replacement.getItem());
}
@Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("RETURN"))
@SuppressWarnings("unused")
private void onReadFromNBTReturn(NBTTagCompound p_77963_1_, CallbackInfo ci) {
ItemStackKey replacement = ItemStackReplacementManager.getItemReplacement(field_151002_e, itemDamage);
if (replacement == null) return;
itemDamage = replacement.getDamage();
func_150996_a(replacement.getItem());
}
@Unique
public native void func_150996_a(Item p_150996_1_);
// @Shadow
// private int itemDamage; // Metadata
// @Shadow
// private Item field_151002_e;
//
// @Inject(method = "<init>(Lnet/minecraft/item/Item;II)V", at = @At("RETURN"))
// @SuppressWarnings("unused")
// private void onConstructorReturn(Item item, int size, int metadata, CallbackInfo ci) {
// ItemStackKey replacement = ItemStackReplacementManager.getItemReplacement(item, metadata);
//
// if (replacement == null) return;
//
// // Edit private variables here.
// itemDamage = replacement.getDamage();
// func_150996_a(replacement.getItem());
// }
//
// @Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("RETURN"))
// @SuppressWarnings("unused")
// private void onReadFromNBTReturn(NBTTagCompound p_77963_1_, CallbackInfo ci) {
// ItemStackKey replacement = ItemStackReplacementManager.getItemReplacement(field_151002_e, itemDamage);
//
// if (replacement == null) return;
//
// itemDamage = replacement.getDamage();
// func_150996_a(replacement.getItem());
// }
//
// @Unique
// public native void func_150996_a(Item p_150996_1_);
}
@@ -18,68 +18,68 @@ import java.util.Map;
@SuppressWarnings("unused")
public class MixinTileEntity {
@Shadow
private static Logger logger;
@Shadow
private static Map nameToClassMap;
@Shadow
protected World worldObj;
// @Shadow
// private static Logger logger;
//
// @Shadow
// private static Map nameToClassMap;
//
// @Shadow
// protected World worldObj;
/**
* Creates a new entity and loads its data from the specified NBT.
*/
@Overwrite
@SuppressWarnings("unused")
public static TileEntity createAndLoadEntity(NBTTagCompound nbt) {
TileEntity tileentity = null;
Class oclass = null;
try
{
String tileEntityStringName = nbt.getString("id");
TileTransformer tileTransformer = TileEntityReplacementManager.getTileReplacementTransformer(tileEntityStringName);
if (tileTransformer == null) {
oclass = (Class)nameToClassMap.get(tileEntityStringName);
} else {
oclass = tileTransformer.getTileClass();
tileTransformer.modifyNBT(nbt);
}
if (oclass != null)
{
tileentity = (TileEntity)oclass.newInstance();
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
if (tileentity != null)
{
try
{
tileentity.readFromNBT(nbt);
}
catch (Exception ex)
{
FMLLog.log(Level.ERROR, ex,
"A TileEntity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author",
nbt.getString("id"), oclass.getName());
tileentity = null;
}
}
else
{
logger.warn("Skipping BlockEntity with id " + nbt.getString("id"));
}
return tileentity;
}
// @Overwrite
// @SuppressWarnings("unused")
// public static TileEntity createAndLoadEntity(NBTTagCompound nbt) {
// TileEntity tileentity = null;
//
// Class oclass = null;
// try
// {
// String tileEntityStringName = nbt.getString("id");
// TileTransformer tileTransformer = TileEntityReplacementManager.getTileReplacementTransformer(tileEntityStringName);
//
//
// if (tileTransformer == null) {
// oclass = (Class)nameToClassMap.get(tileEntityStringName);
// } else {
// oclass = tileTransformer.getTileClass();
// tileTransformer.modifyNBT(nbt);
// }
//
// if (oclass != null)
// {
// tileentity = (TileEntity)oclass.newInstance();
// }
// }
// catch (Exception exception)
// {
// exception.printStackTrace();
// }
//
// if (tileentity != null)
// {
// try
// {
// tileentity.readFromNBT(nbt);
// }
// catch (Exception ex)
// {
// FMLLog.log(Level.ERROR, ex,
// "A TileEntity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author",
// nbt.getString("id"), oclass.getName());
// tileentity = null;
// }
// }
// else
// {
// logger.warn("Skipping BlockEntity with id " + nbt.getString("id"));
// }
//
// return tileentity;
// }
}