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

The following examples show how to use net.minecraft.network.PacketBuffer#readString() . 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: 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 2
Source File: GameProfileSerializer.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static GameProfile read(PacketBuffer input) {
	final String uuidStr = input.readString(Short.MAX_VALUE);
	UUID uuid = Strings.isNullOrEmpty(uuidStr)? null : UUID.fromString(uuidStr);
	final String name = input.readString(Short.MAX_VALUE);
	GameProfile result = new GameProfile(uuid, name);
	int propertyCount = input.readVarInt();

	final PropertyMap properties = result.getProperties();
	for (int i = 0; i < propertyCount; ++i) {
		String key = input.readString(Short.MAX_VALUE);
		String value = input.readString(Short.MAX_VALUE);
		if (input.readBoolean()) {
			String signature = input.readString(Short.MAX_VALUE);
			properties.put(key, new Property(key, value, signature));
		} else {
			properties.put(key, new Property(key, value));
		}

	}

	return result;
}
 
Example 3
Source File: SimpleTextWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 1) {
        this.lastText = buffer.readString(Short.MAX_VALUE);
        updateSize();
    }
}
 
Example 4
Source File: TextFieldWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    super.readUpdateInfo(id, buffer);
    if (id == 1) {
        this.currentString = buffer.readString(Short.MAX_VALUE);
        this.textField.setText(currentString);
    }
}
 
Example 5
Source File: TextFieldWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    super.handleClientAction(id, buffer);
    if (id == 1) {
        String clientText = buffer.readString(Short.MAX_VALUE);
        clientText = clientText.substring(0, Math.min(clientText.length(), maxStringLength));
        if (textValidator.test(clientText)) {
            this.currentString = clientText;
            this.textResponder.accept(clientText);
        }
    }
}
 
Example 6
Source File: AdvancedTextWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 1) {
        this.displayText.clear();
        int count = buffer.readVarInt();
        for (int i = 0; i < count; i++) {
            String jsonText = buffer.readString(32767);
            this.displayText.add(ITextComponent.Serializer.jsonToComponent(jsonText));
        }
        formatDisplayText();
        updateComponentTextSize();
    }
}
 
Example 7
Source File: AdvancedTextWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    super.handleClientAction(id, buffer);
    if (id == 1) {
        ClickData clickData = ClickData.readFromBuf(buffer);
        String componentData = buffer.readString(128);
        if (clickHandler != null) {
            clickHandler.accept(componentData, clickData);
        }
    }
}
 
Example 8
Source File: CreateRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Nullable
@Override
public CreateRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    String s = buffer.readString(32767);
    NonNullList<Ingredient> ingredients = NonNullList.withSize(3 * 3, Ingredient.EMPTY);

    for (int k = 0; k < ingredients.size(); ++k) {
        ingredients.set(k, Ingredient.read(buffer));
    }

    ItemStack result = buffer.readItemStack();
    return new CreateRecipe(recipeId, s, result, ingredients);
}
 
Example 9
Source File: ReColourRecipe.java    From EnderStorage with MIT License 5 votes vote down vote up
@Nullable
@Override
public ReColourRecipe read(ResourceLocation recipeId, PacketBuffer buffer) {
    String s = buffer.readString(32767);
    Ingredient ing = Ingredient.read(buffer);
    ItemStack result = buffer.readItemStack();
    return new ReColourRecipe(recipeId, s, result, ing);
}
 
Example 10
Source File: ChoppingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public ChoppingRecipe read(ResourceLocation recipeId, PacketBuffer buffer)
{

    String group = buffer.readString(32767);
    Ingredient ingredient = Ingredient.read(buffer);
    ItemStack itemstack = buffer.readItemStack();
    double outputMultiplier = buffer.readDouble();
    double hitCountMultiplier = buffer.readDouble();
    int maxOutput = buffer.readVarInt();
    int sawingTime = buffer.readVarInt();
    return new ChoppingRecipe(recipeId, group, ingredient, itemstack, outputMultiplier, hitCountMultiplier, maxOutput, sawingTime);
}
 
