mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-22 11:56:21 +01:00
Implement item interaction logic in <= 1.8
Supersedes https://github.com/ViaVersion/ViaFabricPlus/pull/508 Closes https://github.com/ViaVersion/ViaFabricPlus/issues/496
This commit is contained in:
parent
3ee21d7fb3
commit
e5ba1c7130
@ -57,6 +57,7 @@ import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
@ -228,6 +229,23 @@ public abstract class MixinClientPlayerInteractionManager implements IClientPlay
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "method_41929", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/TypedActionResult;getResult()Lnet/minecraft/util/ActionResult;"))
|
||||
private ActionResult eitherSuccessOrPass(TypedActionResult<ItemStack> instance, @Local(ordinal = 0) ItemStack itemStack) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
// In <= 1.8, ActionResult weren't a thing and interactItem simply returned either true or false
|
||||
// depending on if the input and output item are equal or not
|
||||
final boolean accepted = instance.getValue() != itemStack;
|
||||
|
||||
if (instance.getResult().isAccepted() == accepted) {
|
||||
return instance.getResult();
|
||||
} else {
|
||||
return accepted ? ActionResult.SUCCESS : ActionResult.PASS;
|
||||
}
|
||||
} else {
|
||||
return instance.getResult();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "method_41929", at = @At("HEAD"))
|
||||
private void trackLastUsedItem(Hand hand, PlayerEntity playerEntity, MutableObject<ActionResult> mutableObject, int sequence, CallbackInfoReturnable<Packet<?>> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
|
Loading…
Reference in New Issue
Block a user