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

The following examples show how to use net.minecraft.network.PacketBuffer#writeInt() . 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: ComponentExplosive.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public boolean itemInteractionForEntity(ItemStack itemStack, EntityPlayer player, EntityLivingBase entityLiving) {
	if(player.worldObj.isRemote) {
		PacketBuffer out =  new PacketBuffer(Unpooled.buffer());
		
		//System.out.println("Building packet...");
		out.writeInt(PacketHandlerServer.EXPLOSIONS);
		out.writeInt(player.getEntityId());
		out.writeInt(player.inventory.currentItem);
		//out.writeFloat(par3EntityPlayer.getHealth()+1);
		CToSMessage packet = new CToSMessage(out);
		//System.out.println("Sending packet..." + player);
		DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
		//par1ItemStack.damageItem(1, par2EntityPlayer);
		
		return true;

	}
	return false;
}
 
Example 2
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 3
Source File: ComponentObscurity.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
	public boolean hitEntity(ItemStack itemStack, EntityLivingBase entityVictim, EntityLivingBase entityAttacker) {
		EntityPlayerMP player = UtilsForComponents.getPlayerFromUsername(entityAttacker.getCommandSenderName());
		
		if(player != null) {
			player.addPotionEffect(new PotionEffect(14, 600, 0));
			
			PacketBuffer out = new PacketBuffer(Unpooled.buffer());
			
			out.writeInt(PacketHandlerClient.OBSCURITY);
			SToCMessage packet = new SToCMessage(out);
			DragonArtifacts.artifactNetworkWrapper.sendTo(packet, player);
			
			//System.out.println("Cloaking player.");
			itemStack.damageItem(1, player);
//			UtilsForComponents.sendItemDamagePacket(entityAttacker, entityAttacker.inventory.currentItem, 1); //itemStack.damageItem(1, player);
//			itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 200);
		}
		return false;
	}
 
Example 4
Source File: MessageStopPiloting.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(posToStopPiloting.getX());
    packetBuf.writeInt(posToStopPiloting.getY());
    packetBuf.writeInt(posToStopPiloting.getZ());
    //use absolute coordinates instead of writeBlockPos in case we ever add compatibility with cubic chunks
}
 
Example 5
Source File: ComponentLightning.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
	PacketBuffer out = new PacketBuffer(Unpooled.buffer());
	//System.out.println("Building packet...");
	out.writeInt(PacketHandlerServer.LIGHTNING);
	out.writeInt(player.getEntityId());
	out.writeInt(player.inventory.currentItem);
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	UtilsForComponents.sendItemDamagePacket(player, player.inventory.currentItem, 1);
	itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 5);
	
	return itemStack;
}
 
Example 6
Source File: UtilsForComponents.java    From Artifacts with MIT License 5 votes vote down vote up
public static void sendItemDamagePacket(EntityPlayer player, int inventorySlot, int damageToDeal) {
	if(player.worldObj.isRemote) {
		PacketBuffer out =  new PacketBuffer(Unpooled.buffer());
	
		out.writeInt(PacketHandlerServer.DAMAGE_ITEM);
		out.writeInt(player.getEntityId());
		out.writeInt(inventorySlot);
		out.writeInt(damageToDeal);
		CToSMessage packet = new CToSMessage(out);
		DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	}
}
 
Example 7
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 8
Source File: ComponentHeal.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
	PacketBuffer out = new PacketBuffer(Unpooled.buffer());
		//System.out.println("Building packet...");
	out.writeInt(PacketHandlerServer.HEALING);
	out.writeFloat(1);
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	UtilsForComponents.sendItemDamagePacket(player, player.inventory.currentItem, 1);
	itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 20);

	return itemStack;
}
 
Example 9
Source File: ComponentFireball.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,	EntityPlayer player) {
	PacketBuffer out =  new PacketBuffer(Unpooled.buffer());
	out.writeInt(PacketHandlerServer.FIREBALLS);
	out.writeInt(player.getEntityId());
	out.writeInt(player.inventory.currentItem);
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	UtilsForComponents.sendItemDamagePacket(player, player.inventory.currentItem, 1);
	itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 20);
	
	return itemStack;
}
 
Example 10
Source File: ItemArtifact.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
   {
	NBTTagCompound data = itemStack.getTagCompound();
	int effectID = 0;
	if(data != null && world.isRemote) {
		effectID = data.getInteger("onItemRightClick");
		if(effectID != 0) {
			//System.out.println("Activating...");
			int d = data.getInteger("onItemRightClickDelay");
			//System.out.println("R-click: " + d);
			if(d <= 0) {
				IArtifactComponent c = ArtifactsAPI.artifacts.getComponent(effectID);
				if(c != null)
					itemStack = c.onItemRightClick(itemStack, world, player);
				d = itemStack.stackTagCompound.getInteger("onItemRightClickDelay");
				
				PacketBuffer out = new PacketBuffer(Unpooled.buffer());
				out.writeInt(4096);
				out.writeInt(d);
				out.writeInt(player.inventory.currentItem);
				CToSMessage packet = new CToSMessage(out);
				DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
			}
		}
	}
       return itemStack;
   }
 
