Search in sources :

Example 1 with MinecraftKey

use of net.minecraft.server.v1_15_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_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_15_R1.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 3 with MinecraftKey

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

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

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

Aggregations

SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 ItemStack (org.bukkit.inventory.ItemStack)2 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 EntitySize (net.minecraft.server.v1_16_R3.EntitySize)1 MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)1 Item (net.minecraft.server.v1_8_R3.Item)1 MinecraftKey (net.minecraft.server.v1_8_R3.MinecraftKey)1