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

The following examples show how to use net.minecraft.network.PacketBuffer#writeBoolean() . 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: PhysicsObject.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
public void writeSpawnData(ByteBuf buffer) {
    PacketBuffer modifiedBuffer = new PacketBuffer(buffer);

    modifiedBuffer.writeInt(getOwnedChunks().getCenterX());
    modifiedBuffer.writeInt(getOwnedChunks().getCenterZ());
    modifiedBuffer.writeInt(getOwnedChunks().getRadius());

    modifiedBuffer.writeDouble(getWrapperEntity().posX);
    modifiedBuffer.writeDouble(getWrapperEntity().posY);
    modifiedBuffer.writeDouble(getWrapperEntity().posZ);

    modifiedBuffer.writeDouble(getWrapperEntity().getPitch());
    modifiedBuffer.writeDouble(getWrapperEntity().getYaw());
    modifiedBuffer.writeDouble(getWrapperEntity().getRoll());

    getCenterCoord().writeToByteBuf(modifiedBuffer);

    // Make a local copy to avoid potential data races
    BlockPos physicsInfuserPosLocal = getPhysicsInfuserPos();
    modifiedBuffer.writeBoolean(physicsInfuserPosLocal != null);
    if (physicsInfuserPosLocal != null) {
        modifiedBuffer.writeBlockPos(physicsInfuserPosLocal);
    }
}
 
Example 2
Source File: GameProfileSerializer.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static void write(GameProfile o, PacketBuffer output) {
	final UUID uuid = o.getId();
	output.writeString(uuid == null? "" : uuid.toString());
	output.writeString(Strings.nullToEmpty(o.getName()));
	final PropertyMap properties = o.getProperties();
	output.writeVarInt(properties.size());
	for (Property p : properties.values()) {
		output.writeString(p.getName());
		output.writeString(p.getValue());

		final String signature = p.getSignature();
		if (signature != null) {
			output.writeBoolean(true);
			output.writeString(signature);
		} else {
			output.writeBoolean(false);
		}
	}
}
 
Example 3
Source File: SyncableUUID.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	if (uuid != null) {
		stream.writeBoolean(true);
		stream.writeUniqueId(uuid);
	} else {
		stream.writeBoolean(false);
	}
}
 
Example 4
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 5
Source File: ComponentMusicPlayer.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,	EntityPlayer player) {
	NBTTagCompound tag = itemStack.getTagCompound();
	String record = tag.getString("record");
	
	//Determine if the record should play.
	boolean shouldPlay = !tag.getBoolean("playing");
	
	int x = tag.getInteger("playingX");
	int y = tag.getInteger("playingY");
	int z = tag.getInteger("playingZ");
	
	if(shouldPlay) {
		x = MathHelper.floor_double(player.posX);
		y = MathHelper.floor_double(player.posY);
		z = MathHelper.floor_double(player.posZ);
	}
	
	//Send the packet to the server, to play the record (or stop playing).
	tag.setBoolean("playing", shouldPlay);
	
	PacketBuffer out = new PacketBuffer(Unpooled.buffer());
	out.writeInt(PacketHandlerServer.MUSIC_PLAYER);
	out.writeInt(x);
	out.writeInt(y);
	out.writeInt(z);
	out.writeBoolean(shouldPlay);
	out.writeInt(player.inventory.currentItem);
	if(shouldPlay) {
		out.writeInt(record.length());
		for(int i = 0; i < record.length(); i++) {
			out.writeChar(record.charAt(i));
		}
	}
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	
	tag.setInteger("onItemRightClickDelay", 10);
	return itemStack;
}
 
Example 6
Source File: MetaTileEntityMultiblockPart.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    MultiblockControllerBase controller = getController();
    buf.writeBoolean(controller != null);
    if (controller != null) {
        buf.writeBlockPos(controller.getPos());
    }
}
 
Example 7
Source File: LaserParticleData.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void write(PacketBuffer buf) {
    buf.writeVarInt(Block.BLOCK_STATE_IDS.get(state));
    buf.writeFloat(size);
    buf.writeFloat(r);
    buf.writeFloat(g);
    buf.writeFloat(b);
    buf.writeFloat(maxAgeMul);
    buf.writeBoolean(depthTest);
}
 
Example 8
Source File: RecipeLogicSteam.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialData(PacketBuffer buf) {
    super.writeInitialData(buf);
    buf.writeByte(getVentingSide().getIndex());
    buf.writeBoolean(needsVenting);
    buf.writeBoolean(ventingStuck);
}
 
Example 9
Source File: MethodParamsCodec.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static void writeArg(PacketBuffer output, int argIndex, IStreamWriter<Object> writer, boolean isNullable, Object value) throws IOException {
	if (isNullable) {
		if (value == null) {
			output.writeBoolean(false);
			return;
		}
		output.writeBoolean(true);
	} else {
		Preconditions.checkNotNull(value, "Only @NullableArg arguments can be null");
	}

	writer.writeToStream(value, output);
}
 
Example 10
Source File: SimpleMachineMetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeByte(getOutputFacing().getIndex());
    buf.writeBoolean(autoOutputItems);
    buf.writeBoolean(autoOutputFluids);
}
 
Example 11
Source File: MetaTileEntityHolder.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    if (metaTileEntity != null) {
        buf.writeBoolean(true);
        buf.writeVarInt(GregTechAPI.META_TILE_ENTITY_REGISTRY.getIdByObjectName(metaTileEntity.metaTileEntityId));
        metaTileEntity.writeInitialSyncData(buf);
    } else buf.writeBoolean(false);
}
 
Example 12
Source File: SyncableTank.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	if (fluid != null) {
		stream.writeBoolean(true);
		final String id = FluidRegistry.getFluidName(fluid.getFluid());
		stream.writeString(id);
		stream.writeInt(fluid.amount);
		stream.writeCompoundTag(fluid.tag);
	} else {
		stream.writeBoolean(false);
	}
}
 
Example 13
Source File: MessageStartPiloting.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer packetBuf = new PacketBuffer(buf);
    packetBuf.writeInt(posToStartPiloting.getX());
    packetBuf.writeInt(posToStartPiloting.getY());
    packetBuf.writeInt(posToStartPiloting.getZ());
    //use absolute coordinates instead of writeBlockPos in case we ever add compatibility with cubic chunks
    packetBuf.writeBoolean(setPhysicsWrapperEntityToPilot);
    packetBuf.writeEnumValue(controlType);
}
 
Example 14
Source File: MultiblockControllerBase.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(structureFormed);
}
 
Example 15
Source File: Widget.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void writeToBuf(PacketBuffer buf) {
    buf.writeVarInt(button);
    buf.writeBoolean(isShiftClick);
    buf.writeBoolean(isCtrlClick);
}
 
Example 16
Source File: MetaTileEntityPrimitiveBlastFurnace.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(isActive);
}
 
Example 17
Source File: MetaTileEntityItemCollector.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(isWorking);
}
 
Example 18
Source File: MetaTileEntityRotorHolder.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(isRotorLooping);
    buf.writeInt(rotorColor);
}
 
Example 19
Source File: MetaTileEntityTransformer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(isTransformUp);
}
 
Example 20
Source File: MetaTileEntityCokeOven.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeBoolean(isActive);
}