Example 11
Source File: DryingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public DryingRecipe read(ResourceLocation recipeId, PacketBuffer buffer)
{
    String group = buffer.readString(32767);
    Ingredient ingredient = Ingredient.read(buffer);
    ItemStack itemstack = buffer.readItemStack();
    int dryingTime = buffer.readVarInt();
    return new DryingRecipe(recipeId, group, ingredient, itemstack, dryingTime);
}
 
Example 12
Source File: PacketDimInfo.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readClient(ByteBuf in) {
	PacketBuffer packetBuffer = new PacketBuffer(in);
	NBTTagCompound nbt;
	dimNumber = in.readInt();
	

	deleteDim = in.readBoolean();
	
	if(!deleteDim) {
		//TODO: error handling
		try {
			dimNBT = nbt = packetBuffer.readCompoundTag();

			int number = packetBuffer.readShort();
			for(int i = 0; i < number; i++) {
				NBTTagCompound nbt2 = packetBuffer.readCompoundTag();
				artifacts.add(new ItemStack(nbt2));
			}
			
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		dimProperties = new DimensionProperties(dimNumber);
		dimProperties.readFromNBT(nbt);
		
		short strLen = packetBuffer.readShort();
		if(strLen > 0)
		{
			dimProperties.customIcon = packetBuffer.readString(strLen);
		}
	}
}
 
Example 13
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 14
Source File: StructuredTest.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer input) {
	this.value = input.readString(Short.MAX_VALUE);
}
 
Example 15
Source File: SyncableString.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void readFromStream(PacketBuffer stream) {
	value = stream.readString(Short.MAX_VALUE);
}
 
Example 16
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public String readFromStream(PacketBuffer input) {
	return input.readString(Short.MAX_VALUE);
}
 
Example 17
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 18
Source File: PacketUpdateUpgrade.java    From MiningGadgets with MIT License 4 votes vote down vote up
public static PacketUpdateUpgrade decode(PacketBuffer buffer) {
    return new PacketUpdateUpgrade(buffer.readString(100));
}
 
Example 19
Source File: PlayerParticleData.java    From MiningGadgets with MIT License 4 votes vote down vote up
@Override
public PlayerParticleData read(@Nonnull ParticleType<PlayerParticleData> type, PacketBuffer buf) {
    return new PlayerParticleData(buf.readString(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readFloat(), buf.readFloat(), buf.readFloat(), buf.readFloat(), buf.readFloat(), buf.readBoolean());
}
 
Example 20
Source File: SyncMapClient.java    From OpenModsLib with MIT License 3 votes vote down vote up
@Override
public void readIntializationData(PacketBuffer dis) throws IOException {
	final int count = dis.readVarInt();

	final ImmutableList.Builder<ISyncableObject> idToObject = ImmutableList.builder();

	final ImmutableMap.Builder<ISyncableObject, Integer> objectToId = ImmutableMap.builder();

	final Set<ISyncableObject> changedObjects = Sets.newIdentityHashSet();

	for (int i = 0; i < count; i++) {
		final String id = dis.readString(Short.MAX_VALUE);
		final int typeId = dis.readVarInt();

		final SyncableObjectType type = SyncableObjectTypeRegistry.getType(typeId);

		ISyncableObject object = availableObjects.get(id);
		if (object == null || !type.isValidType(object))
			object = type.createDummyObject();

		object.readFromStream(dis);

		idToObject.add(object);
		objectToId.put(object, i);

		changedObjects.add(object);
	}

	this.idToObject = idToObject.build();
	this.objectToId = objectToId.build();
	this.bitmapLength = (count + 7) / 8;

	notifySyncListeners(updateListeners, Collections.unmodifiableSet(changedObjects));
}