Skip to content

Commit

Permalink
Fix even not firing for vanilla and items visible clientside as block…
Browse files Browse the repository at this point in the history
…s creating ghost blocks
  • Loading branch information
Patbox committed Jul 7, 2021
1 parent e6e2b6a commit e0d21a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.3

# Mod Properties
mod_version = 0.1.0-pre7+1.17.1
mod_version = 0.1.0-pre8+1.17.1
maven_group = eu.pb4
archives_base_name = polymer

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/eu/pb4/polymer/item/ItemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class ItemHelper {
public static final BooleanEvent<ItemStack> VIRTUAL_ITEM_CHECK = new BooleanEvent<>();

public static ItemStack getVirtualItemStack(ItemStack itemStack, ServerPlayerEntity player) {
if (itemStack.getItem() instanceof VirtualItem) {
VirtualItem item = (VirtualItem) itemStack.getItem();
if (itemStack.getItem() instanceof VirtualItem item) {
return item.getVirtualItemStack(itemStack, player);
} else if (itemStack.hasEnchantments()) {
for (NbtElement enchantment : itemStack.getEnchantments()) {
Expand All @@ -62,7 +61,9 @@ public static ItemStack getVirtualItemStack(ItemStack itemStack, ServerPlayerEnt
return createBasicVirtualItemStack(itemStack, player);
}
}
} else if (VIRTUAL_ITEM_CHECK.invoke(itemStack)) {
}

if (VIRTUAL_ITEM_CHECK.invoke(itemStack)) {
return createBasicVirtualItemStack(itemStack, player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

// Modified version of PolyMC mixin - https://github.com/TheEpicBlock/PolyMc/blob/master/src/main/java/io/github/theepicblock/polymc/mixins/block/BlockBreakingPatch.java
// Part of this mixin is based on https://github.com/TheEpicBlock/PolyMc/blob/master/src/main/java/io/github/theepicblock/polymc/mixins/block/BlockBreakingPatch.java

@Mixin(ServerPlayerInteractionManager.class)
public abstract class ServerPlayerInteractionManagerMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import eu.pb4.polymer.item.VirtualItem;
import net.minecraft.item.BlockItem;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand Down Expand Up @@ -34,6 +36,8 @@ public abstract class ServerPlayNetworkHandlerMixin {
@Shadow
public abstract void sendPacket(Packet<?> packet);

@Shadow public abstract void onPlayerInteractItem(PlayerInteractItemC2SPacket packet);

@Inject(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V", shift = At.Shift.AFTER))
private void resendToolIfItsBlockClientSide(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {
ItemStack itemStack = this.player.getStackInHand(packet.getHand());
Expand All @@ -44,13 +48,7 @@ private void resendToolIfItsBlockClientSide(PlayerInteractBlockC2SPacket packet,
}

@Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 0))
private void replaceOriginalCall1(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet<?> packet) {
}

@Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/Packet;)V", ordinal = 1))
private void replaceOriginalCall2(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet<?> packet) {
}

private void replaceOriginalCall(ServerPlayNetworkHandler serverPlayNetworkHandler, Packet<?> packet) {}

@Inject(method = "onPlayerInteractBlock", at = @At("TAIL"))
private void updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) {
Expand All @@ -59,6 +57,13 @@ private void updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo
for (Direction direction : Direction.values()) {
this.player.networkHandler.sendPacket(new BlockUpdateS2CPacket(this.player.world, base.offset(direction)));
}

ItemStack stack = this.player.getStackInHand(packet.getHand());
Item item = stack.getItem();

if (stack.getItem() instanceof VirtualItem && !(item instanceof BlockItem || item instanceof BucketItem)) {
this.onPlayerInteractItem(new PlayerInteractItemC2SPacket(packet.getHand()));
}
}

@Unique
Expand Down

0 comments on commit e0d21a5

Please sign in to comment.