Skip to content

Commit

Permalink
Fix compatibility with ItemFavourites (and likely other mods with bad…
Browse files Browse the repository at this point in the history
… packet format changing mixins)
  • Loading branch information
Patbox committed Aug 20, 2023
1 parent 3bde037 commit 1fd0bc5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.83.0+1.20.1

maven_group = eu.pb4

mod_version = 0.5.11
mod_version = 0.5.12

minecraft_version_supported = ">=1.20-"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.function.Predicate;

public final class PolymerBlockUtils {
private static final NbtCompound STATIC_COMPOUND = new NbtCompound();

private PolymerBlockUtils() {
}

Expand Down Expand Up @@ -246,8 +248,8 @@ public static Block getBlockSafely(PolymerBlock block, BlockState state) {
return getBlockSafely(block, state, NESTED_DEFAULT_DISTANCE);
}

public static BlockEntityUpdateS2CPacket createBlockEntityPacket(BlockPos pos, BlockEntityType<?> type, NbtCompound nbtCompound) {
return BlockEntityUpdateS2CPacketAccessor.createBlockEntityUpdateS2CPacket(pos.toImmutable(), type, nbtCompound);
public static BlockEntityUpdateS2CPacket createBlockEntityPacket(BlockPos pos, BlockEntityType<?> type, @Nullable NbtCompound nbtCompound) {
return BlockEntityUpdateS2CPacketAccessor.createBlockEntityUpdateS2CPacket(pos.toImmutable(), type, nbtCompound != null ? nbtCompound : STATIC_COMPOUND);
}

@ApiStatus.Experimental
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.pb4.polymer.core.mixin.item.packet;

import eu.pb4.polymer.common.impl.client.ClientUtils;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import eu.pb4.polymer.common.api.PolymerCommonUtils;
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
Expand Down Expand Up @@ -38,9 +39,9 @@ public abstract class PacketByteBufMixin {
}

@Environment(EnvType.SERVER)
@Inject(method = "readItemStack", at = @At("RETURN"), cancellable = true)
private void polymer$decodeItemStackServer(CallbackInfoReturnable<ItemStack> cir) {
cir.setReturnValue(PolymerItemUtils.getRealItemStack(cir.getReturnValue()));
@ModifyReturnValue(method = "readItemStack", at = @At(value = "RETURN", ordinal = 1))
private ItemStack polymerCore$decodeItemStackServer(ItemStack stack) {
return (PolymerItemUtils.getRealItemStack(stack));
}

@Environment(EnvType.CLIENT)
Expand All @@ -50,9 +51,8 @@ public abstract class PacketByteBufMixin {
}

@Environment(EnvType.CLIENT)
@Inject(method = "readItemStack", at = @At("TAIL"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void polymer$decodeItemStackClient(CallbackInfoReturnable<ItemStack> cir, Item decodedItem, int i, ItemStack itemStack) {
ItemStack stack = cir.getReturnValue();
@ModifyReturnValue(method = "readItemStack", at = @At(value = "RETURN", ordinal = 1))
private ItemStack polymerCore$decodeItemStackClient(ItemStack stack) {
var currentIndex = this.readerIndex();
this.readerIndex(this.polymer$readerIndex);
var rawId = this.readVarInt();
Expand All @@ -62,15 +62,12 @@ public abstract class PacketByteBufMixin {
var item = InternalClientRegistry.ITEMS.get(rawId);

if (item != null) {
var count = stack.getCount();

stack = item.visualStack().copy();
stack.setCount(count);

cir.setReturnValue(stack);
return item.visualStack().copyWithCount(stack.getCount());
}
} else if (PolymerUtils.isOnPlayerNetworking() && !ClientUtils.isClientThread()) {
cir.setReturnValue(PolymerItemUtils.getRealItemStack(stack));
} else if (PolymerCommonUtils.isNetworkingThread()) {
return PolymerItemUtils.getRealItemStack(stack);
}

return stack;
}
}

0 comments on commit 1fd0bc5

Please sign in to comment.