mod for the islanders smp
1package net.radsteve.islanders.mixin;
2
3import com.llamalad7.mixinextras.sugar.Local;
4import net.minecraft.entity.EquipmentSlot;
5import net.minecraft.entity.LivingEntity;
6import net.minecraft.entity.decoration.ArmorStandEntity;
7import net.minecraft.entity.player.PlayerEntity;
8import net.minecraft.item.ItemStack;
9import net.minecraft.server.network.ServerPlayerEntity;
10import net.minecraft.util.ActionResult;
11import net.minecraft.util.Hand;
12import net.minecraft.util.math.Vec3d;
13import net.radsteve.islanders.SpecialItem;
14import org.spongepowered.asm.mixin.Mixin;
15import org.spongepowered.asm.mixin.Shadow;
16import org.spongepowered.asm.mixin.injection.At;
17import org.spongepowered.asm.mixin.injection.Inject;
18import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
19
20@Mixin(ArmorStandEntity.class)
21public abstract class ArmorStandEntityMixin {
22 @Shadow
23 protected abstract EquipmentSlot getSlotFromPosition(Vec3d hitPos);
24
25 @Inject(method = "interactAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;equip(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/entity/EquipmentSlot;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Hand;)Z", ordinal = 1))
26 private void islanders$interactAt$glowingEnable(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfoReturnable<ActionResult> cir, @Local ItemStack stack) {
27 final SpecialItem item = SpecialItem.Companion.find(stack);
28 if (item == null) {
29 return;
30 }
31
32 item.dropped((ServerPlayerEntity) player, true);
33
34 final LivingEntity entity = LivingEntity.class.cast(this);
35 entity.setGlowing(true);
36 entity.getWorld().getScoreboard().addScoreHolderToTeam(entity.getNameForScoreboard(), item.getTeam());
37 }
38
39 @Inject(method = "interactAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z"))
40 private void islanders$interactAt$glowingDisable(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfoReturnable<ActionResult> cir) {
41 final LivingEntity entity = LivingEntity.class.cast(this);
42 final EquipmentSlot hitSlot = getSlotFromPosition(hitPos);
43 final ItemStack stack = entity.getEquippedStack(hitSlot);
44
45 final SpecialItem item = SpecialItem.Companion.find(stack);
46 if (item == null) {
47 return;
48 }
49
50 item.pickedUp((ServerPlayerEntity) player);
51
52 boolean containsMoreSpecialItems = false;
53 for (final EquipmentSlot slot : EquipmentSlot.values()) {
54 final ItemStack content = ((LivingEntityAccessor) entity).getEquipment().get(slot);
55 final SpecialItem itemContent = SpecialItem.Companion.find(content);
56 if (itemContent != null && !itemContent.getId().contentEquals(item.getId())) {
57 containsMoreSpecialItems = true;
58 break;
59 }
60 }
61
62 if (!containsMoreSpecialItems) {
63 entity.setGlowing(false);
64 }
65 }
66}