use of net.minecraft.nbt.NbtCompound in project MCDoom by AzureDoom.
the class DoomEquipmentUtils method getNbtForEnchantments.
public static NbtCompound getNbtForEnchantments(ItemStack breakingStack, ItemStack ruinedStack) {
Set<String> enchantmentStrings = new HashSet<>();
for (Map.Entry<Enchantment, Integer> ench : EnchantmentHelper.get(breakingStack).entrySet()) {
String enchantString = Registry.ENCHANTMENT.getId(ench.getKey()) + ">" + ench.getValue();
enchantmentStrings.add(enchantString);
}
if (!enchantmentStrings.isEmpty()) {
NbtCompound tag = ruinedStack.getNbt();
if (tag == null)
tag = new NbtCompound();
tag.putString(TAG, String.join(",", enchantmentStrings));
return tag;
}
return null;
}
use of net.minecraft.nbt.NbtCompound in project Polymorph by TheIllusiveC4.
the class AbstractStackRecipeData method readNbt.
@Override
public void readNbt(NbtCompound pCompound) {
if (pCompound.contains("SelectedRecipe")) {
this.loadedRecipe = new Identifier(pCompound.getString("SelectedRecipe"));
}
if (pCompound.contains("RecipeDataSet")) {
Set<RecipePair> dataset = this.getRecipesList();
dataset.clear();
NbtList list = pCompound.getList("RecipeDataSet", NbtType.COMPOUND);
for (NbtElement inbt : list) {
NbtCompound tag = (NbtCompound) inbt;
Identifier id = Identifier.tryParse(tag.getString("Id"));
ItemStack stack = ItemStack.fromNbt(tag.getCompound("ItemStack"));
dataset.add(new RecipePairImpl(id, stack));
}
}
}
use of net.minecraft.nbt.NbtCompound in project Rug by RubixDev.
the class PeekCommand method execute.
private static int execute(CommandContext<ServerCommandSource> context, boolean isEnderChest) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();
PlayerManager playerManager = source.getServer().getPlayerManager();
GameProfile targetPlayerProfile = GameProfileArgumentType.getProfileArgument(context, "player").iterator().next();
ServerPlayerEntity targetPlayer = playerManager.getPlayer(targetPlayerProfile.getName());
ServerPlayerEntity executingPlayer = source.getPlayer();
if (targetPlayer == null) {
targetPlayer = playerManager.createPlayer(targetPlayerProfile);
NbtCompound targetPlayerData = playerManager.loadPlayerData(targetPlayer);
if (targetPlayerData == null) {
source.sendError(Text.of("Targeted player's data could not be found. Was he ever in this world?"));
return 0;
}
@SuppressWarnings("deprecation") ServerWorld world = source.getServer().getWorld(DimensionType.worldFromDimensionNbt(new Dynamic<>(NbtOps.INSTANCE, targetPlayerData.get("Dimension"))).result().orElseThrow());
if (world != null)
targetPlayer.setWorld(world);
}
if (isEnderChest) {
showEnderChest(executingPlayer, targetPlayer);
} else {
showInventory(executingPlayer, targetPlayer);
}
return 1;
}
use of net.minecraft.nbt.NbtCompound in project Rug by RubixDev.
the class BlockMixin method onDropStacks.
@Inject(method = "dropStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)V", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/entity/BlockEntity;Lnet/minecraft/entity/Entity;Lnet/minecraft/item/ItemStack;)Ljava/util/List;"))
private static void onDropStacks(BlockState state, World world, BlockPos pos, BlockEntity blockEntity, Entity entity, ItemStack stack, CallbackInfo ci) {
boolean usesSilkTouch = EnchantmentHelper.get(stack).containsKey(Enchantments.SILK_TOUCH) && stack.getItem() != Items.ENCHANTED_BOOK;
if (RugSettings.silkTouchFarmland && state.isOf(Blocks.FARMLAND) && usesSilkTouch) {
dropStack(world, pos, new ItemStack(Items.FARMLAND));
ci.cancel();
} else if (RugSettings.silkTouchPathBlocks && state.isOf(Blocks.DIRT_PATH) && usesSilkTouch) {
dropStack(world, pos, new ItemStack(Items.DIRT_PATH));
ci.cancel();
} else if (RugSettings.silkTouchBuddingAmethysts && state.isOf(Blocks.BUDDING_AMETHYST) && usesSilkTouch) {
dropStack(world, pos, new ItemStack(Items.BUDDING_AMETHYST));
ci.cancel();
} else if (RugSettings.silkTouchSpawners && state.isOf(Blocks.SPAWNER) && usesSilkTouch) {
ItemStack newStack = new ItemStack(Items.SPAWNER);
NbtCompound tag = blockEntity.createNbt();
tag.remove("id");
tag.remove("x");
tag.remove("y");
tag.remove("z");
newStack.setSubNbt("BlockEntityTag", tag);
dropStack(world, pos, newStack);
ci.cancel();
}
}
use of net.minecraft.nbt.NbtCompound in project Primeval by devs-immortal.
the class PitKilnBlockEntity method toInitialChunkDataNbt.
@Override
public NbtCompound toInitialChunkDataNbt() {
NbtCompound nbtCompound = new NbtCompound();
for (int i = 0; i < 4; i++) {
nbtCompound.put(("Item" + i), this.inventory[i].writeNbt(new NbtCompound()));
}
nbtCompound.putInt("burnTimer", this.burnTimer);
return nbtCompound;
}
Aggregations