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

The following examples show how to use net.minecraft.network.PacketBuffer#readInt() . 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: MessageBackpackUpdate.java    From WearableBackpacks with MIT License 6 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	try {
		_entityId = buffer.readInt();
		_type = UpdateType.fromByte(buffer.readByte());
		switch (_type) {
			case STACK: _stack = buffer.readItemStack(); break;
			case OPEN: _open = buffer.readBoolean(); break;
			default: throw new RuntimeException("Invalid UpdateType");
		}
	} catch (Exception ex) {
		_entityId = -1;
		_type = UpdateType.INVALID;
		_stack = ItemStack.EMPTY;
		_open = false;
	}
}
 
Example 2
Source File: PacketAsteroidInfo.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	
	asteroid.ID = packetBuffer.readString(128);
	asteroid.distance = packetBuffer.readInt();
	asteroid.mass = packetBuffer.readInt();
	asteroid.minLevel = packetBuffer.readInt();
	asteroid.massVariability = packetBuffer.readFloat();
	asteroid.richness = packetBuffer.readFloat();					//factor of the ratio of ore to stone
	asteroid.richnessVariability = packetBuffer.readFloat();		//variability of richness
	asteroid.probability = packetBuffer.readFloat();				//probability of the asteroid spawning
	asteroid.timeMultiplier = packetBuffer.readFloat();
	
	int size = packetBuffer.readInt();
	for(int i = 0; i < size; i++)
	{
		try {
			asteroid.itemStacks.add(packetBuffer.readItemStack());
			asteroid.stackProbabilites.add(packetBuffer.readFloat());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
Example 3
Source File: MessageStartPiloting.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer packetBuf = new PacketBuffer(buf);
    posToStartPiloting = new BlockPos(
        packetBuf.readInt(),
        packetBuf.readInt(),
        packetBuf.readInt()
    );
    setPhysicsWrapperEntityToPilot = packetBuf.readBoolean();
    controlType = packetBuf.readEnumValue(ControllerInputType.class);
}
 
Example 4
Source File: TileEntityRpcTarget.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) {
	int worldId = input.readInt();
	BlockPos pos = input.readBlockPos();

	World world = WorldUtils.getWorld(side, worldId);
	te = world.getTileEntity(pos);
}
 
Example 5
Source File: EntityRpcTarget.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) {
	int worldId = input.readInt();
	int entityId = input.readInt();

	World world = WorldUtils.getWorld(side, worldId);
	entity = world.getEntityByID(entityId);
}
 
Example 6
Source File: MessageOpenGui.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	try {
		_windowId = buffer.readInt();
		_data = buffer.readCompoundTag();
	} catch (Exception ex) {
		_windowId = -1;
		_data = null;
	}
}
 
Example 7
Source File: EntityMountable.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void readSpawnData(ByteBuf additionalData) {
    PacketBuffer packetBuffer = new PacketBuffer(additionalData);
    mountPos = new Vec3d(packetBuffer.readDouble(), packetBuffer.readDouble(),
        packetBuffer.readDouble());
    mountPosSpace = CoordinateSpaceType.values()[packetBuffer.readInt()];
    if (packetBuffer.readBoolean()) {
        referencePos = packetBuffer.readBlockPos();
    } else {
        referencePos = null;
    }
}
 
Example 8
Source File: MessagePlayerStoppedPiloting.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer packetBuf = new PacketBuffer(buf);
    posToStopPiloting = new BlockPos(
        packetBuf.readInt(),
        packetBuf.readInt(),
        packetBuf.readInt()
    );
}
 
Example 9
Source File: SyncableTank.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) throws IOException {
	if (stream.readBoolean()) {
		String fluidName = stream.readString(Short.MAX_VALUE);
		Fluid fluid = FluidRegistry.getFluid(fluidName);

		int fluidAmount = stream.readInt();

		this.fluid = new FluidStack(fluid, fluidAmount);
		this.fluid.tag = stream.readCompoundTag();
	} else {
		this.fluid = null;
	}
}
 
Example 10
Source File: HDataSerializers.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Area read(PacketBuffer buf) throws IOException {
	Area temparea = new Area();
	int[] array = new int[6];
	int i = 0;
	while (i < array.length) {
		array[i] = buf.readInt();
		++i;
	}
	temparea.deserialize(array);
	return temparea;
}
 
