Java Code Examples for net.minecraft.nbt.CompoundTag#put()

The following examples show how to use net.minecraft.nbt.CompoundTag#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
        method = "toTag",
        at = @At(value = "INVOKE", shift = At.Shift.BEFORE, ordinal = 0,
                target = "Lnet/minecraft/nbt/CompoundTag;put(Ljava/lang/String;Lnet/minecraft/nbt/Tag;)Lnet/minecraft/nbt/Tag;")
)
private void onToTag(CompoundTag compoundTag_1, CallbackInfoReturnable<CompoundTag> cir)
{
    if (CarpetExtraSettings.reloadSuffocationFix)
    {
        Box box = this.getBoundingBox();
        compoundTag_1.put("CM_Box", this.toListTag(box.x1, box.y1, box.z1, box.x2, box.y2, box.z2));
    }
}
 
Example 2
Source File: PistonBlockEntity_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "toTag", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void onToTag(CompoundTag compoundTag_1, CallbackInfoReturnable<CompoundTag> cir)
{
    if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null)
    {
        //Leave name "carriedTileEntityCM" instead of "carriedBlockEntityCM" for upgrade compatibility with 1.13.2 movable TE
        compoundTag_1.put("carriedTileEntityCM", this.carriedBlockEntity.toTag(new CompoundTag()));
    }
}
 
Example 3
Source File: ClientNetworkHandler.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void clientCommand(String command)
{
    CompoundTag tag = new CompoundTag();
    tag.putString("id", command);
    tag.putString("command", command);
    CompoundTag outer = new CompoundTag();
    outer.put("clientCommand", tag);
    CarpetClient.getPlayer().networkHandler.sendPacket(new CustomPayloadC2SPacket(
            CarpetClient.CARPET_CHANNEL,
            (new PacketByteBuf(Unpooled.buffer())).writeVarInt(CarpetClient.DATA).writeCompoundTag(outer)
    ));
}
 
Example 4
Source File: EntityValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    CompoundTag tag = new CompoundTag();
    tag.put("Data", getEntity().toTag( new CompoundTag()));
    tag.put("Name", StringTag.of(Registry.ENTITY_TYPE.getId(entity.getType()).toString()));
    return tag;
}
 
Example 5
Source File: BlockValue.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Override
public Tag toTag(boolean force)
{
    if (!force) throw new NBTSerializableValue.IncompatibleTypeException(this);
    // follows falling block convertion
    CompoundTag tag =  new CompoundTag();
    CompoundTag state = new CompoundTag();
    BlockState s = getBlockState();
    state.put("Name", StringTag.of(Registry.BLOCK.getId(s.getBlock()).toString()));
    Collection<Property<?>> properties = s.getProperties();
    if (!properties.isEmpty())
    {
        CompoundTag props = new CompoundTag();
        for (Property<?> p: properties)
        {
            props.put(p.getName(), StringTag.of(s.get(p).toString().toLowerCase(Locale.ROOT)));
        }
        state.put("Properties", props);
    }
    tag.put("BlockState", state);
    CompoundTag dataTag = getData();
    if (dataTag != null)
    {
        tag.put("TileEntityData", dataTag);
    }
    return tag;
}
 
Example 6
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "serialize", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;saveToTag(Lnet/minecraft/nbt/CompoundTag;)Z"), to = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/ProtoChunk;getEntities()Ljava/util/List;")), at = @At(value = "JUMP", opcode = Opcodes.GOTO, ordinal = 2), locals = LocalCapture.CAPTURE_FAILHARD)
private static void serializeCapabilities(ServerWorld serverWorld, Chunk chunk, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable, ChunkPos chunkPos, CompoundTag compoundTag, CompoundTag level) {
	CompoundTag tag = ((CapabilityProviderHolder) chunk).serializeCaps();

	if (tag != null) {
		level.put("ForgeCaps", tag);
	}
}
 
