Fix duplicated swing animations on high-ping servers

Use `InteractionResult.sidedSuccess` / `.CONSUME` where applicable instead of `.SUCCESS`. This prevents the server from sending an additional swing animation packet to the client. Normally this isn't a problem, since the client will de-duplicate swing packets if they are within the animation duration of the currently playing swing; however, when connected to a server with a high ping the packet is sent after the animation is already finished on the client, resulting in a duplicate animation.
This commit is contained in:
emmachase 2022-12-19 19:53:41 -08:00
parent 9d394f44d3
commit 172d1824fc
8 changed files with 12 additions and 12 deletions

View File

@ -98,7 +98,7 @@ public InteractionResult use(Player player, InteractionHand hand) {
setLabel(currentItem.getHoverName().getString());
currentItem.shrink(1);
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(getLevel().isClientSide);
} else if (!player.isCrouching()) {
// Regular right click to activate computer
if (!getLevel().isClientSide && isUsable(player)) {
@ -110,7 +110,7 @@ public InteractionResult use(Player player, InteractionHand hand) {
: ItemStack.EMPTY;
new ComputerContainerData(computer, stack).open(player, this);
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(getLevel().isClientSide);
}
return InteractionResult.PASS;
}

View File

@ -56,7 +56,7 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera
new HeldItemContainerData(hand)
.open(player, new HeldItemMenu.Factory(ModRegistry.Menus.PRINTOUT.get(), player.getItemInHand(hand), hand));
}
return new InteractionResultHolder<>(InteractionResult.SUCCESS, player.getItemInHand(hand));
return new InteractionResultHolder<>(InteractionResult.sidedSuccess(world.isClientSide), player.getItemInHand(hand));
}
private ItemStack createFromTitleAndText(@Nullable String title, @Nullable String[] text, @Nullable String[] colours) {

View File

@ -193,7 +193,7 @@ InteractionResult use(Player player) {
}
}
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
@Override

View File

@ -78,7 +78,7 @@ public InteractionResult place(BlockPlaceContext context) {
.setValue(CONNECTIONS.get(side), existingState.getValue(CABLE));
if (placeAt(world, pos, newState)) {
stack.shrink(1);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(world.isClientSide);
}
}
@ -105,7 +105,7 @@ public InteractionResult place(BlockPlaceContext context) {
if (insideState.getBlock() == ModRegistry.Blocks.CABLE.get() && !insideState.getValue(CableBlock.CABLE)
&& placeAtCorrected(world, insidePos, insideState.setValue(CableBlock.CABLE, true))) {
stack.shrink(1);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(world.isClientSide);
}
// Try to add a cable to a modem adjacent to this block
@ -113,7 +113,7 @@ && placeAtCorrected(world, insidePos, insideState.setValue(CableBlock.CABLE, tru
if (existingState.getBlock() == ModRegistry.Blocks.CABLE.get() && !existingState.getValue(CableBlock.CABLE)
&& placeAtCorrected(world, pos, existingState.setValue(CableBlock.CABLE, true))) {
stack.shrink(1);
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(world.isClientSide);
}
return super.place(context);

View File

@ -139,7 +139,7 @@ public InteractionResult use(Player player) {
sendPeripheralChanges(player, "chat.computercraft.wired_modem.peripheral_connected", periphNames);
}
return InteractionResult.SUCCESS;
return InteractionResult.CONSUME;
}
private static void sendPeripheralChanges(Player player, String kind, Collection<String> peripherals) {

View File

@ -110,7 +110,7 @@ public final InteractionResult use(BlockState state, Level level, BlockPos pos,
);
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(level.isClientSide);
}
@Override

View File

@ -141,7 +141,7 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera
new ComputerContainerData(computer, stack).open(player, new PocketComputerMenuProvider(computer, stack, this, hand, isTypingOnly));
}
}
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
return new InteractionResultHolder<>(InteractionResult.sidedSuccess(world.isClientSide), stack);
}
@Override

View File

@ -104,7 +104,7 @@ public InteractionResult use(Player player, InteractionHand hand) {
}
}
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(getLevel().isClientSide);
} else if (currentItem.getItem() == Items.WATER_BUCKET && brain.getColour() != -1) {
// Water to remove turtle colour
if (!getLevel().isClientSide) {
@ -116,7 +116,7 @@ public InteractionResult use(Player player, InteractionHand hand) {
}
}
}
return InteractionResult.SUCCESS;
return InteractionResult.sidedSuccess(getLevel().isClientSide);
}
}