Search in sources :

Example 26 with MinecraftKey

use of net.minecraft.server.v1_16_R1.MinecraftKey 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_R1.ItemStack itemstack = net.minecraft.server.v1_16_R1.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("bE", entityVillager, foodLevel);
                }
                if (villagerTag.containsKey("Gossips")) {
                    TagList inventoryTag = villagerTag.get("Gossips");
                    NBTTagList vanillaNBT = (NBTTagList) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
                    ((Reputation) ReflectionUtil.getFieldValue(EntityVillager.class, entityVillager, "bF")).a(new Dynamic<>(DynamicOpsNBT.a, vanillaNBT));
                }
                if (villagerTag.containsKey("LastRestock")) {
                    long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
                    ReflectionUtil.setFieldValue("bJ", entityVillager, lastRestock);
                }
                if (villagerTag.containsKey("LastGossipDecay")) {
                    long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
                    ReflectionUtil.setFieldValue("bH", entityVillager, lastGossipDecay);
                }
                if (villagerTag.containsKey("RestocksToday")) {
                    int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
                    ReflectionUtil.setFieldValue("bK", entityVillager, restocksToday);
                }
                // AssignProfessionWhenSpawned
                ReflectionUtil.setFieldValue("bM", 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();
        }
    }
}
Also used : CraftTropicalFish(org.bukkit.craftbukkit.v1_16_R1.entity.CraftTropicalFish) CraftVillagerZombie(org.bukkit.craftbukkit.v1_16_R1.entity.CraftVillagerZombie) CraftVillager(org.bukkit.craftbukkit.v1_16_R1.entity.CraftVillager) CraftVillager(org.bukkit.craftbukkit.v1_16_R1.entity.CraftVillager) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R1(net.minecraft.server.v1_16_R1) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby)

Example 27 with MinecraftKey

use of net.minecraft.server.v1_16_R1.MinecraftKey in project MyPet by xXKeyleXx.

the class EntityRegistry method registerEntityType.

@SuppressWarnings("unchecked")
protected void registerEntityType(MyPetType petType, String key, RegistryBlocks<EntityTypes<?>> entityRegistry) {
    EntitySize size = entityRegistry.get(new MinecraftKey(key.toLowerCase())).l();
    entityTypes.put(petType, IRegistry.a(entityRegistry, "mypet_" + key.toLowerCase(), EntityTypes.Builder.a(EnumCreatureType.CREATURE).b().a().a(size.width, size.height).a(key)));
    registerDefaultAttributes(entityTypes.get(petType), (EntityTypes<? extends EntityLiving>) ReflectionUtil.getFieldValue(EntityTypes.class, null, ("" + petType.getTypeID()).toUpperCase()));
    overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry);
}
Also used : EntitySize(net.minecraft.server.v1_16_R3.EntitySize) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Example 28 with MinecraftKey

use of net.minecraft.server.v1_16_R1.MinecraftKey in project MyPet by xXKeyleXx.

the class ConfigItem method load.

public void load(MaterialHolder material, String data) {
    MinecraftKey key = new MinecraftKey(material.getLegacyName().getName());
    Item item = Item.REGISTRY.get(key);
    if (item == null) {
        return;
    }
    net.minecraft.server.v1_9_R2.ItemStack is = new net.minecraft.server.v1_9_R2.ItemStack(item, 1, material.getLegacyName().getData());
    if (data != null) {
        NBTTagCompound tag = null;
        String nbtString = data.trim();
        if (nbtString.startsWith("{") && nbtString.endsWith("}")) {
            try {
                tag = MojangsonParser.parse(nbtString);
            } catch (Exception e) {
                MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.UNDERLINE + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
                MyPetApi.getLogger().warning(item.getName() + " " + nbtString);
            }
            if (tag != null) {
                is.setTag(tag);
            }
        }
    }
    this.item = CraftItemStack.asCraftMirror(is);
}
Also used : Item(net.minecraft.server.v1_9_R2.Item) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_9_R2.MinecraftKey) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 29 with MinecraftKey

use of net.minecraft.server.v1_16_R1.MinecraftKey in project Citizens2 by CitizensDev.

the class NMSImpl method registerEntityClass.

@Override
public void registerEntityClass(Class<?> clazz) {
    if (ENTITY_REGISTRY == null)
        return;
    Class<?> search = clazz;
    while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
        MinecraftKey key = ENTITY_REGISTRY.b(search);
        if (key == null)
            continue;
        int code = ENTITY_REGISTRY.a(search);
        ENTITY_REGISTRY.put(code, key, (Class<? extends Entity>) clazz);
        return;
    }
    throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
Also used : PathEntity(net.minecraft.server.v1_11_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.server.v1_11_R1.Entity) MinecraftKey(net.minecraft.server.v1_11_R1.MinecraftKey) PathPoint(net.minecraft.server.v1_11_R1.PathPoint)

Example 30 with MinecraftKey

use of net.minecraft.server.v1_16_R1.MinecraftKey in project Citizens2 by CitizensDev.

the class NMSImpl method registerEntityClass.

@Override
public void registerEntityClass(Class<?> clazz) {
    if (ENTITY_REGISTRY == null)
        return;
    Class<?> search = clazz;
    while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
        EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
        MinecraftKey key = ENTITY_REGISTRY.getKey(type);
        if (key == null || type == null)
            continue;
        CITIZENS_ENTITY_TYPES.put(clazz, type);
        int code = ENTITY_REGISTRY.a(type);
        ENTITY_REGISTRY.put(code, key, type);
        return;
    }
    throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_15_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_15_R1.PathEntity) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey) PathPoint(net.minecraft.server.v1_15_R1.PathPoint)

Aggregations

MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)9 Field (java.lang.reflect.Field)8 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)6 MinecraftKey (net.minecraft.server.v1_15_R1.MinecraftKey)6 MinecraftKey (net.minecraft.server.v1_16_R2.MinecraftKey)6 LivingEntity (org.bukkit.entity.LivingEntity)6 MinecraftKey (net.minecraft.server.v1_13_R2.MinecraftKey)5 MinecraftKey (net.minecraft.server.v1_14_R1.MinecraftKey)5 MinecraftKey (net.minecraft.server.v1_11_R1.MinecraftKey)4 MinecraftKey (net.minecraft.server.v1_12_R1.MinecraftKey)4 MinecraftKey (net.minecraft.server.v1_16_R1.MinecraftKey)4 NamespacedKey (org.bukkit.NamespacedKey)3 EntityType (org.bukkit.entity.EntityType)3 MobSpawningMethod (dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod)2 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)2 List (java.util.List)2 Entity (net.minecraft.server.v1_11_R1.Entity)2 TileEntityMobSpawner (net.minecraft.server.v1_11_R1.TileEntityMobSpawner)2 Entity (net.minecraft.server.v1_12_R1.Entity)2 TileEntityMobSpawner (net.minecraft.server.v1_12_R1.TileEntityMobSpawner)2