13
0
geforkt von Mirrors/Paper

SPIGOT-3842: Add Player#fireworkBoost() and expand Firework API

By: Parker Hawke <hawkeboyz2@hotmail.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2022-09-12 19:04:24 +10:00
Ursprung d41367ee6d
Commit 7d96f4be6d
3 geänderte Dateien mit 84 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/projectile/EntityFireworks.java --- a/net/minecraft/world/entity/projectile/EntityFireworks.java
+++ b/net/minecraft/world/entity/projectile/EntityFireworks.java +++ b/net/minecraft/world/entity/projectile/EntityFireworks.java
@@ -29,6 +29,8 @@ @@ -29,15 +29,17 @@
import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.MovingObjectPositionEntity;
import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.Vec3D;
@ -9,6 +9,17 @@
public class EntityFireworks extends IProjectile implements ItemSupplier { public class EntityFireworks extends IProjectile implements ItemSupplier {
public static final DataWatcherObject<ItemStack> DATA_ID_FIREWORKS_ITEM = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.ITEM_STACK); public static final DataWatcherObject<ItemStack> DATA_ID_FIREWORKS_ITEM = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.ITEM_STACK);
private static final DataWatcherObject<OptionalInt> DATA_ATTACHED_TO_TARGET = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.OPTIONAL_UNSIGNED_INT);
public static final DataWatcherObject<Boolean> DATA_SHOT_AT_ANGLE = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.BOOLEAN);
- private int life;
+ public int life; // PAIL private -> public
public int lifetime;
@Nullable
- private EntityLiving attachedToEntity;
+ public EntityLiving attachedToEntity; // PAIL private -> public
public EntityFireworks(EntityTypes<? extends EntityFireworks> entitytypes, World world) {
super(entitytypes, world);
@@ -144,7 +146,7 @@ @@ -144,7 +146,7 @@
MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResult(this, this::canHitEntity); MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResult(this, this::canHitEntity);

Datei anzeigen

@ -1,6 +1,8 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import java.util.Random; import java.util.Random;
import net.minecraft.world.entity.EntityLiving;
import net.minecraft.world.entity.projectile.EntityFireworks; import net.minecraft.world.entity.projectile.EntityFireworks;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
@ -9,6 +11,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.inventory.meta.FireworkMeta;
public class CraftFirework extends CraftProjectile implements Firework { public class CraftFirework extends CraftProjectile implements Firework {
@ -64,9 +67,64 @@ public class CraftFirework extends CraftProjectile implements Firework {
getHandle().getEntityData().markDirty(EntityFireworks.DATA_ID_FIREWORKS_ITEM); getHandle().getEntityData().markDirty(EntityFireworks.DATA_ID_FIREWORKS_ITEM);
} }
@Override
public boolean setAttachedTo(LivingEntity entity) {
if (isDetonated()) {
return false;
}
getHandle().attachedToEntity = (entity != null) ? ((CraftLivingEntity) entity).getHandle() : null;
return true;
}
@Override
public LivingEntity getAttachedTo() {
EntityLiving entity = getHandle().attachedToEntity;
return (entity != null) ? (LivingEntity) entity.getBukkitEntity() : null;
}
@Override
public boolean setLife(int ticks) {
Preconditions.checkArgument(ticks >= 0, "ticks must be greater than or equal to 0");
if (isDetonated()) {
return false;
}
getHandle().life = ticks;
return true;
}
@Override
public int getLife() {
return getHandle().life;
}
@Override
public boolean setMaxLife(int ticks) {
Preconditions.checkArgument(ticks > 0, "ticks must be greater than 0");
if (isDetonated()) {
return false;
}
getHandle().lifetime = ticks;
return true;
}
@Override
public int getMaxLife() {
return getHandle().lifetime;
}
@Override @Override
public void detonate() { public void detonate() {
getHandle().lifetime = 0; this.setLife(getMaxLife() + 1);
}
@Override
public boolean isDetonated() {
return getHandle().life > getHandle().lifetime;
} }
@Override @Override

Datei anzeigen

@ -18,6 +18,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.entity.EnumMainHand; import net.minecraft.world.entity.EnumMainHand;
import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.entity.projectile.EntityFireworks;
import net.minecraft.world.inventory.Container; import net.minecraft.world.inventory.Container;
import net.minecraft.world.inventory.Containers; import net.minecraft.world.inventory.Containers;
import net.minecraft.world.item.ItemCooldown; import net.minecraft.world.item.ItemCooldown;
@ -49,8 +50,10 @@ import org.bukkit.craftbukkit.inventory.CraftMerchantCustom;
import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.entity.Firework;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Villager; import org.bukkit.entity.Villager;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
@ -661,4 +664,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
getHandle().setLastDeathLocation(Optional.of(CraftMemoryMapper.toNms(location))); getHandle().setLastDeathLocation(Optional.of(CraftMemoryMapper.toNms(location)));
} }
} }
@Override
public Firework fireworkBoost(ItemStack fireworkItemStack) {
Preconditions.checkArgument(fireworkItemStack != null, "fireworkItemStack must not be null");
Preconditions.checkArgument(fireworkItemStack.getType() == Material.FIREWORK_ROCKET, "fireworkItemStack must be of type %s", Material.FIREWORK_ROCKET);
EntityFireworks fireworks = new EntityFireworks(getHandle().level, CraftItemStack.asNMSCopy(fireworkItemStack), getHandle());
boolean success = getHandle().level.addFreshEntity(fireworks, SpawnReason.CUSTOM);
return success ? (Firework) fireworks.getBukkitEntity() : null;
}
} }