mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
#1328: Rename CraftArrow to CraftAbstractArrow and CraftTippedArrow to CraftArrow to better reflect Bukkit's names
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
1b0447274f
commit
d122883f57
6 changed files with 254 additions and 254 deletions
|
@ -0,0 +1,144 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
|
||||
public class CraftAbstractArrow extends AbstractProjectile implements AbstractArrow {
|
||||
|
||||
public CraftAbstractArrow(CraftServer server, EntityArrow entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackStrength(int knockbackStrength) {
|
||||
Preconditions.checkArgument(knockbackStrength >= 0, "Knockback value (%s) cannot be negative", knockbackStrength);
|
||||
getHandle().setKnockback(knockbackStrength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKnockbackStrength() {
|
||||
return getHandle().knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDamage() {
|
||||
return getHandle().getBaseDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(double damage) {
|
||||
Preconditions.checkArgument(damage >= 0, "Damage value (%s) must be positive", damage);
|
||||
getHandle().setBaseDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPierceLevel() {
|
||||
return getHandle().getPierceLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPierceLevel(int pierceLevel) {
|
||||
Preconditions.checkArgument(0 <= pierceLevel && pierceLevel <= Byte.MAX_VALUE, "Pierce level (%s) out of range, expected 0 < level < 127", pierceLevel);
|
||||
|
||||
getHandle().setPierceLevel((byte) pierceLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCritical() {
|
||||
return getHandle().isCritArrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCritical(boolean critical) {
|
||||
getHandle().setCritArrow(critical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectileSource getShooter() {
|
||||
return getHandle().projectileSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShooter(ProjectileSource shooter) {
|
||||
if (shooter instanceof Entity) {
|
||||
getHandle().setOwner(((CraftEntity) shooter).getHandle());
|
||||
} else {
|
||||
getHandle().setOwner(null);
|
||||
}
|
||||
getHandle().projectileSource = shooter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInBlock() {
|
||||
return getHandle().inGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getAttachedBlock() {
|
||||
if (!isInBlock()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockPosition pos = getHandle().blockPosition();
|
||||
return getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickupStatus getPickupStatus() {
|
||||
return PickupStatus.values()[getHandle().pickup.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupStatus(PickupStatus status) {
|
||||
Preconditions.checkArgument(status != null, "PickupStatus cannot be null");
|
||||
getHandle().pickup = EntityArrow.PickupStatus.byOrdinal(status.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicksLived(int value) {
|
||||
super.setTicksLived(value);
|
||||
|
||||
// Second field for EntityArrow
|
||||
getHandle().life = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShotFromCrossbow() {
|
||||
return getHandle().shotFromCrossbow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShotFromCrossbow(boolean shotFromCrossbow) {
|
||||
getHandle().setShotFromCrossbow(shotFromCrossbow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return CraftItemStack.asBukkitCopy(getHandle().pickupItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(ItemStack item) {
|
||||
Preconditions.checkArgument(item != null, "ItemStack cannot be null");
|
||||
|
||||
getHandle().pickupItemStack = CraftItemStack.asNMSCopy(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityArrow getHandle() {
|
||||
return (EntityArrow) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftArrow";
|
||||
}
|
||||
}
|
|
@ -1,144 +1,122 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.entity.projectile.EntityArrow;
|
||||
import org.bukkit.block.Block;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.projectiles.ProjectileSource;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionType;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftArrow extends AbstractProjectile implements AbstractArrow {
|
||||
public class CraftArrow extends CraftAbstractArrow implements Arrow {
|
||||
|
||||
public CraftArrow(CraftServer server, EntityArrow entity) {
|
||||
public CraftArrow(CraftServer server, EntityTippedArrow entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackStrength(int knockbackStrength) {
|
||||
Preconditions.checkArgument(knockbackStrength >= 0, "Knockback value (%s) cannot be negative", knockbackStrength);
|
||||
getHandle().setKnockback(knockbackStrength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKnockbackStrength() {
|
||||
return getHandle().knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDamage() {
|
||||
return getHandle().getBaseDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(double damage) {
|
||||
Preconditions.checkArgument(damage >= 0, "Damage value (%s) must be positive", damage);
|
||||
getHandle().setBaseDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPierceLevel() {
|
||||
return getHandle().getPierceLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPierceLevel(int pierceLevel) {
|
||||
Preconditions.checkArgument(0 <= pierceLevel && pierceLevel <= Byte.MAX_VALUE, "Pierce level (%s) out of range, expected 0 < level < 127", pierceLevel);
|
||||
|
||||
getHandle().setPierceLevel((byte) pierceLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCritical() {
|
||||
return getHandle().isCritArrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCritical(boolean critical) {
|
||||
getHandle().setCritArrow(critical);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectileSource getShooter() {
|
||||
return getHandle().projectileSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShooter(ProjectileSource shooter) {
|
||||
if (shooter instanceof Entity) {
|
||||
getHandle().setOwner(((CraftEntity) shooter).getHandle());
|
||||
} else {
|
||||
getHandle().setOwner(null);
|
||||
}
|
||||
getHandle().projectileSource = shooter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInBlock() {
|
||||
return getHandle().inGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getAttachedBlock() {
|
||||
if (!isInBlock()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BlockPosition pos = getHandle().blockPosition();
|
||||
return getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PickupStatus getPickupStatus() {
|
||||
return PickupStatus.values()[getHandle().pickup.ordinal()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPickupStatus(PickupStatus status) {
|
||||
Preconditions.checkArgument(status != null, "PickupStatus cannot be null");
|
||||
getHandle().pickup = EntityArrow.PickupStatus.byOrdinal(status.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTicksLived(int value) {
|
||||
super.setTicksLived(value);
|
||||
|
||||
// Second field for EntityArrow
|
||||
getHandle().life = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShotFromCrossbow() {
|
||||
return getHandle().shotFromCrossbow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setShotFromCrossbow(boolean shotFromCrossbow) {
|
||||
getHandle().setShotFromCrossbow(shotFromCrossbow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return CraftItemStack.asBukkitCopy(getHandle().pickupItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(ItemStack item) {
|
||||
Preconditions.checkArgument(item != null, "ItemStack cannot be null");
|
||||
|
||||
getHandle().pickupItemStack = CraftItemStack.asNMSCopy(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityArrow getHandle() {
|
||||
return (EntityArrow) entity;
|
||||
public EntityTippedArrow getHandle() {
|
||||
return (EntityTippedArrow) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftArrow";
|
||||
return "CraftTippedArrow";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addCustomEffect(PotionEffect effect, boolean override) {
|
||||
if (hasCustomEffect(effect.getType())) {
|
||||
if (!override) {
|
||||
return false;
|
||||
}
|
||||
removeCustomEffect(effect.getType());
|
||||
}
|
||||
getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
|
||||
getHandle().updateColor();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCustomEffects() {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
|
||||
getHandle().updateColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PotionEffect> getCustomEffects() {
|
||||
ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
|
||||
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
|
||||
builder.add(CraftPotionUtil.toBukkit(effect));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEffect(PotionEffectType type) {
|
||||
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
|
||||
if (CraftPotionUtil.equals(effect.getEffect(), type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEffects() {
|
||||
return !getHandle().getPotionContents().customEffects().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeCustomEffect(PotionEffectType effect) {
|
||||
if (!hasCustomEffect(effect)) {
|
||||
return false;
|
||||
}
|
||||
Holder<MobEffectList> minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect);
|
||||
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasePotionType(PotionType potionType) {
|
||||
if (potionType != null) {
|
||||
getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
|
||||
} else {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionType getBasePotionType() {
|
||||
return getHandle().getPotionContents().potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
int colorRGB = (color == null) ? -1 : color.asRGB();
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
if (getHandle().getColor() <= -1) {
|
||||
return null;
|
||||
}
|
||||
return Color.fromRGB(getHandle().getColor());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -347,7 +347,7 @@ public final class CraftEntityTypes {
|
|||
register(new EntityTypeData<>(EntityType.GLOW_ITEM_FRAME, GlowItemFrame.class, CraftGlowItemFrame::new, createHanging(GlowItemFrame.class, (spawnData, hangingData) -> new net.minecraft.world.entity.decoration.GlowItemFrame(spawnData.minecraftWorld(), hangingData.position(), hangingData.direction()))));
|
||||
|
||||
// Move no rotation
|
||||
register(new EntityTypeData<>(EntityType.ARROW, Arrow.class, CraftTippedArrow::new, createAndMoveEmptyRot(EntityTypes.ARROW)));
|
||||
register(new EntityTypeData<>(EntityType.ARROW, Arrow.class, CraftArrow::new, createAndMoveEmptyRot(EntityTypes.ARROW)));
|
||||
register(new EntityTypeData<>(EntityType.ENDER_PEARL, EnderPearl.class, CraftEnderPearl::new, createAndMoveEmptyRot(EntityTypes.ENDER_PEARL)));
|
||||
register(new EntityTypeData<>(EntityType.THROWN_EXP_BOTTLE, ThrownExpBottle.class, CraftThrownExpBottle::new, createAndMoveEmptyRot(EntityTypes.EXPERIENCE_BOTTLE)));
|
||||
register(new EntityTypeData<>(EntityType.SPECTRAL_ARROW, SpectralArrow.class, CraftSpectralArrow::new, createAndMoveEmptyRot(EntityTypes.SPECTRAL_ARROW)));
|
||||
|
|
|
@ -4,7 +4,7 @@ import net.minecraft.world.entity.projectile.EntitySpectralArrow;
|
|||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.SpectralArrow;
|
||||
|
||||
public class CraftSpectralArrow extends CraftArrow implements SpectralArrow {
|
||||
public class CraftSpectralArrow extends CraftAbstractArrow implements SpectralArrow {
|
||||
|
||||
public CraftSpectralArrow(CraftServer server, EntitySpectralArrow entity) {
|
||||
super(server, entity);
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import net.minecraft.world.entity.projectile.EntityTippedArrow;
|
||||
import net.minecraft.world.item.alchemy.PotionContents;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionType;
|
||||
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftTippedArrow extends CraftArrow implements Arrow {
|
||||
|
||||
public CraftTippedArrow(CraftServer server, EntityTippedArrow entity) {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityTippedArrow getHandle() {
|
||||
return (EntityTippedArrow) entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftTippedArrow";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addCustomEffect(PotionEffect effect, boolean override) {
|
||||
if (hasCustomEffect(effect.getType())) {
|
||||
if (!override) {
|
||||
return false;
|
||||
}
|
||||
removeCustomEffect(effect.getType());
|
||||
}
|
||||
getHandle().addEffect(CraftPotionUtil.fromBukkit(effect));
|
||||
getHandle().updateColor();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCustomEffects() {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of()));
|
||||
getHandle().updateColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PotionEffect> getCustomEffects() {
|
||||
ImmutableList.Builder<PotionEffect> builder = ImmutableList.builder();
|
||||
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
|
||||
builder.add(CraftPotionUtil.toBukkit(effect));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEffect(PotionEffectType type) {
|
||||
for (MobEffect effect : getHandle().getPotionContents().customEffects()) {
|
||||
if (CraftPotionUtil.equals(effect.getEffect(), type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomEffects() {
|
||||
return !getHandle().getPotionContents().customEffects().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeCustomEffect(PotionEffectType effect) {
|
||||
if (!hasCustomEffect(effect)) {
|
||||
return false;
|
||||
}
|
||||
Holder<MobEffectList> minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect);
|
||||
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasePotionType(PotionType potionType) {
|
||||
if (potionType != null) {
|
||||
getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType)));
|
||||
} else {
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionType getBasePotionType() {
|
||||
return getHandle().getPotionContents().potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(Color color) {
|
||||
int colorRGB = (color == null) ? -1 : color.asRGB();
|
||||
PotionContents old = getHandle().getPotionContents();
|
||||
getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
if (getHandle().getColor() <= -1) {
|
||||
return null;
|
||||
}
|
||||
return Color.fromRGB(getHandle().getColor());
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CraftTrident extends CraftArrow implements Trident {
|
||||
public class CraftTrident extends CraftAbstractArrow implements Trident {
|
||||
|
||||
public CraftTrident(CraftServer server, EntityThrownTrident entity) {
|
||||
super(server, entity);
|
||||
|
|
Loading…
Reference in a new issue