Example 7
Source File: EntityMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "toTag", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;writeCustomDataToTag(Lnet/minecraft/nbt/CompoundTag;)V"))
private void serializeCapabilities(CompoundTag tag, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable) {
	CompoundTag capabilities = serializeCaps();

	if (capabilities != null) {
		tag.put("ForgeCaps", capabilities);
	}
}
 
Example 8
Source File: ItemStackMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "toTag", at = @At(value = "RETURN"))
private void serializeCapabilities(CompoundTag tag, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable) {
	CompoundTag compoundTag = serializeCaps();

	if (compoundTag != null && !compoundTag.isEmpty()) {
		tag.put("ForgeCaps", compoundTag);
	}
}
 
Example 9
Source File: CapabilityDispatcher.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public CompoundTag serializeNBT() {
	CompoundTag tag = new CompoundTag();

	for (int x = 0; x < writers.length; x++) {
		try {
			tag.put(names[x], writers[x].serializeNBT());
		} catch (Exception exception) {
			LogManager.getLogger().error("A capability provider with the name " + names[x] + " has thrown an exception trying to write state. It will not persist. Report this to the mod author", exception);
		}
	}

	return tag;
}
 
Example 10
Source File: ConfigurableElectricMachineBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public CompoundTag toTag(CompoundTag tag) {
    CompoundTag compoundTag = new CompoundTag();
    if (this.hasOwner()) {
        compoundTag.putUuid("owner", this.owner);
    }
    compoundTag.putString("username", this.username);
    compoundTag.putString("publicity", this.publicity.asString());
    if (this.hasTeam()) {
        compoundTag.putString("team", team.toString());
    }
    tag.put("security", compoundTag);
    return tag;
}
 
Example 11
Source File: PotionCmd.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
private void remove(ItemStack stack, String[] args) throws CmdSyntaxError
{
	if(args.length != 2)
		throw new CmdSyntaxError();
	
	int id = parseEffectId(args[1]);
	
	List<StatusEffectInstance> oldEffects =
		PotionUtil.getCustomPotionEffects(stack);
	
	ListTag newEffects = new ListTag();
	for(StatusEffectInstance oldEffect : oldEffects)
	{
		int oldId = StatusEffect.getRawId(oldEffect.getEffectType());
		
		if(oldId == id)
			continue;
		
		CompoundTag effect = new CompoundTag();
		effect.putInt("Id", oldId);
		effect.putInt("Amplifier", oldEffect.getAmplifier());
		effect.putInt("Duration", oldEffect.getDuration());
		newEffects.add(effect);
	}
	
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", newEffects);
	stack.setTag(nbt);
	ChatUtils.message("Effect removed.");
}
 
Example 12
Source File: CrashChestHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	if(!MC.player.inventory.getArmorStack(0).isEmpty())
	{
		ChatUtils.error("Please clear your shoes slot.");
		setEnabled(false);
		return;
	}
	
	// generate item
	ItemStack stack = new ItemStack(Blocks.CHEST);
	CompoundTag nbtCompound = new CompoundTag();
	ListTag nbtList = new ListTag();
	for(int i = 0; i < 40000; i++)
		nbtList.add(new ListTag());
	nbtCompound.put("www.wurstclient.net", nbtList);
	stack.setTag(nbtCompound);
	stack.setCustomName(new LiteralText("Copy Me"));
	
	// give item
	MC.player.inventory.armor.set(0, stack);
	ChatUtils.message("Item has been placed in your shoes slot.");
	setEnabled(false);
}
 
Example 13
Source File: KillPotionHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	// check gamemode
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	// generate potion
	ItemStack stack = new ItemStack(Items.SPLASH_POTION);
	CompoundTag effect = new CompoundTag();
	effect.putInt("Amplifier", 125);
	effect.putInt("Duration", 2000);
	effect.putInt("Id", 6);
	ListTag effects = new ListTag();
	effects.add(effect);
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", effects);
	stack.setTag(nbt);
	String name = "\u00a7rSplash Potion of \u00a74\u00a7lINSTANT DEATH";
	stack.setCustomName(new LiteralText(name));
	
	// give potion
	if(placeStackInHotbar(stack))
		ChatUtils.message("Potion created.");
	else
		ChatUtils.error("Please clear a slot in your hotbar.");
	
	setEnabled(false);
}
 
