Fix wrappedblockstate not working on 1.12

This commit is contained in:
libraryaddict 2025-01-06 04:16:58 +13:00
parent 456ca8eefc
commit c49eb5b575
5 changed files with 29 additions and 8 deletions

View File

@ -26,7 +26,7 @@ public class EndermanWatcher extends InsentientWatcher {
}
if (!NmsVersion.v1_13.isSupported()) {
return ReflectionManager.getItemStackByCombinedId(value.getGlobalId());
return ReflectionManager.getItemStackByCombinedId(ReflectionManager.getCombinedIdByWrappedBlockState(value));
}
MaterialData pair = SpigotConversionUtil.toBukkitMaterialData(value);

View File

@ -98,12 +98,12 @@ public class FallingBlockWatcher extends FlagWatcher {
@MethodMappedAs("getBlock")
public WrappedBlockState getBlockState() {
return WrappedBlockState.getByGlobalId(getBlockCombinedId());
return ReflectionManager.getWrapepdBlockStateByCombinedId(getBlockCombinedId());
}
@MethodMappedAs("setBlock")
public void setBlockState(WrappedBlockState state) {
setBlockCombinedId(state.getType().getName(), state.getGlobalId());
setBlockCombinedId(state.getType().getName(), ReflectionManager.getCombinedIdByWrappedBlockState(state));
}
@NmsAddedIn(NmsVersion.v1_13)

View File

@ -36,11 +36,12 @@ public class MinecartWatcher extends FlagWatcher {
}
public WrappedBlockState getBlock() {
return WrappedBlockState.getByGlobalId(getData(MetaIndex.MINECART_BLOCK));
return ReflectionManager.getWrapepdBlockStateByCombinedId(getData(MetaIndex.MINECART_BLOCK));
}
public void setBlock(WrappedBlockState state) {
setData(MetaIndex.MINECART_BLOCK, state == null || state.getType() == StateTypes.AIR ? 0 : state.getGlobalId());
setData(MetaIndex.MINECART_BLOCK,
state == null || state.getType() == StateTypes.AIR ? 0 : ReflectionManager.getCombinedIdByWrappedBlockState(state));
setData(MetaIndex.MINECART_BLOCK_VISIBLE, state != null && state.getType() != StateTypes.AIR);
sendData(MetaIndex.MINECART_BLOCK, MetaIndex.MINECART_BLOCK_VISIBLE);

View File

@ -12,6 +12,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import java.lang.reflect.Type;
@ -40,6 +41,6 @@ public class SerializerWrappedBlockData implements JsonSerializer<WrappedBlockSt
int combinedID = stateType.getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion()) << 4 | data;
return WrappedBlockState.getByGlobalId(combinedID);
return ReflectionManager.getWrapepdBlockStateByCombinedId(combinedID);
}
}

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities.reflection;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.entity.armadillo.ArmadilloState;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
@ -12,6 +13,7 @@ import com.github.retrooper.packetevents.protocol.player.UserProfile;
import com.github.retrooper.packetevents.protocol.sound.SoundCategory;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;
import com.github.retrooper.packetevents.util.Vector3f;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
@ -1481,7 +1483,7 @@ public class ReflectionManager {
} else if (index.isItemStack()) {
return (T) DisguiseUtilities.toBukkitItemStack((com.github.retrooper.packetevents.protocol.item.ItemStack) value);
} else if (index.isBlock() || index.isBlockOpt()) {
return (T) WrappedBlockState.getByGlobalId((int) value);
return (T) ReflectionManager.getWrapepdBlockStateByCombinedId((int) value);
/* BlockData data = getBlockDataByCombinedId((int) value);
return (T) SpigotConversionUtil.fromBukkitBlockData(data);*/
@ -1542,7 +1544,7 @@ public class ReflectionManager {
}
if (value instanceof WrappedBlockState) {
return ((WrappedBlockState) value).getGlobalId();
return ReflectionManager.getCombinedIdByWrappedBlockState((WrappedBlockState) value);
}
if (NmsVersion.v1_14.isSupported()) {
@ -1882,6 +1884,23 @@ public class ReflectionManager {
return 0;
}
public static int getCombinedIdByWrappedBlockState(WrappedBlockState state) {
if (NmsVersion.v1_13.isSupported()) {
return state.getType().getMapped().getId(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion());
}
return state.getGlobalId();
}
public static WrappedBlockState getWrapepdBlockStateByCombinedId(int combinedId) {
if (NmsVersion.v1_13.isSupported()) {
return WrappedBlockState.getByGlobalId(combinedId);
}
return StateTypes.getById(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(), combinedId)
.createBlockState(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion());
}
public static int getCombinedIdByItemStack(ItemStack itemStack) {
if (nmsReflection != null) {
return nmsReflection.getCombinedIdByItemStack(itemStack);