use of org.bukkit.craftbukkit.v1_18_R2.entity in project Denizen by DenizenScript.
the class EnchantmentHelperImpl method registerFakeEnchantment.
@Override
public org.bukkit.enchantments.Enchantment registerFakeEnchantment(EnchantmentScriptContainer.EnchantmentReference script) {
try {
EquipmentSlot[] slots = new EquipmentSlot[script.script.slots.size()];
for (int i = 0; i < slots.length; i++) {
slots[i] = EquipmentSlot.valueOf(script.script.slots.get(i).toUpperCase());
}
net.minecraft.world.item.enchantment.Enchantment nmsEnchant = new net.minecraft.world.item.enchantment.Enchantment(net.minecraft.world.item.enchantment.Enchantment.Rarity.valueOf(script.script.rarity), EnchantmentCategory.valueOf(script.script.category), slots) {
@Override
public int getMinLevel() {
return script.script.minLevel;
}
@Override
public int getMaxLevel() {
return script.script.maxLevel;
}
@Override
public int getMinCost(int level) {
return script.script.getMinCost(level);
}
@Override
public int getMaxCost(int level) {
return script.script.getMaxCost(level);
}
@Override
public int getDamageProtection(int level, DamageSource src) {
return script.script.getDamageProtection(level, src.msgId, src.getEntity() == null ? null : src.getEntity().getBukkitEntity());
}
@Override
public float getDamageBonus(int level, MobType type) {
String typeName = "UNDEFINED";
if (type == MobType.ARTHROPOD) {
typeName = "ARTHROPOD";
} else if (type == MobType.ILLAGER) {
typeName = "ILLAGER";
} else if (type == MobType.UNDEAD) {
typeName = "UNDEAD";
} else if (type == MobType.WATER) {
typeName = "WATER";
}
return script.script.getDamageBonus(level, typeName);
}
@Override
protected boolean checkCompatibility(net.minecraft.world.item.enchantment.Enchantment nmsEnchantment) {
ResourceLocation nmsKey = Registry.ENCHANTMENT.getKey(nmsEnchantment);
NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(nmsKey);
org.bukkit.enchantments.Enchantment bukkitEnchant = CraftEnchantment.getByKey(bukkitKey);
return script.script.isCompatible(bukkitEnchant);
}
@Override
protected String getOrCreateDescriptionId() {
return script.script.descriptionId;
}
@Override
public String getDescriptionId() {
return script.script.descriptionId;
}
@Override
public Component getFullname(int level) {
return Handler.componentToNMS(script.script.getFullName(level));
}
@Override
public boolean canEnchant(net.minecraft.world.item.ItemStack var0) {
return super.canEnchant(var0) && script.script.canEnchant(CraftItemStack.asBukkitCopy(var0));
}
@Override
public void doPostAttack(LivingEntity attacker, Entity victim, int level) {
script.script.doPostAttack(attacker.getBukkitEntity(), victim.getBukkitEntity(), level);
}
@Override
public void doPostHurt(LivingEntity victim, Entity attacker, int level) {
script.script.doPostHurt(victim.getBukkitEntity(), attacker.getBukkitEntity(), level);
}
@Override
public boolean isTreasureOnly() {
return script.script.isTreasureOnly;
}
@Override
public boolean isCurse() {
return script.script.isCurse;
}
@Override
public boolean isTradeable() {
return script.script.isTradable;
}
@Override
public boolean isDiscoverable() {
return script.script.isDiscoverable;
}
};
String enchName = script.script.id.toUpperCase();
Registry.register(Registry.ENCHANTMENT, "denizen:" + script.script.id, nmsEnchant);
CraftEnchantment ench = new CraftEnchantment(nmsEnchant) {
@Override
public String getName() {
return enchName;
}
};
ENCHANTMENTS_BY_KEY.put(ench.getKey(), ench);
ENCHANTMENTS_BY_NAME.put(enchName, ench);
return ench;
} catch (Throwable ex) {
Debug.echoError("Failed to register enchantment " + script.script.id);
Debug.echoError(ex);
return null;
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity in project Denizen by DenizenScript.
the class EntityHelperImpl method walkTo.
@Override
public void walkTo(final LivingEntity entity, Location location, Double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.world.entity.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof Mob)) {
return;
}
final Mob nmsEntity = (Mob) nmsEntityEntity;
final PathNavigation entityNavigation = nmsEntity.getNavigation();
final Path path;
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
entity.setAI(true);
try {
ENTITY_ONGROUND_SETTER.invoke(nmsEntity, true);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
path = entityNavigation.createPath(location.getX(), location.getY(), location.getZ(), 1);
if (path != null) {
nmsEntity.goalSelector.enableControlFlag(Goal.Flag.MOVE);
entityNavigation.moveTo(path, 1D);
entityNavigation.setSpeedModifier(2D);
final double oldSpeed = nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).getBaseValue();
if (speed != null) {
nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
new BukkitRunnable() {
@Override
public void run() {
if (!entity.isValid()) {
if (callback != null) {
callback.run();
}
cancel();
return;
}
if (aiDisabled && entity instanceof Wolf) {
((Wolf) entity).setAngry(false);
}
if (entityNavigation.isDone() || path.isDone()) {
if (callback != null) {
callback.run();
}
if (speed != null) {
nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(oldSpeed);
}
if (aiDisabled) {
entity.setAI(false);
}
cancel();
}
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
} else // if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
// TODO: generate waypoints to the target location?
{
entity.teleport(location);
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity in project Denizen by DenizenScript.
the class EntityHelperImpl method setTrackingRange.
@Override
public void setTrackingRange(Entity entity, int range) {
try {
ChunkMap map = ((CraftWorld) entity.getWorld()).getHandle().getChunkSource().chunkMap;
ChunkMap.TrackedEntity entry = map.entityMap.get(entity.getEntityId());
TRACKING_RANGE_SETTER.invoke(entry, range);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity in project Denizen by DenizenScript.
the class PacketHelperImpl method setVision.
@Override
public void setVision(Player player, EntityType entityType) {
final net.minecraft.world.entity.LivingEntity entity;
if (entityType == EntityType.CREEPER) {
entity = new Creeper(net.minecraft.world.entity.EntityType.CREEPER, ((CraftWorld) player.getWorld()).getHandle());
} else if (entityType == EntityType.SPIDER) {
entity = new Spider(net.minecraft.world.entity.EntityType.SPIDER, ((CraftWorld) player.getWorld()).getHandle());
} else if (entityType == EntityType.CAVE_SPIDER) {
entity = new CaveSpider(net.minecraft.world.entity.EntityType.CAVE_SPIDER, ((CraftWorld) player.getWorld()).getHandle());
} else if (entityType == EntityType.ENDERMAN) {
entity = new EnderMan(net.minecraft.world.entity.EntityType.ENDERMAN, ((CraftWorld) player.getWorld()).getHandle());
} else {
return;
}
// Spectating an entity then immediately respawning the player prevents a client shader update,
// allowing the player to retain whatever vision the mob they spectated had.
send(player, new ClientboundAddMobPacket(entity));
send(player, new ClientboundSetCameraPacket(entity));
((CraftServer) Bukkit.getServer()).getHandle().respawn(((CraftPlayer) player).getHandle(), ((CraftWorld) player.getWorld()).getHandle(), true, player.getLocation(), false);
}
use of org.bukkit.craftbukkit.v1_18_R2.entity in project Denizen by DenizenScript.
the class BlockHelperImpl method setSpawnerSpawnedType.
@Override
public void setSpawnerSpawnedType(CreatureSpawner spawner, EntityTag entity) {
spawner.setSpawnedType(entity.getBukkitEntityType());
if (entity.getWaitingMechanisms() == null || entity.getWaitingMechanisms().size() == 0) {
return;
}
try {
// Wrangle a fake entity
Entity nmsEntity = ((CraftWorld) spawner.getWorld()).createEntity(spawner.getLocation(), entity.getBukkitEntityType().getEntityClass());
EntityTag entityTag = new EntityTag(nmsEntity.getBukkitEntity());
entityTag.isFake = true;
entityTag.isFakeValid = true;
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
entityTag.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
// Store it into the spawner
CraftCreatureSpawner bukkitSpawner = (CraftCreatureSpawner) spawner;
SpawnerBlockEntity nmsSnapshot = (SpawnerBlockEntity) craftBlockEntityState_snapshot.get(bukkitSpawner);
BaseSpawner nmsSpawner = nmsSnapshot.getSpawner();
SpawnData toSpawn = nmsSpawner.nextSpawnData;
net.minecraft.nbt.CompoundTag tag = toSpawn.getEntityToSpawn();
nmsEntity.saveWithoutId(tag);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
Aggregations