121 lines
4.5 KiB
Java
121 lines
4.5 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import java.util.Comparator;
|
|
import java.util.Arrays;
|
|
import net.minecraft.nbt.ListTag;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import java.util.Collection;
|
|
import net.minecraft.network.chat.TextComponent;
|
|
import com.google.common.collect.Lists;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import net.minecraft.network.chat.Component;
|
|
import java.util.List;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
public class FireworkRocketItem extends Item {
|
|
public FireworkRocketItem(final Properties a) {
|
|
super(a);
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult useOn(final UseOnContext bfw) {
|
|
final Level bjt3 = bfw.getLevel();
|
|
if (!bjt3.isClientSide) {
|
|
final ItemStack bek4 = bfw.getItemInHand();
|
|
final Vec3 cvi5 = bfw.getClickLocation();
|
|
final Direction fp6 = bfw.getClickedFace();
|
|
final FireworkRocketEntity ayr7 = new FireworkRocketEntity(bjt3, cvi5.x + fp6.getStepX() * 0.15, cvi5.y + fp6.getStepY() * 0.15, cvi5.z + fp6.getStepZ() * 0.15, bek4);
|
|
bjt3.addFreshEntity(ayr7);
|
|
bek4.shrink(1);
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
|
|
if (ayg.isFallFlying()) {
|
|
final ItemStack bek5 = ayg.getItemInHand(ajh);
|
|
if (!bjt.isClientSide) {
|
|
bjt.addFreshEntity(new FireworkRocketEntity(bjt, bek5, ayg));
|
|
if (!ayg.abilities.instabuild) {
|
|
bek5.shrink(1);
|
|
}
|
|
}
|
|
return InteractionResultHolder.<ItemStack>success(ayg.getItemInHand(ajh));
|
|
}
|
|
return InteractionResultHolder.<ItemStack>pass(ayg.getItemInHand(ajh));
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(final ItemStack bek, @Nullable final Level bjt, final List<Component> list, final TooltipFlag bft) {
|
|
final CompoundTag jt6 = bek.getTagElement("Fireworks");
|
|
if (jt6 == null) {
|
|
return;
|
|
}
|
|
if (jt6.contains("Flight", 99)) {
|
|
list.add(new TranslatableComponent("item.minecraft.firework_rocket.flight", new Object[0]).append(" ").append(String.valueOf(jt6.getByte("Flight"))).withStyle(ChatFormatting.GRAY));
|
|
}
|
|
final ListTag jz7 = jt6.getList("Explosions", 10);
|
|
if (!jz7.isEmpty()) {
|
|
for (int integer8 = 0; integer8 < jz7.size(); ++integer8) {
|
|
final CompoundTag jt7 = jz7.getCompound(integer8);
|
|
final List<Component> list2 = Lists.newArrayList();
|
|
FireworkStarItem.appendHoverText(jt7, list2);
|
|
if (!list2.isEmpty()) {
|
|
for (int integer9 = 1; integer9 < list2.size(); ++integer9) {
|
|
list2.set(integer9, new TextComponent(" ").append(list2.get(integer9)).withStyle(ChatFormatting.GRAY));
|
|
}
|
|
list.addAll(list2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum Shape {
|
|
SMALL_BALL(0, "small_ball"),
|
|
LARGE_BALL(1, "large_ball"),
|
|
STAR(2, "star"),
|
|
CREEPER(3, "creeper"),
|
|
BURST(4, "burst");
|
|
|
|
private static final Shape[] BY_ID;
|
|
private final int id;
|
|
private final String name;
|
|
|
|
private Shape(final int integer3, final String string4) {
|
|
this.id = integer3;
|
|
this.name = string4;
|
|
}
|
|
|
|
public int getId() {
|
|
return this.id;
|
|
}
|
|
|
|
public String getName() {
|
|
return this.name;
|
|
}
|
|
|
|
public static Shape byId(final int integer) {
|
|
if (integer < 0 || integer >= Shape.BY_ID.length) {
|
|
return Shape.SMALL_BALL;
|
|
}
|
|
return Shape.BY_ID[integer];
|
|
}
|
|
|
|
static {
|
|
BY_ID = Arrays.<Shape>stream(values()).sorted(Comparator.comparingInt(a -> a.id)).<Shape>toArray(Shape[]::new);
|
|
}
|
|
}
|
|
}
|