|
| 1 | +/* |
| 2 | + * Minecraft Forge, Patchwork Project |
| 3 | + * Copyright (c) 2016-2020, 2019-2020 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation version 2.1 |
| 8 | + * of the License. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package net.patchworkmc.mixin.event.entity; |
| 21 | + |
| 22 | +import java.util.List; |
| 23 | + |
| 24 | +import net.minecraftforge.common.MinecraftForge; |
| 25 | +import net.minecraftforge.event.entity.player.ItemFishedEvent; |
| 26 | +import org.spongepowered.asm.mixin.Mixin; |
| 27 | +import org.spongepowered.asm.mixin.Shadow; |
| 28 | +import org.spongepowered.asm.mixin.Unique; |
| 29 | +import org.spongepowered.asm.mixin.injection.At; |
| 30 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 31 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 32 | +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
| 33 | + |
| 34 | +import net.minecraft.entity.projectile.FishingBobberEntity; |
| 35 | +import net.minecraft.item.ItemStack; |
| 36 | +import net.minecraft.loot.LootTable; |
| 37 | +import net.minecraft.loot.context.LootContext; |
| 38 | + |
| 39 | +@Mixin(FishingBobberEntity.class) |
| 40 | +public abstract class MixinFishingBobberEntity { |
| 41 | + @Shadow |
| 42 | + private boolean field_7176; // is stuck to block |
| 43 | + |
| 44 | + @Shadow |
| 45 | + public abstract void remove(); |
| 46 | + |
| 47 | + @Unique |
| 48 | + private final ThreadLocal<Integer> rodDamage = ThreadLocal.withInitial(() -> -1); |
| 49 | + |
| 50 | + @Inject(method = "method_6957", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancement/criterion/FishingRodHookedCriterion;trigger(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/projectile/FishingBobberEntity;Ljava/util/Collection;)V", ordinal = 1), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) |
| 51 | + private void onReeledIn(ItemStack itemStack, CallbackInfoReturnable<Integer> cir, int i, LootContext.Builder builder, LootTable lootTable, List<ItemStack> list) { |
| 52 | + ItemFishedEvent event = new ItemFishedEvent(list, this.field_7176 ? 2 : 1, (FishingBobberEntity) (Object) this); |
| 53 | + MinecraftForge.EVENT_BUS.post(event); |
| 54 | + |
| 55 | + if (event.isCanceled()) { |
| 56 | + this.remove(); |
| 57 | + cir.setReturnValue(event.getRodDamage()); |
| 58 | + } else { |
| 59 | + rodDamage.set(event.getRodDamage()); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + @Inject(method = "method_6957", at = @At("RETURN"), cancellable = true) |
| 64 | + private void onRodDamage(ItemStack itemStack, CallbackInfoReturnable<Integer> cir) { |
| 65 | + Integer damage = rodDamage.get(); |
| 66 | + |
| 67 | + if (damage != -1) { |
| 68 | + cir.setReturnValue(damage); |
| 69 | + rodDamage.set(-1); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments