migrate some spaghetti code to ChunkAPI

replaced netcode/saving logic for blocks, metadata, and biomes
This commit is contained in:
FalsePattern committed 2023-03-30 22:50:11 +02:00
1 parent 984c976b34
commit de5fa2d322
17 files changed
+394 -978

No files matched your search

@@ -1,49 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.client.biome.vanilla;
import com.falsepattern.endlessids.Hooks;
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.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.world.chunk.Chunk;
import java.util.Iterator;
@Mixin(Chunk.class)
public abstract class ChunkMixin {
@SuppressWarnings("rawtypes")
@Inject(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;clearMSBArray()V")),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void biomeData(byte[] p_76607_1_, int p_76607_2_, int p_76607_3_, boolean p_76607_4_, CallbackInfo ci, Iterator iterator, int k, boolean flag1, int l) {
Hooks.readBiomeArrayFromPacket((Chunk) (Object) this, p_76607_1_, k);
}
@Redirect(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;clearMSBArray()V")),
require = 1)
private void noCopyBiome(Object src, int srcPos, Object dest, int destPos, int length) {
}
@Redirect(method = "fillChunk",
at = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/Chunk;blockBiomeArray:[B",
args = "array=length"),
require = 1)
private int noBiomeArrayLength(byte[] array) {
return 0;
}
}
@@ -1,141 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.client.blockitem.vanilla;
import com.falsepattern.endlessids.Hooks;
import com.falsepattern.endlessids.mixin.helpers.IExtendedBlockStorageMixin;
import lombok.val;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import java.util.Iterator;
@Mixin(Chunk.class)
public abstract class ChunkMixin {
//This is needed because the array is not a field, but a local, and local arraylength overriding does not exist
private static byte[][] fakeArrays;
private static NibbleArray[] fakeNarrays;
@Shadow
private ExtendedBlockStorage[] storageArrays;
private int ebsData;
@ModifyVariable(method = "fillChunk",
at = @At("HEAD"),
ordinal = 0,
argsOnly = true)
private int extractEBSData(int ebs) {
ebsData = ebs;
int result = 0;
for (int i = 0; i < 16; i++) {
result |= ((ebs >>> (i << 1)) & 0b11) > 0 ? 1 << i : 0;
}
return result;
}
@Redirect(method = "fillChunk",
at = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/Chunk;storageArrays:[Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;",
args = "array=length",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getSkylightArray()Lnet/minecraft/world/chunk/NibbleArray;")),
require = 1)
private int noMSBLoop(ExtendedBlockStorage[] array) {
return 0;
}
@SuppressWarnings("rawtypes")
@Inject(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B"),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void blockData(byte[] p_76607_1_, int p_76607_2_, int p_76607_3_, boolean p_76607_4_, CallbackInfo ci, Iterator iterator, int k, boolean flag1, int l) {
val storageFlag = (p_76607_3_ >>> (l << 1)) & 0b11;
Hooks.setBlockData((IExtendedBlockStorageMixin) this.storageArrays[l], p_76607_1_, k, storageFlag);
}
@Redirect(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B"),
require = 1)
private byte[] fakeLSBArray(ExtendedBlockStorage instance) {
if (fakeArrays == null) {
fakeArrays = new byte[4][];
fakeArrays[0] = new byte[16 * 16 * 16 * 2 / 2];
fakeArrays[1] = new byte[16 * 16 * 16 * 3 / 2];
fakeArrays[2] = new byte[16 * 16 * 16 * 4 / 2];
fakeArrays[3] = new byte[16 * 16 * 16 * 6 / 2];
}
return fakeArrays[((IExtendedBlockStorageMixin) instance).getEBSMSBMask()];
}
@Redirect(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B")),
require = 1)
private void noCopy(Object src, int srcPos, Object dest, int destPos, int length) {
}
@Inject(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void hookSetBlockMeta(byte[] p_76607_1_, int p_76607_2_, int p_76607_3_, boolean p_76607_4_, CallbackInfo ci, Iterator iterator, int k, boolean flag1, int l) {
val storageFlag = (ebsData >>> (l << 1)) & 0b11;
Hooks.setBlockMeta((IExtendedBlockStorageMixin) this.storageArrays[l], p_76607_1_, k, storageFlag);
}
@Redirect(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
require = 1)
private NibbleArray hookSetBlockMetaNoArray(ExtendedBlockStorage instance) {
if (fakeNarrays == null) {
fakeNarrays = new NibbleArray[3];
fakeNarrays[0] = new NibbleArray(new byte[]{(byte)0b01}, 0);
fakeNarrays[1] = new NibbleArray(new byte[]{(byte)0b10}, 0);
fakeNarrays[2] = new NibbleArray(new byte[]{(byte)0b100}, 0);
}
return fakeNarrays[((IExtendedBlockStorageMixin)instance).getEBSMask() - 1];
}
@Redirect(method = "fillChunk",
at = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/NibbleArray;data:[B",
args = "array=length"),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
to = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlocklightArray()Lnet/minecraft/world/chunk/NibbleArray;")),
expect = 2,
require = 2)
private int hookSetBlockMetaFakeBytesLength(byte[] array) {
return 16 * 16 * 16 * (array[0] & 0xFF) / 2;
}
@Redirect(method = "fillChunk",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;")),
require = 1)
private void hookSetBlockMetaNoCopy(Object src, int srcPos, Object dest, int destPos, int length) {
}
}
@@ -1,65 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.biome.vanilla;
import com.falsepattern.endlessids.Hooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
@Mixin(AnvilChunkLoader.class)
public abstract class AnvilChunkLoaderMixin {
//TODO not thread safe
private Chunk chunk;
private NBTTagCompound nbt;
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private byte[] grabChunkBiomeDataWrite(Chunk instance) {
chunk = instance;
return null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V"),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Sections"),
to = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/Chunk;hasEntities:Z",
ordinal = 0)),
require = 1)
private void redirectBiomeDataWrite(NBTTagCompound instance, String p_74773_1_, byte[] p_74773_2_) {
Hooks.writeChunkBiomeArrayToNbt(chunk, instance);
chunk = null;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z",
ordinal = 0),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Biomes",
ordinal = 0)),
require = 1)
private boolean grabBiomeNBTRead(NBTTagCompound instance, String p_150297_1_, int p_150297_2_) {
nbt = instance;
return true;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;setBiomeArray([B)V"),
require = 1)
private void redirectBiomeDataRead(Chunk instance, byte[] p_76616_1_) {
Hooks.readChunkBiomeArrayFromNbt(instance, nbt);
nbt = null;
}
}
@@ -1,21 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.biome.vanilla;
import com.falsepattern.endlessids.Hooks;
import com.falsepattern.endlessids.mixin.helpers.IChunkMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import net.minecraft.network.play.server.S21PacketChunkData;
import net.minecraft.world.chunk.Chunk;
@Mixin(S21PacketChunkData.class)
public abstract class S21PacketChunkDataMixin {
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/Chunk;getBiomeArray()[B"),
require = 1)
private static byte[] getBiomesArrayShort(Chunk instance) {
return Hooks.shortToByteArray(((IChunkMixin) instance).getBiomeShortArray());
}
}
@@ -1,138 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.blockitem.vanilla;
import com.falsepattern.endlessids.Hooks;
import com.falsepattern.endlessids.mixin.helpers.IExtendedBlockStorageMixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
@Mixin(AnvilChunkLoader.class)
public abstract class AnvilChunkLoaderMixin {
//TODO not thread safe
private IExtendedBlockStorageMixin ebs;
private NBTTagCompound nbt;
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B"),
require = 1)
private byte[] grabEBSBlockDataWrite(ExtendedBlockStorage instance) {
ebs = (IExtendedBlockStorageMixin) instance;
return null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V"),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getYLocation()I"),
to = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockMSBArray()Lnet/minecraft/world/chunk/NibbleArray;")),
require = 1)
private void redirectBlockDataWrite(NBTTagCompound instance, String key, byte[] value) {
Hooks.writeBlockDataToNBT(instance, ebs);
ebs = null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockMSBArray()Lnet/minecraft/world/chunk/NibbleArray;"),
require = 1)
private NibbleArray suppressVanillaBlockDataWrite(ExtendedBlockStorage instance) {
return null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
require = 1)
private NibbleArray grabEBSBlockMetaWrite(ExtendedBlockStorage instance) {
ebs = (IExtendedBlockStorageMixin) instance;
return null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/NibbleArray;data:[B",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;")),
require = 1)
private byte[] suppressEBSBlockMetaNibbleArrayAccess(NibbleArray instance) {
return null;
}
@Redirect(method = "writeChunkToNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;setByteArray(Ljava/lang/String;[B)V",
ordinal = 0),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Data")),
require = 1)
private void redirectBlockMetaWrite(NBTTagCompound instance, String p_74773_1_, byte[] p_74773_2_) {
Hooks.writeBlockMetaToNBT(ebs, instance);
ebs = null;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B",
ordinal = 0),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Blocks")),
require = 1)
private byte[] grabNBTBlockDataRead(NBTTagCompound instance, String key) {
nbt = instance;
return null;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockLSBArray([B)V"),
require = 1)
private void redirectBlockDataRead(ExtendedBlockStorage instance, byte[] p_76664_1_) {
Hooks.readBlockDataFromNBT((IExtendedBlockStorageMixin) instance, nbt);
nbt = null;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z",
ordinal = 0),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Add",
ordinal = 0)),
require = 1)
private boolean suppressVanillaBlockDataRead(NBTTagCompound instance, String key, int type) {
return false;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/nbt/NBTTagCompound;getByteArray(Ljava/lang/String;)[B",
ordinal = 0),
slice = @Slice(from = @At(value = "CONSTANT",
args = "stringValue=Data")),
require = 1)
private byte[] grabNBTBlockMetaRead(NBTTagCompound instance, String key) {
nbt = instance;
return null;
}
@Redirect(method = "readChunkFromNBT",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;setBlockMetadataArray(Lnet/minecraft/world/chunk/NibbleArray;)V"),
require = 1)
private void redirectBlockMetaRead(ExtendedBlockStorage instance, NibbleArray p_76668_1_) {
Hooks.readBlockMetaFromNBT((IExtendedBlockStorageMixin) instance, nbt);
nbt = null;
}
}
@@ -1,120 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.blockitem.vanilla;
import com.falsepattern.endlessids.Hooks;
import com.falsepattern.endlessids.mixin.helpers.IExtendedBlockStorageMixin;
import lombok.val;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.network.play.server.S21PacketChunkData;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.NibbleArray;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
@Mixin(S21PacketChunkData.class)
public abstract class S21PacketChunkDataMixin {
private static byte[][] fakeArrays;
private static NibbleArray[] fakeNarrays;
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockMSBArray()Lnet/minecraft/world/chunk/NibbleArray;",
ordinal = 0),
require = 1)
private static NibbleArray noMSB(ExtendedBlockStorage instance) {
return null;
}
@Inject(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B"),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private static void hookGetBlockData(Chunk p_149269_0_, boolean p_149269_1_, int p_149269_2_, CallbackInfoReturnable<S21PacketChunkData.Extracted> cir, int j, ExtendedBlockStorage[] aextendedblockstorage, int k, S21PacketChunkData.Extracted extracted, byte[] abyte, int l) {
val ebs = (IExtendedBlockStorageMixin) aextendedblockstorage[l];
extracted.field_150281_c |= Hooks.getBlockData(ebs, abyte, j) << (l << 1);
}
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B"),
require = 1)
private static byte[] hookGetBlockDataFakeArray(ExtendedBlockStorage instance) {
if (fakeArrays == null) {
fakeArrays = new byte[4][];
fakeArrays[0] = new byte[16 * 16 * 16 * 2 / 2];
fakeArrays[1] = new byte[16 * 16 * 16 * 3 / 2];
fakeArrays[2] = new byte[16 * 16 * 16 * 4 / 2];
fakeArrays[3] = new byte[16 * 16 * 16 * 6 / 2];
}
return fakeArrays[((IExtendedBlockStorageMixin) instance).getEBSMSBMask()];
}
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlockLSBArray()[B")),
require = 1)
private static void hookGetBlockDataNoCopy(Object src, int srcPos, Object dest, int destPos, int length) {
}
@Inject(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private static void hookGetBlockMeta(Chunk p_149269_0_, boolean p_149269_1_, int p_149269_2_, CallbackInfoReturnable<S21PacketChunkData.Extracted> cir, int j, ExtendedBlockStorage[] aextendedblockstorage, int k, S21PacketChunkData.Extracted extracted, byte[] abyte, int l) {
if (l == 0) {
extracted.field_150280_b = 0;
}
extracted.field_150280_b |= Hooks.getBlockMeta((IExtendedBlockStorageMixin) aextendedblockstorage[l], abyte, j) << (l << 1);
}
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
require = 1)
private static NibbleArray hookGetBlockMetaNoArray(ExtendedBlockStorage instance) {
if (fakeNarrays == null) {
fakeNarrays = new NibbleArray[3];
fakeNarrays[0] = new NibbleArray(new byte[]{(byte)0b01}, 0);
fakeNarrays[1] = new NibbleArray(new byte[]{(byte)0b10}, 0);
fakeNarrays[2] = new NibbleArray(new byte[]{(byte)0b100}, 0);
}
return fakeNarrays[((IExtendedBlockStorageMixin)instance).getEBSMask() - 1];
}
@Redirect(method = "func_149269_a",
at = @At(value = "FIELD",
target = "Lnet/minecraft/world/chunk/NibbleArray;data:[B",
args = "array=length"),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;"),
to = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getBlocklightArray()Lnet/minecraft/world/chunk/NibbleArray;")),
expect = 2,
require = 2)
private static int hookGetBlockMetaFakeBytesLength(byte[] array) {
return 16 * 16 * 16 * (array[0] & 0xFF) / 2;
}
@Redirect(method = "func_149269_a",
at = @At(value = "INVOKE",
target = "Ljava/lang/System;arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V",
ordinal = 0),
slice = @Slice(from = @At(value = "INVOKE",
target = "Lnet/minecraft/world/chunk/storage/ExtendedBlockStorage;getMetadataArray()Lnet/minecraft/world/chunk/NibbleArray;")),
require = 1)
private static void hookGetBlockMetaNoCopy(Object src, int srcPos, Object dest, int destPos, int length) {
}
}
@@ -1,121 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla;
import com.falsepattern.endlessids.config.GeneralConfig;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import io.netty.buffer.ByteBuf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S21PacketChunkData;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
@Mixin(S21PacketChunkData.class)
public abstract class S21PacketChunkDataMixin {
@Shadow
private static byte[] field_149286_i;
@Shadow
private int field_149280_d;
@Shadow
private byte[] field_149278_f;
@Shadow
private int field_149284_a;
@Shadow
private int field_149282_b;
@Shadow
private boolean field_149279_g;
@Shadow
private int field_149283_c;
@Shadow
private int field_149285_h;
@ModifyConstant(method = {"<clinit>", "func_149275_c"},
constant = @Constant(intValue = VanillaConstants.bytesPerChunk),
require = 1)
private static int increasePacketSize(int constant) {
return ExtendedConstants.bytesPerChunk;
}
@Inject(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 0),
require = 1)
private void extendWrite(PacketBuffer p_148840_1_, CallbackInfo ci) {
if (GeneralConfig.extendBlockItem) {
p_148840_1_.writeInt(this.field_149283_c);
p_148840_1_.writeInt(this.field_149280_d);
} else {
p_148840_1_.writeShort((short)(this.field_149283_c & 65535));
p_148840_1_.writeShort((short)(this.field_149280_d & 65535));
}
p_148840_1_.writeInt(this.field_149278_f.length);
}
@Redirect(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 0),
require = 1)
private ByteBuf suppressOldWrite1(PacketBuffer instance, int p_writeShort_1_) {
return null;
}
@Redirect(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 1),
require = 1)
private ByteBuf suppressOldWrite2(PacketBuffer instance, int p_writeShort_1_) {
return null;
}
@Inject(method = "readPacketData",
at = @At("HEAD"),
require = 1,
cancellable = true)
private void customRead(PacketBuffer data, CallbackInfo ci) throws IOException {
this.field_149284_a = data.readInt();
this.field_149282_b = data.readInt();
this.field_149279_g = data.readBoolean();
if (GeneralConfig.extendBlockItem) {
this.field_149283_c = data.readInt();
this.field_149280_d = data.readInt();
} else {
this.field_149283_c = data.readShort();
this.field_149280_d = data.readShort();
}
int length = data.readInt();
this.field_149285_h = data.readInt();
if (field_149286_i.length < this.field_149285_h) {
field_149286_i = new byte[this.field_149285_h];
}
data.readBytes(field_149286_i, 0, this.field_149285_h);
this.field_149278_f = new byte[length];
Inflater inflater = new Inflater();
inflater.setInput(field_149286_i, 0, this.field_149285_h);
try {
inflater.inflate(this.field_149278_f);
} catch (DataFormatException dataformatexception) {
throw new IOException("Bad compressed data format");
} finally {
inflater.end();
}
ci.cancel();
}
}
@@ -1,97 +0,0 @@
package com.falsepattern.endlessids.mixin.mixins.common.vanilla;
import com.falsepattern.endlessids.config.GeneralConfig;
import io.netty.buffer.ByteBuf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.server.S26PacketMapChunkBulk;
import java.util.zip.Inflater;
@Mixin(S26PacketMapChunkBulk.class)
public abstract class S26PacketMapChunkBulkMixin {
@Shadow
private int[] field_149262_d;
@Shadow
private byte[][] field_149260_f;
@Shadow
private int[] field_149266_a;
@Shadow
private int[] field_149264_b;
@Shadow
private int[] field_149265_c;
@Inject(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 1),
locals = LocalCapture.CAPTURE_FAILHARD,
require = 1)
private void extendWrite(PacketBuffer p_148840_1_, CallbackInfo ci, int i) {
if (GeneralConfig.extendBlockItem) {
p_148840_1_.writeInt(this.field_149265_c[i]);
p_148840_1_.writeInt(this.field_149262_d[i]);
} else {
p_148840_1_.writeShort((short)(this.field_149265_c[i] & 65535));
p_148840_1_.writeShort((short)(this.field_149262_d[i] & 65535));
}
p_148840_1_.writeInt(this.field_149260_f[i].length);
}
@Redirect(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 1),
require = 1)
private ByteBuf suppressOldWrite1(PacketBuffer instance, int p_writeShort_1_) {
return null;
}
@Redirect(method = "writePacketData",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/network/PacketBuffer;writeShort(I)Lio/netty/buffer/ByteBuf;",
ordinal = 2),
require = 1)
private ByteBuf suppressOldWrite2(PacketBuffer instance, int p_writeShort_1_) {
return null;
}
@Inject(method = "readPacketData",
at = @At(value = "INVOKE",
target = "Ljava/util/zip/Inflater;inflate([B)I",
shift = At.Shift.AFTER),
require = 1,
locals = LocalCapture.CAPTURE_FAILHARD,
cancellable = true)
private void customRead(PacketBuffer data, CallbackInfo ci, short short1, byte[] abyte, Inflater inflater) {
int i = 0;
for (int j = 0; j < short1; ++j) {
this.field_149266_a[j] = data.readInt();
this.field_149264_b[j] = data.readInt();
if (GeneralConfig.extendBlockItem) {
this.field_149265_c[j] = data.readInt();
this.field_149262_d[j] = data.readInt();
} else {
this.field_149265_c[j] = data.readShort();
this.field_149262_d[j] = data.readShort();
}
byte[] dataBytes = new byte[data.readInt()];
this.field_149260_f[j] = dataBytes;
System.arraycopy(abyte, i, dataBytes, 0, dataBytes.length);
i += dataBytes.length;
}
ci.cancel();
}
}
@@ -9,7 +9,6 @@ import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.function.Predicate;
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.always;
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.avoid;
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.condition;
import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.require;
@@ -17,10 +16,6 @@ import static com.falsepattern.lib.mixin.IMixin.PredicateHelpers.require;
@RequiredArgsConstructor
public enum Mixin implements IMixin {
//region common
//region vanilla
S21PacketChunkDataMixin(Side.COMMON, always(), "vanilla.S21PacketChunkDataMixin"),
S26PacketMapChunkBulkMixin(Side.COMMON, always(), "vanilla.S26PacketMapChunkBulkMixin"),
//endregion vanilla
//region AntiIDConflict
AIDCAntiIdConflictBaseMixin(Side.COMMON, require(TargetedMod.ANTIIDCONFLICT), "antiidconflict.AntiIdConflictBaseMixin"),
AIDCBiomesGenBasePlaceholderMixin(Side.COMMON, require(TargetedMod.ANTIIDCONFLICT), "antiidconflict.BiomeGenBasePlaceholderMixin"),
@@ -32,13 +27,11 @@ public enum Mixin implements IMixin {
//endregion AntiIDConflict
//region biome
//region vanilla
AnvilChunkLoaderMixinBiome(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.AnvilChunkLoaderMixin"),
BiomeDictionaryMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.BiomeDictionaryMixin"),
BiomeGenBaseMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.BiomeGenBaseMixin"),
ChunkMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.ChunkMixin"),
GenLayerRiverMixMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(avoid(TargetedMod.DRAGONAPI)), "biome.vanilla.GenLayerRiverMixMixin"),
GenLayerVoronoiZoomMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.GenLayerVoronoiZoomMixin"),
S21PacketChunkDataMixinBiome(Side.COMMON, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.S21PacketChunkDataMixin"),
//endregion vanilla
//region AbyssalCraft
AbyssalCraftMixin(Side.COMMON, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.ABYSSALCRAFT)), "biome.abyssalcraft.AbyssalCraftMixin"),
@@ -164,13 +157,11 @@ public enum Mixin implements IMixin {
//endregion biome
//region blockitem
//region vanilla
AnvilChunkLoaderMixinBlockItem(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.AnvilChunkLoaderMixin"),
BlockFireMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.BlockFireMixin"),
ExtendedBlockStorageMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.ExtendedBlockStorageMixin"),
ItemInWorldManagerMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.ItemInWorldManagerMixin"),
ItemStackMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.ItemStackMixin"),
PacketBufferMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.PacketBufferMixin"),
S21PacketChunkDataMixinBlockItem(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.S21PacketChunkDataMixin"),
S22PacketMultiBlockChangeMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.S22PacketMultiBlockChangeMixin"),
S24PacketBlockActionMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.S24PacketBlockActionMixin"),
StatListMixin(Side.COMMON, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.StatListMixin"),
@@ -219,16 +210,12 @@ public enum Mixin implements IMixin {
//region client
//region biome
//region vanilla
ChunkMixinClientBiome(Side.CLIENT, condition(() -> GeneralConfig.extendBiome), "biome.vanilla.ChunkMixin"),
//endregion vanilla
//region Biome Wand
BiomeWandItemClientMixin(Side.CLIENT, condition(() -> GeneralConfig.extendBiome).and(require(TargetedMod.BIOMEWAND)), "biome.biomewand.BiomeWandItemMixin"),
//endregion Biome Wand
//endregion biome
//region blockitem
//region vanilla
ChunkMixinClientBlockItem(Side.CLIENT, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.ChunkMixin"),
NetHandlerPlayClientMixinBlockItem(Side.CLIENT, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.NetHandlerPlayClientMixin"),
PlayerControllerMPMixin(Side.CLIENT, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.PlayerControllerMPMixin"),
RenderGlobalMixin(Side.CLIENT, condition(() -> GeneralConfig.extendBlockItem), "blockitem.vanilla.RenderGlobalMixin"),