Example 14
Source File: TrollPotionHack.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEnable()
{
	// check gamemode
	if(!MC.player.abilities.creativeMode)
	{
		ChatUtils.error("Creative mode only.");
		setEnabled(false);
		return;
	}
	
	// generate potion
	ItemStack stack = new ItemStack(Items.SPLASH_POTION);
	ListTag effects = new ListTag();
	for(int i = 1; i <= 23; i++)
	{
		CompoundTag effect = new CompoundTag();
		effect.putInt("Amplifier", Integer.MAX_VALUE);
		effect.putInt("Duration", Integer.MAX_VALUE);
		effect.putInt("Id", i);
		effects.add(effect);
	}
	CompoundTag nbt = new CompoundTag();
	nbt.put("CustomPotionEffects", effects);
	stack.setTag(nbt);
	String name = "\u00a7rSplash Potion of Trolling";
	stack.setCustomName(new LiteralText(name));
	
	// give potion
	if(placeStackInHotbar(stack))
		ChatUtils.message("Potion created.");
	else
		ChatUtils.error("Please clear a slot in your hotbar.");
	
	setEnabled(false);
}
 
Example 15
Source File: CandyComponent.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
	ListTag list = new ListTag();
	Iterator<Map.Entry<UUID, Long>> iterator = lastGivenCandy.entrySet().iterator();
	while (iterator.hasNext()) {
		Map.Entry<UUID, Long> entry = iterator.next();
		CompoundTag item = new CompoundTag();
		item.putUuid("uuid", entry.getKey());
		item.putLong("time", entry.getValue());
		list.add(item);
	}
	tag.put("entities", list);
	return tag;
}
 
Example 16
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag t) {
	CompoundTag tag = super.toTag(t);
	tag.put("Left", leftItem.toTag(new CompoundTag()));
	tag.put("Right", rightItem.toTag(new CompoundTag()));
	return tag;
}
 
Example 17
Source File: BasicSolarPanelPartBlockEntity.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
public CompoundTag toTag(CompoundTag tag) {
    tag = super.toTag(tag);
    CompoundTag baseTag = new CompoundTag();
    baseTag.putInt("X", this.basePos.getX());
    baseTag.putInt("Y", this.basePos.getY());
    baseTag.putInt("Z", this.basePos.getZ());

    tag.put("Base", baseTag);
    return tag;
}
 
Example 18
Source File: ConfigurableElectricMachineBlock.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public ItemStack getPickStack(BlockView blockView_1, BlockPos blockPos_1, BlockState blockState_1) {
    ItemStack stack = super.getPickStack(blockView_1, blockPos_1, blockState_1);
    CompoundTag tag = (stack.getTag() != null ? stack.getTag() : new CompoundTag());
    if (blockView_1.getBlockEntity(blockPos_1) != null) {
        tag.put("BlockEntityTag", blockView_1.getBlockEntity(blockPos_1).toTag(new CompoundTag()));
    }

    stack.setTag(tag);
    return stack;
}
 
Example 19
Source File: BlockEntityMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "writeIdentifyingData", at = @At("RETURN"))
private void serializeCapabilities(CompoundTag compoundTag, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable) {
	if (getCapabilities() != null) {
		compoundTag.put("ForgeCaps", serializeCaps());
	}
}
 
Example 20
Source File: TinyPumpkinBlockEntity.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public CompoundTag toClientTag(CompoundTag tag) {
	tag.put("Left", leftItem.toTag(new CompoundTag()));
	tag.put("Right", rightItem.toTag(new CompoundTag()));
	return tag;
}