Search in sources :

Example 6 with CompoundTag

use of com.denizenscript.denizen.nms.util.jnbt.CompoundTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemFrameInvisible method adjust.

public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("invisible") && mechanism.requireBoolean()) {
        CompoundTag compoundTag = NMSHandler.getItemHelper().getNbtData(item.getItemStack());
        Map<String, Tag> result = new LinkedHashMap<>(compoundTag.getValue());
        CompoundTag entityTag = (CompoundTag) result.get("EntityTag");
        Map<String, Tag> entMap;
        if (entityTag != null) {
            entMap = new LinkedHashMap<>(entityTag.getValue());
        } else {
            entMap = new LinkedHashMap<>();
        }
        if (mechanism.getValue().asBoolean()) {
            entMap.put("Invisible", new ByteTag((byte) 1));
        } else {
            entMap.remove("Invisible");
        }
        if (entMap.isEmpty()) {
            result.remove("EntityTag");
        } else {
            result.put("EntityTag", NMSHandler.getInstance().createCompoundTag(entMap));
        }
        compoundTag = NMSHandler.getInstance().createCompoundTag(result);
        item.setItemStack(NMSHandler.getItemHelper().setNbtData(item.getItemStack(), compoundTag));
    }
}
Also used : ByteTag(com.denizenscript.denizen.nms.util.jnbt.ByteTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) Tag(com.denizenscript.denizen.nms.util.jnbt.Tag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ByteTag(com.denizenscript.denizen.nms.util.jnbt.ByteTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with CompoundTag

use of com.denizenscript.denizen.nms.util.jnbt.CompoundTag in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) JNBTListTag(com.denizenscript.denizen.nms.util.jnbt.JNBTListTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag)

Aggregations

CompoundTag (com.denizenscript.denizen.nms.util.jnbt.CompoundTag)7 JNBTListTag (com.denizenscript.denizen.nms.util.jnbt.JNBTListTag)3 Pattern (org.bukkit.block.banner.Pattern)3 ByteTag (com.denizenscript.denizen.nms.util.jnbt.ByteTag)1 Tag (com.denizenscript.denizen.nms.util.jnbt.Tag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 LinkedHashMap (java.util.LinkedHashMap)1 BlockPos (net.minecraft.core.BlockPos)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1