Java Code Examples for net.minecraft.network.PacketBuffer#writeItemStack()

The following examples show how to use net.minecraft.network.PacketBuffer#writeItemStack() . 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: BookBot.java    From ForgeHax with MIT License 6 votes vote down vote up
private void sendBook(ItemStack stack) {
  NBTTagList pages = new NBTTagList(); // page tag list
  
  // copy pages into NBT
  for (int i = 0; i < MAX_PAGES && parser.hasNext(); i++) {
    pages.appendTag(new NBTTagString(parser.next().trim()));
    page++;
  }
  
  // set our client side book
  if (stack.hasTagCompound()) {
    stack.getTagCompound().setTag("pages", pages);
  } else {
    stack.setTagInfo("pages", pages);
  }
  
  // publish the book
  stack.setTagInfo("author", new NBTTagString(getLocalPlayer().getName()));
  stack.setTagInfo(
      "title",
      new NBTTagString(parent.name.get().replaceAll(NUMBER_TOKEN, "" + getBook()).trim()));
  
  PacketBuffer buff = new PacketBuffer(Unpooled.buffer());
  buff.writeItemStack(stack);
  MC.getConnection().sendPacket(new CPacketCustomPayload("MC|BSign", buff));
}
 
Example 2
Source File: PacketAsteroidInfo.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void write(ByteBuf out) {
	PacketBuffer packetBuffer = new PacketBuffer(out);
	NBTTagCompound nbt = new NBTTagCompound();
	
	packetBuffer.writeString(asteroid.ID);
	packetBuffer.writeInt(asteroid.distance);
	packetBuffer.writeInt(asteroid.mass);
	packetBuffer.writeInt(asteroid.minLevel);
	packetBuffer.writeFloat(asteroid.massVariability);
	packetBuffer.writeFloat(asteroid.richness);					//factor of the ratio of ore to stone
	packetBuffer.writeFloat(asteroid.richnessVariability);		//variability of richness
	packetBuffer.writeFloat(asteroid.probability);				//probability of the asteroid spawning
	packetBuffer.writeFloat(asteroid.timeMultiplier);
	
	packetBuffer.writeInt(asteroid.stackProbabilites.size());
	for(int i = 0; i < asteroid.stackProbabilites.size(); i++)
	{
		packetBuffer.writeItemStack(asteroid.itemStacks.get(i));
		packetBuffer.writeFloat(asteroid.stackProbabilites.get(i));
	}
}
 
Example 3
Source File: CreateRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public void write(PacketBuffer buffer, CreateRecipe recipe) {
    buffer.writeString(recipe.group);

    for (Ingredient ingredient : recipe.input) {
        ingredient.write(buffer);
    }

    buffer.writeItemStack(recipe.output);
}
 
Example 4
Source File: ChoppingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(PacketBuffer buffer, ChoppingRecipe recipe)
{
    buffer.writeString(recipe.group);
    recipe.input.write(buffer);
    buffer.writeItemStack(recipe.output);
    buffer.writeDouble(recipe.outputMultiplier);
    buffer.writeDouble(recipe.hitCountMultiplier);
    buffer.writeVarInt(recipe.maxOutput);
    buffer.writeVarInt(recipe.sawingTime);
}
 
Example 5
Source File: DryingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(PacketBuffer buffer, DryingRecipe recipe)
{
    buffer.writeString(recipe.group);
    recipe.input.write(buffer);
    buffer.writeItemStack(recipe.output);
    buffer.writeVarInt(recipe.time);
}
 
Example 6
Source File: MessageBackpackUpdate.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	buffer.writeInt(_entityId);
	buffer.writeByte(_type.ordinal());
	switch (_type) {
		case STACK: buffer.writeItemStack(_stack); break;
		case OPEN: buffer.writeBoolean(_open); break;
		default: throw new RuntimeException("Invalid UpdateType");
	}
}
 
Example 7
Source File: PacketGhostSlot.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static void encode(PacketGhostSlot msg, PacketBuffer buffer) {
    buffer.writeInt(msg.slotNumber);
    buffer.writeItemStack(msg.stack);
}
 
Example 8
Source File: PlayerInventoryUIFactory.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void writeHolderToSyncData(PacketBuffer syncData, PlayerInventoryHolder holder) {
    syncData.writeByte(holder.hand.ordinal());
    syncData.writeItemStack(holder.getCurrentItem());
}
 
Example 9
Source File: ReColourRecipe.java    From EnderStorage with MIT License 4 votes vote down vote up
@Override
public void write(PacketBuffer buffer, ReColourRecipe recipe) {
    buffer.writeString(recipe.group);
    recipe.ingredient.write(buffer);
    buffer.writeItemStack(recipe.output);
}
 
Example 10
Source File: ScrapingMessage.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void encode(PacketBuffer buf)
{
    buf.writeItemStack(stack);
    buf.writeItemStack(ret);
}
 
Example 11
Source File: SyncableItemStack.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeItemStack(this.stack);

}