Search in sources :

Example 1 with MinecraftKey

use of net.minecraft.server.v1_16_R3.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_8_R3.ItemStack is = new net.minecraft.server.v1_8_R3.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_8_R3.Item) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) MinecraftKey(net.minecraft.server.v1_8_R3.MinecraftKey) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with MinecraftKey

use of net.minecraft.server.v1_16_R3.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_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();
        }
    }
}
Also used : CraftTropicalFish(org.bukkit.craftbukkit.v1_16_R3.entity.CraftTropicalFish) CraftVillagerZombie(org.bukkit.craftbukkit.v1_16_R3.entity.CraftVillagerZombie) CraftVillager(org.bukkit.craftbukkit.v1_16_R3.entity.CraftVillager) CraftVillager(org.bukkit.craftbukkit.v1_16_R3.entity.CraftVillager) ItemStack(org.bukkit.inventory.ItemStack) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) MyPetBaby(de.Keyle.MyPet.api.entity.MyPetBaby)

Example 3 with MinecraftKey

use of net.minecraft.server.v1_16_R3.MinecraftKey in project solinia3-core by mixxit.

the class ForgeUtils method sendForgeMessage.

public static void sendForgeMessage(Player player, String channelName, byte discriminator, String message) throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(stream);
    try {
        // diesieben07 - Forge uses an unsigned byte for the discriminator, for a start
        // dataOut.writeInt(discriminator);
        dataOut.writeByte(discriminator);
        // diesieben07 - But you should really send some kind of length prefix
        // and then only read that much of the string
        // You're already using DataOuput, it has writeUTFString
        // dataOut.write(message.getBytes(StandardCharsets.UTF_8));
        dataOut.writeUTF(message);
        PacketPlayOutCustomPayload packet = new PacketPlayOutCustomPayload(new MinecraftKey(channelName), new PacketDataSerializer(Unpooled.wrappedBuffer(stream.toByteArray())));
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    } finally {
        dataOut.close();
        stream.close();
    }
}
Also used : PacketDataSerializer(net.minecraft.server.v1_15_R1.PacketDataSerializer) DataOutputStream(java.io.DataOutputStream) PacketPlayOutCustomPayload(net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MinecraftKey(net.minecraft.server.v1_15_R1.MinecraftKey)

Example 4 with MinecraftKey

use of net.minecraft.server.v1_16_R3.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 5 with MinecraftKey

use of net.minecraft.server.v1_16_R3.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)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)3 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Entity (net.minecraft.server.v1_11_R1.Entity)1 MinecraftKey (net.minecraft.server.v1_11_R1.MinecraftKey)1 PathEntity (net.minecraft.server.v1_11_R1.PathEntity)1 PathPoint (net.minecraft.server.v1_11_R1.PathPoint)1 Entity (net.minecraft.server.v1_12_R1.Entity)1 MinecraftKey (net.minecraft.server.v1_12_R1.MinecraftKey)1 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)1 PathPoint (net.minecraft.server.v1_12_R1.PathPoint)1 MinecraftKey (net.minecraft.server.v1_15_R1.MinecraftKey)1 PacketDataSerializer (net.minecraft.server.v1_15_R1.PacketDataSerializer)1 PacketPlayOutCustomPayload (net.minecraft.server.v1_15_R1.PacketPlayOutCustomPayload)1 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)1 EntitySize (net.minecraft.server.v1_16_R3.EntitySize)1 MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)1