2022-09-18 01:23:29 +02:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2022-10-12 10:40:36 +02:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2022-09-28 22:43:45 +02:00
|
|
|
import com.minelittlepony.unicopia.advancement.UCriteria;
|
2023-04-30 11:46:33 +02:00
|
|
|
import com.minelittlepony.unicopia.server.world.DragonBreathStore;
|
2023-09-09 19:46:41 +02:00
|
|
|
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
|
2022-09-18 01:23:29 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2023-09-09 19:46:41 +02:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2022-09-18 01:23:29 +02:00
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.TypedActionResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class DragonBreathScrollItem extends Item {
|
|
|
|
|
|
|
|
public DragonBreathScrollItem(Settings settings) {
|
|
|
|
super(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
|
|
|
ItemStack stack = player.getStackInHand(hand);
|
|
|
|
ItemStack payload = player.getStackInHand(hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND);
|
|
|
|
|
|
|
|
if (payload.isEmpty() || !stack.hasCustomName()) {
|
|
|
|
return TypedActionResult.fail(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
stack.split(1);
|
|
|
|
if (!world.isClient) {
|
2023-09-09 19:46:41 +02:00
|
|
|
String recipient = stack.getName().getString();
|
|
|
|
UCriteria.SEND_DRAGON_BREATH.triggerSent(player, payload, recipient, (counterName, count) -> {
|
|
|
|
if (count == 1 && "dings_on_celestias_head".equals(counterName)) {
|
|
|
|
UnicopiaWorldProperties properties = UnicopiaWorldProperties.forWorld((ServerWorld)world);
|
|
|
|
properties.setTangentalSkyAngle(properties.getTangentalSkyAngle() + 15);
|
|
|
|
player.playSound(USounds.Vanilla.BLOCK_ANVIL_HIT, 0.3F, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
DragonBreathStore.get(world).put(recipient, payload.split(1));
|
2022-09-18 01:23:29 +02:00
|
|
|
}
|
2022-10-12 10:40:36 +02:00
|
|
|
player.playSound(USounds.ITEM_DRAGON_BREATH_SCROLL_USE, 1, 1);
|
2022-09-18 01:23:29 +02:00
|
|
|
return TypedActionResult.consume(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack setRecipient(ItemStack stack, UUID recipient) {
|
|
|
|
stack.getOrCreateSubNbt("recipient").putUuid("id", recipient);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
}
|