use of net.minecraft.server.v1_16_R3 in project Denizen-For-Bukkit by DenizenScript.
the class PlayerHelperImpl method sendEntitySpawn.
@Override
public FakeEntity sendEntitySpawn(List<PlayerTag> players, DenizenEntityType entityType, LocationTag location, ArrayList<Mechanism> mechanisms, int customId, UUID customUUID, boolean autoTrack) {
CraftWorld world = ((CraftWorld) location.getWorld());
net.minecraft.server.v1_16_R3.Entity nmsEntity;
if (entityType.isCustom()) {
if (entityType.customEntityType == CustomEntityType.ITEM_PROJECTILE) {
org.bukkit.inventory.ItemStack itemStack = new ItemStack(Material.STONE);
for (Mechanism mechanism : mechanisms) {
if (mechanism.matches("item") && mechanism.requireObject(ItemTag.class)) {
itemStack = mechanism.valueAsType(ItemTag.class).getItemStack();
}
}
nmsEntity = new EntityItemProjectileImpl(world.getHandle(), location, CraftItemStack.asNMSCopy(itemStack));
} else if (entityType.customEntityType == CustomEntityType.FAKE_PLAYER) {
String name = null;
String skin = null;
for (Mechanism mechanism : new ArrayList<>(mechanisms)) {
if (mechanism.matches("name")) {
name = mechanism.getValue().asString();
mechanisms.remove(mechanism);
} else if (mechanism.matches("skin")) {
skin = mechanism.getValue().asString();
mechanisms.remove(mechanism);
}
if (name != null && skin != null) {
break;
}
}
nmsEntity = ((CraftFakePlayerImpl) CustomEntityHelperImpl.spawnFakePlayer(location, name, skin, false)).getHandle();
} else {
throw new IllegalArgumentException("entityType");
}
} else {
nmsEntity = world.createEntity(location, entityType.getBukkitEntityType().getEntityClass());
}
if (customUUID != null) {
nmsEntity.e(customId);
nmsEntity.a_(customUUID);
}
EntityTag entity = new EntityTag(nmsEntity.getBukkitEntity());
for (Mechanism mechanism : mechanisms) {
entity.safeAdjustDuplicate(mechanism);
}
nmsEntity.dead = false;
FakeEntity fake = new FakeEntity(players, location, entity.getBukkitEntity().getEntityId());
fake.entity = new EntityTag(entity.getBukkitEntity());
fake.entity.isFake = true;
fake.entity.isFakeValid = true;
List<TrackerData> trackers = new ArrayList<>();
fake.triggerSpawnPacket = (player) -> {
EntityPlayer nmsPlayer = ((CraftPlayer) player.getPlayerEntity()).getHandle();
PlayerConnection conn = nmsPlayer.playerConnection;
final EntityTrackerEntry tracker = new EntityTrackerEntry(world.getHandle(), nmsEntity, 1, true, conn::sendPacket, Collections.singleton(nmsPlayer));
tracker.b(nmsPlayer);
final TrackerData data = new TrackerData();
data.player = player;
data.tracker = tracker;
trackers.add(data);
if (autoTrack) {
new BukkitRunnable() {
boolean wasOnline = true;
@Override
public void run() {
if (!fake.entity.isFakeValid) {
cancel();
return;
}
if (player.isOnline()) {
if (!wasOnline) {
tracker.b(((CraftPlayer) player.getPlayerEntity()).getHandle());
wasOnline = true;
}
tracker.a();
} else if (wasOnline) {
wasOnline = false;
}
}
}.runTaskTimer(Denizen.getInstance(), 1, 1);
}
};
for (PlayerTag player : players) {
fake.triggerSpawnPacket.accept(player);
}
fake.triggerUpdatePacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a();
}
}
};
fake.triggerDestroyPacket = () -> {
for (TrackerData tracker : trackers) {
if (tracker.player.isOnline()) {
tracker.tracker.a(((CraftPlayer) tracker.player.getPlayerEntity()).getHandle());
}
}
trackers.clear();
};
return fake;
}
use of net.minecraft.server.v1_16_R3 in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getDamageTo.
@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
EnumMonsterType monsterType;
if (target instanceof LivingEntity) {
monsterType = ((CraftLivingEntity) target).getHandle().getMonsterType();
} else {
monsterType = EnumMonsterType.UNDEFINED;
}
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentManager.a(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
if (damage <= 0) {
return 0;
}
if (target != null) {
DamageSource source;
if (attacker instanceof Player) {
source = DamageSource.playerAttack(((CraftPlayer) attacker).getHandle());
} else {
source = DamageSource.mobAttack(((CraftLivingEntity) attacker).getHandle());
}
net.minecraft.server.v1_16_R3.Entity nmsTarget = ((CraftEntity) target).getHandle();
if (nmsTarget.isInvulnerable(source)) {
return 0;
}
if (!(nmsTarget instanceof EntityLiving)) {
return damage;
}
EntityLiving livingTarget = (EntityLiving) nmsTarget;
damage = CombatMath.a((float) damage, (float) livingTarget.getArmorStrength(), (float) livingTarget.getAttributeInstance(GenericAttributes.ARMOR_TOUGHNESS).getValue());
int enchantDamageModifier = EnchantmentManager.a(livingTarget.getArmorItems(), source);
if (enchantDamageModifier > 0) {
damage = CombatMath.a((float) damage, (float) enchantDamageModifier);
}
}
return damage;
}
use of net.minecraft.server.v1_16_R3 in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method damage.
@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (target == null) {
return;
}
EntityLiving nmsTarget = ((CraftLivingEntity) target).getHandle();
net.minecraft.server.v1_16_R3.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
CraftEventFactory.entityDamage = nmsSource;
try {
DamageSource src = DamageSource.GENERIC;
if (nmsSource != null) {
if (nmsSource instanceof EntityHuman) {
src = DamageSource.playerAttack((EntityHuman) nmsSource);
} else if (nmsSource instanceof EntityLiving) {
src = DamageSource.mobAttack((EntityLiving) nmsSource);
}
}
if (cause != null) {
switch(cause) {
case CONTACT:
src = DamageSource.CACTUS;
break;
case ENTITY_ATTACK:
src = DamageSource.mobAttack(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case ENTITY_SWEEP_ATTACK:
if (src != DamageSource.GENERIC) {
src.sweep();
}
break;
case PROJECTILE:
src = DamageSource.projectile(nmsSource, source instanceof Projectile && ((Projectile) source).getShooter() instanceof Entity ? ((CraftEntity) ((Projectile) source).getShooter()).getHandle() : null);
break;
case SUFFOCATION:
src = DamageSource.STUCK;
break;
case FALL:
src = DamageSource.FALL;
break;
case FIRE:
src = DamageSource.FIRE;
break;
case FIRE_TICK:
src = DamageSource.BURN;
break;
case MELTING:
src = CraftEventFactory.MELTING;
break;
case LAVA:
src = DamageSource.LAVA;
break;
case DROWNING:
src = DamageSource.DROWN;
break;
case BLOCK_EXPLOSION:
src = DamageSource.d(nmsSource instanceof TNTPrimed && ((TNTPrimed) nmsSource).getSource() instanceof EntityLiving ? (EntityLiving) ((TNTPrimed) nmsSource).getSource() : null);
break;
case ENTITY_EXPLOSION:
src = DamageSource.d(nmsSource instanceof EntityLiving ? (EntityLiving) nmsSource : null);
break;
case VOID:
src = DamageSource.OUT_OF_WORLD;
break;
case LIGHTNING:
src = DamageSource.LIGHTNING;
break;
case STARVATION:
src = DamageSource.STARVE;
break;
case POISON:
src = CraftEventFactory.POISON;
break;
case MAGIC:
src = DamageSource.MAGIC;
break;
case WITHER:
src = DamageSource.WITHER;
break;
case FALLING_BLOCK:
src = DamageSource.FALLING_BLOCK;
break;
case THORNS:
src = DamageSource.a(nmsSource);
break;
case DRAGON_BREATH:
src = DamageSource.DRAGON_BREATH;
break;
case CUSTOM:
src = DamageSource.GENERIC;
break;
case FLY_INTO_WALL:
src = DamageSource.FLY_INTO_WALL;
break;
case HOT_FLOOR:
src = DamageSource.HOT_FLOOR;
break;
case CRAMMING:
src = DamageSource.CRAMMING;
break;
case DRYOUT:
src = DamageSource.DRYOUT;
break;
// case SUICIDE:
default:
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (ede.isCancelled()) {
return;
}
break;
}
}
nmsTarget.damageEntity(src, amount);
} finally {
CraftEventFactory.entityDamage = null;
}
}
use of net.minecraft.server.v1_16_R3 in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method setSkullSkin.
@Override
public ItemStack setSkullSkin(ItemStack itemStack, PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
if (playerProfile.hasTexture()) {
gameProfile.getProperties().get("textures").clear();
if (playerProfile.getTextureSignature() != null) {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
} else {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
}
}
net.minecraft.server.v1_16_R3.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
NBTTagCompound tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new NBTTagCompound();
tag.set("SkullOwner", GameProfileSerializer.serialize(new NBTTagCompound(), gameProfile));
nmsItemStack.setTag(tag);
return CraftItemStack.asBukkitCopy(nmsItemStack);
}
use of net.minecraft.server.v1_16_R3 in project MyPet by xXKeyleXx.
the class EntityConverterService method convertEntity.
@Override
public void convertEntity(MyPet myPet, LivingEntity normalEntity) {
if (myPet instanceof MyCreeper) {
if (((MyCreeper) myPet).isPowered()) {
((Creeper) normalEntity).setPowered(true);
}
} else if (myPet instanceof MyEnderman) {
if (((MyEnderman) myPet).hasBlock()) {
((Enderman) normalEntity).setCarriedMaterial(((MyEnderman) myPet).getBlock().getData());
}
} else if (myPet instanceof MyIronGolem) {
((IronGolem) normalEntity).setPlayerCreated(true);
} else if (myPet instanceof MyMagmaCube) {
((MagmaCube) normalEntity).setSize(((MyMagmaCube) myPet).getSize());
} else if (myPet instanceof MyPig) {
((Pig) normalEntity).setSaddle(((MyPig) myPet).hasSaddle());
} else if (myPet instanceof MySheep) {
((Sheep) normalEntity).setSheared(((MySheep) myPet).isSheared());
((Sheep) normalEntity).setColor(((MySheep) myPet).getColor());
} else if (myPet instanceof MyVillager) {
MyVillager villagerPet = (MyVillager) myPet;
Villager villagerEntity = ((Villager) normalEntity);
Villager.Profession profession = Villager.Profession.values()[villagerPet.getProfession()];
Villager.Type type = Villager.Type.values()[villagerPet.getType().ordinal()];
villagerEntity.setVillagerType(type);
villagerEntity.setProfession(profession);
villagerEntity.setVillagerLevel(villagerPet.getVillagerLevel());
if (villagerPet.hasOriginalData()) {
TagCompound villagerTag = villagerPet.getOriginalData();
EntityVillager entityVillager = ((CraftVillager) villagerEntity).getHandle();
try {
if (villagerTag.containsKey("Offers")) {
TagCompound offersTag = villagerTag.get("Offers");
NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(offersTag);
entityVillager.b(new MerchantRecipeList(vanillaNBT));
}
if (villagerTag.containsKey("Inventory")) {
TagList inventoryTag = villagerTag.get("Inventory");
NBTTagList vanillaNBT = (NBTTagList) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
for (int i = 0; i < vanillaNBT.size(); ++i) {
net.minecraft.server.v1_16_R3.ItemStack itemstack = net.minecraft.server.v1_16_R3.ItemStack.a(vanillaNBT.getCompound(i));
if (!itemstack.isEmpty()) {
entityVillager.getInventory().a(itemstack);
}
}
}
if (villagerTag.containsKey("FoodLevel")) {
byte foodLevel = villagerTag.getAs("FoodLevel", TagByte.class).getByteData();
ReflectionUtil.setFieldValue("bx", entityVillager, foodLevel);
}
if (villagerTag.containsKey("Gossips")) {
TagList inventoryTag = villagerTag.get("Gossips");
NBTTagList vanillaNBT = (NBTTagList) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
((Reputation) ReflectionUtil.getFieldValue(EntityVillager.class, entityVillager, "by")).a(new Dynamic<>(DynamicOpsNBT.a, vanillaNBT));
}
if (villagerTag.containsKey("LastRestock")) {
long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
ReflectionUtil.setFieldValue("bC", entityVillager, lastRestock);
}
if (villagerTag.containsKey("LastGossipDecay")) {
long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
ReflectionUtil.setFieldValue("bA", entityVillager, lastGossipDecay);
}
if (villagerTag.containsKey("RestocksToday")) {
int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
ReflectionUtil.setFieldValue("bD", entityVillager, restocksToday);
}
// AssignProfessionWhenSpawned
ReflectionUtil.setFieldValue("bF", entityVillager, true);
} catch (Exception e) {
e.printStackTrace();
}
if (villagerTag.containsKey("Xp")) {
int xp = villagerTag.getAs("Xp", TagInt.class).getIntData();
entityVillager.setExperience(xp);
}
}
} else if (myPet instanceof MySlime) {
((Slime) normalEntity).setSize(((MySlime) myPet).getSize());
} else if (myPet instanceof MyZombieVillager) {
Villager.Profession profession = Villager.Profession.values()[((MyZombieVillager) myPet).getProfession()];
EntityZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle();
nmsEntity.setVillagerData(nmsEntity.getVillagerData().withType(IRegistry.VILLAGER_TYPE.get(new MinecraftKey(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))).withLevel(((MyZombieVillager) myPet).getTradingLevel()).withProfession(IRegistry.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT)))));
} else if (myPet instanceof MyWitherSkeleton) {
normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.STONE_SWORD));
} else if (myPet instanceof MySkeleton) {
normalEntity.getEquipment().setItemInMainHand(new ItemStack(Material.BOW));
} else if (myPet instanceof MyHorse) {
Horse.Style style = Horse.Style.values()[(((MyHorse) myPet).getVariant() >>> 8)];
Horse.Color color = Horse.Color.values()[(((MyHorse) myPet).getVariant() & 0xFF)];
((Horse) normalEntity).setColor(color);
((Horse) normalEntity).setStyle(style);
if (((MyHorse) myPet).hasSaddle()) {
((Horse) normalEntity).getInventory().setSaddle(((MyHorse) myPet).getSaddle().clone());
}
if (((MyHorse) myPet).hasArmor()) {
((Horse) normalEntity).getInventory().setArmor(((MyHorse) myPet).getArmor().clone());
}
((Horse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MySkeletonHorse) {
((SkeletonHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyZombieHorse) {
((ZombieHorse) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyLlama) {
((Llama) normalEntity).setColor(Llama.Color.values()[Math.max(0, Math.min(3, ((MyLlama) myPet).getVariant()))]);
((Llama) normalEntity).setCarryingChest(((MyLlama) myPet).hasChest());
if (((MyLlama) myPet).hasDecor()) {
((Llama) normalEntity).getInventory().setDecor(((MyLlama) myPet).getDecor());
}
((Llama) normalEntity).setOwner(myPet.getOwner().getPlayer());
} else if (myPet instanceof MyRabbit) {
((Rabbit) normalEntity).setRabbitType(((MyRabbit) myPet).getVariant().getBukkitType());
} else if (myPet instanceof MyParrot) {
((Parrot) normalEntity).setVariant(Parrot.Variant.values()[((MyParrot) myPet).getVariant()]);
} else if (myPet instanceof MyTropicalFish) {
((CraftTropicalFish) normalEntity).getHandle().setVariant(((MyTropicalFish) myPet).getVariant());
} else if (myPet instanceof MyPufferfish) {
((PufferFish) normalEntity).setPuffState(((MyPufferfish) myPet).getPuffState().ordinal());
} else if (myPet instanceof MyPhantom) {
((Phantom) normalEntity).setSize(((MyPhantom) myPet).getSize());
} else if (myPet instanceof MyCat) {
((Cat) normalEntity).setCatType(((MyCat) myPet).getCatType());
((Cat) normalEntity).setCollarColor(((MyCat) myPet).getCollarColor());
} else if (myPet instanceof MyMooshroom) {
((MushroomCow) normalEntity).setVariant(MushroomCow.Variant.values()[((MyMooshroom) myPet).getType().ordinal()]);
} else if (myPet instanceof MyPanda) {
((Panda) normalEntity).setMainGene(((MyPanda) myPet).getMainGene());
((Panda) normalEntity).setHiddenGene(((MyPanda) myPet).getHiddenGene());
} else if (myPet instanceof WanderingTrader) {
MyWanderingTrader traderPet = (MyWanderingTrader) myPet;
if (traderPet.hasOriginalData()) {
TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(normalEntity);
for (String key : traderPet.getOriginalData().getCompoundData().keySet()) {
villagerTag.put(key, traderPet.getOriginalData().get(key));
}
MyPetApi.getPlatformHelper().applyTagToEntity(villagerTag, normalEntity);
}
} else if (myPet instanceof MyBee) {
((Bee) normalEntity).setHasNectar(((MyBee) myPet).hasNectar());
((Bee) normalEntity).setHasStung(((MyBee) myPet).hasStung());
}
if (myPet instanceof MyPetBaby && normalEntity instanceof Ageable) {
if (((MyPetBaby) myPet).isBaby()) {
((Ageable) normalEntity).setBaby();
} else {
((Ageable) normalEntity).setAdult();
}
}
}
Aggregations