Example 11
Source File: MetaTileEntityRotorHolder.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveCustomData(int dataId, PacketBuffer buf) {
    super.receiveCustomData(dataId, buf);
    if (dataId == 200) {
        this.isRotorLooping = buf.readBoolean();
        getHolder().scheduleChunkForRenderUpdate();
    } else if (dataId == 201) {
        this.rotorColor = buf.readInt();
        getHolder().scheduleChunkForRenderUpdate();
    }
}
 
Example 12
Source File: SyncMapEntity.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static ISyncMapProvider findOwner(World world, PacketBuffer input) {
	int entityId = input.readInt();
	Entity entity = world.getEntityByID(entityId);
	if (entity instanceof ISyncMapProvider)
		return (ISyncMapProvider)entity;

	Log.warn("Invalid handler info: can't find ISyncHandler entity id %d", entityId);
	return null;
}
 
Example 13
Source File: TileEntityPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void receiveInitialSyncData(PacketBuffer buf) {
    readPipeProperties(buf);
    this.blockedConnections = buf.readVarInt();
    this.insulationColor = buf.readInt();
    this.coverableImplementation.readInitialSyncData(buf);
}
 
Example 14
Source File: MetaTileEntityRotorHolder.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void receiveInitialSyncData(PacketBuffer buf) {
    super.receiveInitialSyncData(buf);
    this.isRotorLooping = buf.readBoolean();
    this.rotorColor = buf.readInt();
}
 
Example 15
Source File: SyncableFlags.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readInt();
}
 
Example 16
Source File: PacketSpaceStationInfo.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	stationNumber = in.readInt();

	//Is dimension being deleted
	if(in.readBoolean()) {
		if(DimensionManager.getInstance().isDimensionCreated(stationNumber)) {
			DimensionManager.getInstance().deleteDimension(stationNumber);
		}
	}
	else {
		//TODO: error handling
		int direction;
		String clazzId;
		int fuelAmt;
		try {
			clazzId = packetBuffer.readString(127);
			nbt = packetBuffer.readCompoundTag();
			fuelAmt = packetBuffer.readInt();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		
		boolean hasWarpCores = in.readBoolean();
		
		direction = in.readInt();
		
		
		ISpaceObject iObject = SpaceObjectManager.getSpaceManager().getSpaceStation(stationNumber);
		
		
		
		//TODO: interface
		spaceObject = (SpaceObject)iObject;
		
		//Station needs to be created
		if( iObject == null ) {
			ISpaceObject object = SpaceObjectManager.getSpaceManager().getNewSpaceObjectFromIdentifier(clazzId);
			object.readFromNbt(nbt);
			object.setProperties(DimensionProperties.createFromNBT(stationNumber, nbt));
			((SpaceObject)object).setForwardDirection(EnumFacing.values()[direction]);
			
			SpaceObjectManager.getSpaceManager().registerSpaceObjectClient(object, object.getOrbitingPlanetId(), stationNumber);
			((SpaceObject)object).setFuelAmount(fuelAmt);
			((SpaceObject)object).hasWarpCores = hasWarpCores;
		}
		else {
			iObject.readFromNbt(nbt);
			//iObject.setProperties(DimensionProperties.createFromNBT(stationNumber, nbt));
			((SpaceObject)iObject).setForwardDirection(EnumFacing.values()[direction]);
			((SpaceObject)iObject).setFuelAmount(fuelAmt);
			((SpaceObject)iObject).hasWarpCores = hasWarpCores;
		}
	}
}
 
Example 17
Source File: PacketChangeRange.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static PacketChangeRange decode(PacketBuffer buffer) {
    return new PacketChangeRange(buffer.readInt());
}
 
Example 18
Source File: PacketExtractUpgrade.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static PacketExtractUpgrade decode(PacketBuffer buffer) {
    int strLength = buffer.readInt();
    return new PacketExtractUpgrade(buffer.readBlockPos(), buffer.readString(strLength), strLength);
}
 
Example 19
Source File: BlockEventPacket.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
protected void readFromStream(PacketBuffer input) {
	dimension = input.readInt();
	blockPos = input.readBlockPos();
}
 
Example 20
Source File: StructuredTest.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer input) {
	this.value = input.readInt();
}