77import net .minecraft .world .InteractionHand ;
88import net .minecraft .world .InteractionResult ;
99//? <=1.21.1
10- // import net.minecraft.world.InteractionResultHolder;
10+ import net .minecraft .world .InteractionResultHolder ;
1111import net .minecraft .world .entity .LivingEntity ;
1212import net .minecraft .world .entity .SlotAccess ;
1313import net .minecraft .world .entity .player .Player ;
1919import net .minecraft .world .item .SpyglassItem ;
2020import net .minecraft .world .item .TooltipFlag ;
2121//? if >1.21.1
22- import net .minecraft .world .item .component .TooltipDisplay ;
22+ // import net.minecraft.world.item.component.TooltipDisplay;
2323import net .minecraft .world .item .enchantment .EnchantmentHelper ;
2424import net .minecraft .world .level .Level ;
2525import net .minecraft .world .level .block .state .BlockState ;
@@ -60,13 +60,13 @@ protected void insertOrExtractSpyglass(ItemStack stack, ItemStack otherStack, Sl
6060
6161 @ Override
6262 //? if <=1.21.1 {
63- /* protected void preventMining(BlockState state, Level world, BlockPos pos, Player miner, CallbackInfoReturnable<Boolean> cir) {
64- */ //?} else {
65- protected void preventMining (ItemStack tool , BlockState state , Level level , BlockPos pos , LivingEntity living , CallbackInfoReturnable <Boolean > cir ) {
63+ protected void preventMining (BlockState state , Level world , BlockPos pos , Player miner , CallbackInfoReturnable <Boolean > cir ) {
64+ //?} else {
65+ /* protected void preventMining(ItemStack tool, BlockState state, Level level, BlockPos pos, LivingEntity living, CallbackInfoReturnable<Boolean> cir) {
6666 if (!(living instanceof Player miner)) {
6767 return;
6868 }
69- //?}
69+ */ //?}
7070 miner .crossbow_scoping$setAttacking (true );
7171 ItemStack stack = CrossbowScoping .getCrossbowWithScope (miner ).getFirst ();
7272 miner .crossbow_scoping$setAttacking (false );
@@ -77,7 +77,7 @@ protected void preventMining(ItemStack tool, BlockState state, Level level, Bloc
7777 }
7878
7979 @ Inject (method = "use" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/item/CrossbowItem;performShooting(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/item/ItemStack;FFLnet/minecraft/world/entity/LivingEntity;)V" , shift = At .Shift .BEFORE ), cancellable = true )
80- private void scopeInsteadOfShooting (Level world , Player user , InteractionHand hand , CallbackInfoReturnable </*? <=1.21.1 {*/ /* InteractionResultHolder<ItemStack> */ / *?} else {*/ InteractionResult /*?}*/ > cir , @ Local ItemStack stack ) {
80+ private void scopeInsteadOfShooting (Level world , Player user , InteractionHand hand , CallbackInfoReturnable </*? <=1.21.1 {*/ InteractionResultHolder <ItemStack > / *?} else {*/ /* InteractionResult */ /*?}*/ > cir , @ Local ItemStack stack ) {
8181 if (stack .has (LOADING_PHASE )) {
8282 stack .remove (LOADING_PHASE );
8383 }
@@ -87,31 +87,31 @@ private void scopeInsteadOfShooting(Level world, Player user, InteractionHand ha
8787 user .releaseUsingItem ();
8888 }
8989 if (EnchantmentHelper .hasTag (stack , CrossbowScopingTags .USES_EXTENDED_COOLDOWN )) {
90- user .getCooldowns ().addCooldown (stack /*? <=1.21.1 {*/ /* .getItem() */ /*?}*/ , 11 );
90+ user .getCooldowns ().addCooldown (stack /*? <=1.21.1 {*/ .getItem () /*?}*/ , 11 );
9191 } else {
92- user .getCooldowns ().addCooldown (stack /*? <=1.21.1 {*/ /* .getItem() */ /*?}*/ , 5 );
92+ user .getCooldowns ().addCooldown (stack /*? <=1.21.1 {*/ .getItem () /*?}*/ , 5 );
9393 }
9494 return ;
9595 }
9696 ItemStack stackInComponents = stack .getOrDefault (CROSSBOW_SCOPE , ItemStack .EMPTY );
9797 if (!stackInComponents .isEmpty () && stackInComponents .getItem () instanceof SpyglassItem ) {
98- if (user .getCooldowns ().isOnCooldown (stack /*? <=1.21.1 {*/ /* .getItem() */ /*?}*/ )) {
99- cir .setReturnValue (/*? <=1.21.1 {*/ /* InteractionResultHolder.pass(stack) */ / *?} else {*/ InteractionResult .PASS /*?}*/ );
98+ if (user .getCooldowns ().isOnCooldown (stack /*? <=1.21.1 {*/ .getItem () /*?}*/ )) {
99+ cir .setReturnValue (/*? <=1.21.1 {*/ InteractionResultHolder .pass (stack ) / *?} else {*/ /* InteractionResult.PASS */ /*?}*/ );
100100 return ;
101101 }
102102 user .crossbow_scoping$setStartingToScope (stackInComponents );
103- /*? <=1.21.1 {*/ /* InteractionResultHolder<ItemStack> */ / *?} else {*/ InteractionResult /*?}*/ result = stackInComponents .use (world , user , hand );
103+ /*? <=1.21.1 {*/ InteractionResultHolder <ItemStack > / *?} else {*/ /* InteractionResult */ /*?}*/ result = stackInComponents .use (world , user , hand );
104104 user .crossbow_scoping$setStartingToScope (ItemStack .EMPTY );
105105 ItemStack value ;
106106 //? if <=1.21.1 {
107- /* value = result.getObject();
108- */ //?} else {
109- if (result instanceof InteractionResult .Success success ) {
107+ value = result .getObject ();
108+ //?} else {
109+ /* if (result instanceof InteractionResult.Success success) {
110110 value = Objects.requireNonNullElse(success.heldItemTransformedTo(), stackInComponents);
111111 } else {
112112 value = stackInComponents;
113113 }
114- //?}
114+ */ //?}
115115 if (!ItemStack .matches (stackInComponents , value )) {
116116 if (value .isEmpty ()) {
117117 stack .remove (CROSSBOW_SCOPE );
@@ -120,29 +120,29 @@ private void scopeInsteadOfShooting(Level world, Player user, InteractionHand ha
120120 }
121121 }
122122 //? if <=1.21.1 {
123- /*/ /noinspection unchecked
123+ //noinspection unchecked
124124 ((TypedActionResultAccessor <ItemStack >) result ).crossbow_scoping$setValue (stack );
125- */ //?}
125+ //?}
126126 cir .setReturnValue (result );
127127 }
128128 }
129129
130130 @ Inject (method = "use" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/entity/player/Player;startUsingItem(Lnet/minecraft/world/InteractionHand;)V" ))
131- private void setWasLoading (Level world , Player user , InteractionHand hand , CallbackInfoReturnable </*? <=1.21.1 {*/ /* InteractionResultHolder<ItemStack> */ / *?} else {*/ InteractionResult /*?}*/ > cir , @ Local ItemStack stack ) {
131+ private void setWasLoading (Level world , Player user , InteractionHand hand , CallbackInfoReturnable </*? <=1.21.1 {*/ InteractionResultHolder <ItemStack > / *?} else {*/ /* InteractionResult */ /*?}*/ > cir , @ Local ItemStack stack ) {
132132 stack .set (LOADING_PHASE , Unit .INSTANCE );
133133 }
134134
135135 //? if <=1.21.1 {
136- /* @Inject(method = "appendHoverText", at = @At("HEAD"))
136+ @ Inject (method = "appendHoverText" , at = @ At ("HEAD" ))
137137 private void appendScopeInTooltip (ItemStack stack , Item .TooltipContext context , List <Component > tooltip , TooltipFlag type , CallbackInfo ci ) {
138- */ //?} else {
139- @ Override
138+ //?} else {
139+ /* @Override
140140 protected void appendScopeInTooltip(ItemStack stack, Item.TooltipContext context, TooltipDisplay tooltipDisplay, Consumer<Component> tooltipAdder, TooltipFlag flag, CallbackInfo ci) {
141- //?}
141+ */ //?}
142142 ItemStack stackInComponents = stack .getOrDefault (CROSSBOW_SCOPE , ItemStack .EMPTY );
143143 if (!stackInComponents .isEmpty ()) {
144144 Component text = stackInComponents .getHoverName ();
145- /*? <=1.21.1 {*/ /* tooltip.add */ / *?} else {*/ tooltipAdder .accept /*?}*/ (Component .translatable ("item.crossbow_scoping.crossbow.scope" , text ).setStyle (text .getStyle ()));
145+ /*? <=1.21.1 {*/ tooltip .add / *?} else {*/ /* tooltipAdder.accept */ /*?}*/ (Component .translatable ("item.crossbow_scoping.crossbow.scope" , text ).setStyle (text .getStyle ()));
146146 }
147147 }
148148}
0 commit comments