Example 11
Source File: TileEntityPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    writePipeProperties(buf);
    buf.writeVarInt(blockedConnections);
    buf.writeInt(insulationColor);
    this.coverableImplementation.writeInitialSyncData(buf);
}
 
Example 12
Source File: ComponentBaking.java    From Artifacts with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world,	EntityPlayer player) {
	PacketBuffer out = new PacketBuffer(Unpooled.buffer());
	out.writeInt(PacketHandlerServer.BAKING);
	out.writeInt(player.inventory.currentItem);
	CToSMessage packet = new CToSMessage(out);
	DragonArtifacts.artifactNetworkWrapper.sendToServer(packet);
	itemStack.stackTagCompound.setInteger("onItemRightClickDelay", 20);
	return itemStack;
}
 
Example 13
Source File: HDataSerializers.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void write(PacketBuffer buf, Area value) {
	for (int i : value.serialize()) {
		buf.writeInt(i);
	}
}
 
Example 14
Source File: MixinNetHandlerPlayClient.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Inject(method = "handleCustomPayload", at = @At("RETURN"))
private void handleCustomPayload(S3FPacketCustomPayload packetIn, CallbackInfo ci) {
    PacketBuffer packetBuffer = packetIn.getBufferData();
    try {
        int readableBytes = packetBuffer.readableBytes();

        if (readableBytes > 0) {
            byte[] payload = new byte[readableBytes - 1];
            packetBuffer.readBytes(payload);
            String message = new String(payload, Charsets.UTF_8);

            if (LoginReplyHandler.SHOW_MESSAGES) {
                GeneralChatHandler.instance().sendMessage("Packet message on channel " + packetIn.getChannelName() + " -> " + message);
            }

            if ("REGISTER".equalsIgnoreCase(packetIn.getChannelName())) {
                if (message.contains("Hyperium")) {
                    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
                    buffer.writeString("Hyperium;" + Metadata.getVersion() + ";" + Metadata.getVersionID());
                    addToSendQueue(new C17PacketCustomPayload("REGISTER", buffer));
                    PacketBuffer addonbuffer = new PacketBuffer(Unpooled.buffer());
                    List<AddonManifest> addons = AddonBootstrap.INSTANCE.getAddonManifests();
                    addonbuffer.writeInt(addons.size());

                    for (AddonManifest addonmanifest : addons) {
                        String addonName = addonmanifest.getName();
                        String version = addonmanifest.getVersion();

                        if (addonName == null) addonName = addonmanifest.getMainClass();
                        if (version == null) version = "unknown";

                        addonbuffer.writeString(addonName);
                        addonbuffer.writeString(version);
                    }

                    addToSendQueue(new C17PacketCustomPayload("hyperium|Addons", addonbuffer));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 15
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 16
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(Integer o, PacketBuffer output) {
	output.writeInt(o);
}
 
Example 17
Source File: TileEntityDisplayPedestal.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	boolean sendNamePacket = false;
	
	if(entityplayer.worldObj.isRemote) {
		return false;
	}
	
	if( (ownerName == null || ownerName.equals("")) && (ownerUUID == null || ownerUUID.equals(new UUID(0, 0))) ) {
		ownerName = entityplayer.getCommandSenderName();
		ownerUUID = entityplayer.getUniqueID();
		this.markDirty();
		sendNamePacket = true;
	}
	
	if(ownerName.equals(entityplayer.getCommandSenderName()) && (ownerName == null || !ownerUUID.equals(entityplayer.getUniqueID()))) {
		ownerUUID = entityplayer.getUniqueID();
		this.markDirty();
	}
	
	if((ownerName == null || !ownerName.equals(entityplayer.getCommandSenderName())) && ownerUUID.equals(entityplayer.getUniqueID())) {
		ownerName = entityplayer.getCommandSenderName();
		this.markDirty();
		sendNamePacket = true;
	}
	
	if(sendNamePacket) {
		PacketBuffer out = new PacketBuffer(Unpooled.buffer());
		out.writeInt(PacketHandlerClient.PEDESTAL);
		out.writeInt(xCoord);
		out.writeInt(yCoord);
		out.writeInt(zCoord);
		out.writeInt(ownerName.length());
		for(int i = 0; i < ownerName.length(); i++) {
			out.writeChar(ownerName.charAt(i));
		}
		SToCMessage namePacket = new SToCMessage(out);
		DragonArtifacts.artifactNetworkWrapper.sendToAll(namePacket);
	}
	
	if(!(ownerName.equals(entityplayer.getCommandSenderName()) && ownerUUID.equals(entityplayer.getUniqueID()))) {
		return false;
	}
	
	return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this && entityplayer.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}
 
Example 18
Source File: SyncableFlags.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeInt(value);
}
 
Example 19
Source File: PacketChangeFreezeDelay.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static void encode(PacketChangeFreezeDelay msg, PacketBuffer buffer) {
    buffer.writeInt(msg.freezeDelay);
}
 
Example 20
Source File: StructuredTest.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer output) {
	output.writeInt(value);
}