use of net.minecraft.nbt.ListTag in project Tropicraft by Tropicraft.
the class CocktailItem method appendHoverText.
@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag flag) {
Drink drink = getDrink(stack);
if (drink == Drink.COCKTAIL && stack.hasTag() && stack.getTag().contains("Ingredients")) {
final ListTag ingredients = stack.getTag().getList("Ingredients", 10);
for (int i = 0; i < ingredients.size(); ++i) {
CompoundTag ingredient = ingredients.getCompound(i);
int id = ingredient.getByte("IngredientID");
Component ingredientName = Ingredient.ingredientsList[id].getDisplayName();
int ingredientColor = Ingredient.ingredientsList[id].getColor();
// String lvl = StatCollector.translateToLocal("enchantment.level." + count);
// par3List.add(ingredientName + " " + lvl);
tooltip.add(ingredientName);
}
}
}
use of net.minecraft.nbt.ListTag in project MinecraftForge by MinecraftForge.
the class ForgeChunkManager method readForgeForcedChunks.
/**
* Reads the forge forced chunks from the NBT compound. Format is List{modid, List{ChunkPos, List{BlockPos}, List{UUID}}}
*
* @apiNote Internal
*/
public static void readForgeForcedChunks(CompoundTag nbt, TicketTracker<BlockPos> blockForcedChunks, TicketTracker<UUID> entityForcedChunks) {
ListTag forcedChunks = nbt.getList("ForgeForced", Tag.TAG_COMPOUND);
for (int i = 0; i < forcedChunks.size(); i++) {
CompoundTag forcedEntry = forcedChunks.getCompound(i);
String modId = forcedEntry.getString("Mod");
if (ModList.get().isLoaded(modId)) {
ListTag modForced = forcedEntry.getList("ModForced", Tag.TAG_COMPOUND);
for (int j = 0; j < modForced.size(); j++) {
CompoundTag modEntry = modForced.getCompound(j);
long chunkPos = modEntry.getLong("Chunk");
readBlockForcedChunks(modId, chunkPos, modEntry, "Blocks", blockForcedChunks.chunks);
readBlockForcedChunks(modId, chunkPos, modEntry, "TickingBlocks", blockForcedChunks.tickingChunks);
readEntityForcedChunks(modId, chunkPos, modEntry, "Entities", entityForcedChunks.chunks);
readEntityForcedChunks(modId, chunkPos, modEntry, "TickingEntities", entityForcedChunks.tickingChunks);
}
} else {
LOGGER.warn("Found chunk loading data for mod {} which is currently not available or active - it will be removed from the world save.", modId);
}
}
}
use of net.minecraft.nbt.ListTag 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 MyGoat) {
if (((MyGoat) myPet).isScreaming()) {
((Goat) normalEntity).setScreaming(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();
net.minecraft.world.entity.npc.Villager entityVillager = ((CraftVillager) villagerEntity).getHandle();
try {
if (villagerTag.containsKey("Offers")) {
TagCompound offersTag = villagerTag.get("Offers");
CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(offersTag);
entityVillager.setOffers(new MerchantOffers(vanillaNBT));
}
if (villagerTag.containsKey("Inventory")) {
TagList inventoryTag = villagerTag.get("Inventory");
ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
for (int i = 0; i < vanillaNBT.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack = net.minecraft.world.item.ItemStack.of(vanillaNBT.getCompound(i));
ItemStack item = CraftItemStack.asCraftMirror(itemstack);
if (!itemstack.isEmpty()) {
Villager vill = ((Villager) Bukkit.getServer().getEntity(normalEntity.getUniqueId()));
vill.getInventory().addItem(item);
}
}
}
if (villagerTag.containsKey("FoodLevel")) {
byte foodLevel = villagerTag.getAs("FoodLevel", TagByte.class).getByteData();
// Field: foodLevel
ReflectionUtil.setFieldValue("cn", entityVillager, foodLevel);
}
if (villagerTag.containsKey("Gossips")) {
TagList inventoryTag = villagerTag.get("Gossips");
ListTag vanillaNBT = (ListTag) ItemStackNBTConverter.compoundToVanillaCompound(inventoryTag);
// Field: gossips
((GossipContainer) ReflectionUtil.getFieldValue(net.minecraft.world.entity.npc.Villager.class, entityVillager, "co")).update(new Dynamic<>(NbtOps.INSTANCE, vanillaNBT));
}
if (villagerTag.containsKey("LastRestock")) {
long lastRestock = villagerTag.getAs("LastRestock", TagLong.class).getLongData();
// Field: lastRestockGameTime
ReflectionUtil.setFieldValue("cs", entityVillager, lastRestock);
}
if (villagerTag.containsKey("LastGossipDecay")) {
long lastGossipDecay = villagerTag.getAs("LastGossipDecay", TagLong.class).getLongData();
// Field: lastGossipDecayTime
ReflectionUtil.setFieldValue("cq", entityVillager, lastGossipDecay);
}
if (villagerTag.containsKey("RestocksToday")) {
int restocksToday = villagerTag.getAs("RestocksToday", TagInt.class).getIntData();
// Field: numberOfRestocksToday
ReflectionUtil.setFieldValue("ct", entityVillager, restocksToday);
}
// Field: AssignProfessionWhenSpawned
ReflectionUtil.setFieldValue("cv", entityVillager, true);
} catch (Exception e) {
e.printStackTrace();
}
if (villagerTag.containsKey("Xp")) {
int xp = villagerTag.getAs("Xp", TagInt.class).getIntData();
entityVillager.setVillagerXp(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()];
net.minecraft.world.entity.monster.ZombieVillager nmsEntity = ((CraftVillagerZombie) normalEntity).getHandle();
nmsEntity.setVillagerData(nmsEntity.getVillagerData().setType(Registry.VILLAGER_TYPE.get(new ResourceLocation(((MyZombieVillager) myPet).getType().name().toLowerCase(Locale.ROOT)))).setLevel(((MyZombieVillager) myPet).getTradingLevel()).setProfession(Registry.VILLAGER_PROFESSION.get(new ResourceLocation(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 MyAxolotl) {
((Axolotl) normalEntity).setVariant(Axolotl.Variant.values()[((MyAxolotl) 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();
}
}
}
use of net.minecraft.nbt.ListTag in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method compoundToVanillaCompound.
public static Tag compoundToVanillaCompound(TagBase tag) {
switch(TagType.getTypeById(tag.getTagTypeId())) {
case Int:
return IntTag.valueOf(((TagInt) tag).getIntData());
case Short:
return ShortTag.valueOf(((TagShort) tag).getShortData());
case String:
return StringTag.valueOf(((TagString) tag).getStringData());
case Byte:
return ByteTag.valueOf(((TagByte) tag).getByteData());
case Byte_Array:
return new ByteArrayTag(((TagByteArray) tag).getByteArrayData());
case Double:
return DoubleTag.valueOf(((TagDouble) tag).getDoubleData());
case Float:
return FloatTag.valueOf(((TagFloat) tag).getFloatData());
case Int_Array:
return new IntArrayTag(((TagIntArray) tag).getIntArrayData());
case Long:
return LongTag.valueOf(((TagLong) tag).getLongData());
case List:
TagList TagList = (TagList) tag;
ListTag tagList = new ListTag();
for (TagBase tagInList : TagList.getReadOnlyList()) {
tagList.add(compoundToVanillaCompound(tagInList));
}
return tagList;
case Compound:
TagCompound TagCompound = (TagCompound) tag;
CompoundTag tagCompound = new CompoundTag();
for (String name : TagCompound.getCompoundData().keySet()) {
tagCompound.put(name, compoundToVanillaCompound(TagCompound.getCompoundData().get(name)));
}
return tagCompound;
case End:
return null;
}
throw new IllegalArgumentException("Not a valid tag type");
}
use of net.minecraft.nbt.ListTag in project MyPet by xXKeyleXx.
the class ItemStackNBTConverter method vanillaCompoundToCompound.
public static TagBase vanillaCompoundToCompound(Tag vanillaTag) {
switch(vanillaTag.getId()) {
case 1:
return new TagByte(((ByteTag) vanillaTag).getAsByte());
case 2:
return new TagShort(((ShortTag) vanillaTag).getAsShort());
case 3:
return new TagInt(((IntTag) vanillaTag).getAsInt());
case 4:
return new TagLong(((LongTag) vanillaTag).getAsLong());
case 5:
return new TagFloat(((FloatTag) vanillaTag).getAsFloat());
case 6:
return new TagDouble(((DoubleTag) vanillaTag).getAsDouble());
case 7:
return new TagByteArray(((ByteArrayTag) vanillaTag).getAsByteArray());
case 8:
return new TagString(vanillaTag.getAsString());
case 9:
ListTag tagList = (ListTag) vanillaTag;
List compoundList = new ArrayList();
try {
ArrayList list = (ArrayList) TAG_LIST_LIST.get(tagList);
for (Object aList : list) {
compoundList.add(vanillaCompoundToCompound((Tag) aList));
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return new TagList(compoundList);
case 10:
TagCompound compound = new TagCompound();
CompoundTag tagCompound = ((CompoundTag) vanillaTag);
Set<String> keys = tagCompound.getAllKeys();
for (String tagName : keys) {
compound.getCompoundData().put(tagName, vanillaCompoundToCompound(tagCompound.get(tagName)));
}
return compound;
case 11:
return new TagIntArray(((IntArrayTag) vanillaTag).getAsIntArray());
}
return null;
}
Aggregations