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

The following examples show how to use net.minecraft.network.PacketBuffer#writeShort() . 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: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void writeInitialSyncData(PacketBuffer buf) {
    buf.writeByte(this.frontFacing.getIndex());
    buf.writeInt(this.paintingColor);
    buf.writeShort(mteTraits.size());
    for (MTETrait trait : mteTraits) {
        buf.writeVarInt(trait.getNetworkID());
        trait.writeInitialData(buf);
    }
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = getCoverAtSide(coverSide);
        if (coverBehavior != null) {
            int coverId = CoverDefinition.getNetworkIdForCover(coverBehavior.getCoverDefinition());
            buf.writeVarInt(coverId);
            coverBehavior.writeInitialSyncData(buf);
        } else {
            buf.writeVarInt(-1);
        }
    }
    buf.writeBoolean(isFragile);
}
 
Example 2
Source File: LongItemStack.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void writeItemStack(PacketBuffer packetBuffer) {
    if (itemStack.isEmpty()) {
        packetBuffer.writeShort(-1);
    } else {
        packetBuffer.writeShort(Item.getIdFromItem(itemStack.getItem()));
        packetBuffer.writeVarInt(itemStack.getCount());
        packetBuffer.writeShort(itemStack.getMetadata());
        NBTTagCompound nbttagcompound = null;

        if (itemStack.getItem().isDamageable() ||
            itemStack.getItem().getShareTag()) {
            nbttagcompound = itemStack.getItem().getNBTShareTag(itemStack);
        }
        packetBuffer.writeCompoundTag(nbttagcompound);
    }
}
 
Example 3
Source File: MixinC00Handshake.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void writePacketData(PacketBuffer buf) {
    buf.writeVarIntToBuffer(this.protocolVersion);
    buf.writeString(this.ip + (AntiForge.enabled && AntiForge.blockFML && !Minecraft.getMinecraft().isIntegratedServerRunning() ? "" : "\0FML\0"));
    buf.writeShort(this.port);
    buf.writeVarIntToBuffer(this.requestedState.getId());
}
 
Example 4
Source File: MixinC00Handshake.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void writePacketData(PacketBuffer buf) {
    buf.writeVarIntToBuffer(this.protocolVersion);
    buf.writeString(this.ip + (AntiForge.enabled && AntiForge.blockFML && !Minecraft.getMinecraft().isIntegratedServerRunning() ? "" : "\0FML\0"));
    buf.writeShort(this.port);
    buf.writeVarIntToBuffer(this.requestedState.getId());
}
 
Example 5
Source File: PacketChangeColor.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void encode(PacketChangeColor msg, PacketBuffer buffer) {
    buffer.writeShort(msg.red);
    buffer.writeShort(msg.green);
    buffer.writeShort(msg.blue);
    buffer.writeShort(msg.red_inner);
    buffer.writeShort(msg.green_inner);
    buffer.writeShort(msg.blue_inner);
}
 
Example 6
Source File: TileAtmosphereDetector.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void writeDataToNetwork(ByteBuf out, byte id) {
	//Send the unlocalized name over the net to reduce chances of foulup due to client/server inconsistencies
	if(id == 0) {
		PacketBuffer buf = new PacketBuffer(out);
		buf.writeShort(atmosphereToDetect.getUnlocalizedName().length());
		buf.writeString(atmosphereToDetect.getUnlocalizedName());
	}
}
 
Example 7
Source File: CoverFacade.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer packetBuffer) {
    super.writeInitialSyncData(packetBuffer);
    packetBuffer.writeShort(Item.getIdFromItem(facadeStack.getItem()));
    packetBuffer.writeShort(Items.FEATHER.getDamage(facadeStack));
}
 
Example 8
Source File: PacketDimInfo.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = new NBTTagCompound();
	out.writeInt(dimNumber);
	boolean flag = dimProperties == null;
	
	if(!flag) {
		
		//Try to send the nbt data of the dimension to the client, if it fails(probably due to non existent Biome ids) then remove the dimension
		PacketBuffer packetBuffer = new PacketBuffer(out);
		try {
			dimProperties.writeToNBT(nbt);
			out.writeBoolean(false);
			packetBuffer.writeCompoundTag(nbt);
			
			out.writeShort(dimProperties.getRequiredArtifacts().size());
			for(ItemStack i : dimProperties.getRequiredArtifacts()) {
				NBTTagCompound nbt2 = new NBTTagCompound(); 
				i.writeToNBT(nbt2);
				packetBuffer.writeCompoundTag(nbt2);
			}
			
		} catch(NullPointerException e) {
			out.writeBoolean(true);
			e.printStackTrace();
			Logger.getLogger("advancedRocketry").warning("Dimension " + dimNumber + " has thrown an exception trying to write NBT, deleting!");
			DimensionManager.getInstance().deleteDimension(dimNumber);
		}
		
		if(!dimProperties.customIcon.isEmpty())
		{
			packetBuffer.writeShort(dimProperties.customIcon.length());
			packetBuffer.writeString(dimProperties.customIcon);
		}
		else
			packetBuffer.writeShort(0);

	}
	else
		out.writeBoolean(flag);

}
 
Example 9
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(Short o, PacketBuffer output) {
	output.writeShort(o);
}
 
Example 10
Source File: SyncableShort.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeShort(value);
}
 
Example 11
Source File: SyncableFlags.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeShort(value);
}