mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
convert more packets to kotlin, InByteBuffer::readOptional
This commit is contained in:
parent
814cdab159
commit
29c15ad38a
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data;
|
||||
|
||||
import de.bixilon.minosoft.data.inventory.ItemStack;
|
||||
import org.checkerframework.common.value.qual.IntRange;
|
||||
|
||||
public class Trade {
|
||||
private final ItemStack input1;
|
||||
private final ItemStack input2;
|
||||
private final boolean enabled;
|
||||
private final int usages;
|
||||
private final int maxUsages;
|
||||
private final int xp;
|
||||
private final int specialPrice;
|
||||
private final float priceMultiplier;
|
||||
private final int demand;
|
||||
|
||||
public Trade(ItemStack input1, ItemStack input2, boolean enabled, int usages, int maxUsages, int xp, int specialPrice, float priceMultiplier, int demand) {
|
||||
this.input1 = input1;
|
||||
this.input2 = input2;
|
||||
this.enabled = enabled;
|
||||
this.usages = usages;
|
||||
this.maxUsages = maxUsages;
|
||||
this.xp = xp;
|
||||
this.specialPrice = specialPrice;
|
||||
this.priceMultiplier = priceMultiplier;
|
||||
this.demand = demand;
|
||||
}
|
||||
|
||||
public ItemStack getInput1() {
|
||||
return this.input1;
|
||||
}
|
||||
|
||||
public ItemStack getInput2() {
|
||||
return this.input2;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@IntRange(from = 0)
|
||||
public int getUsages() {
|
||||
return this.usages;
|
||||
}
|
||||
|
||||
public int getMaxUsages() {
|
||||
return this.maxUsages;
|
||||
}
|
||||
|
||||
public int getXp() {
|
||||
return this.xp;
|
||||
}
|
||||
|
||||
public int getSpecialPrice() {
|
||||
return this.specialPrice;
|
||||
}
|
||||
|
||||
public float getPriceMultiplier() {
|
||||
return this.priceMultiplier;
|
||||
}
|
||||
|
||||
public int getDemand() {
|
||||
return this.demand;
|
||||
}
|
||||
}
|
27
src/main/java/de/bixilon/minosoft/data/Trade.kt
Normal file
27
src/main/java/de/bixilon/minosoft/data/Trade.kt
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.data
|
||||
|
||||
import de.bixilon.minosoft.data.inventory.ItemStack
|
||||
|
||||
class Trade(
|
||||
val input1: ItemStack?,
|
||||
val input2: ItemStack?,
|
||||
val isEnabled: Boolean,
|
||||
val usages: Int,
|
||||
val maxUsages: Int,
|
||||
val xp: Int,
|
||||
val specialPrice: Int,
|
||||
val priceMultiplier: Float,
|
||||
val demand: Int,
|
||||
)
|
@ -58,28 +58,10 @@ class EntityMetaData(
|
||||
EntityMetaDataDataTypes.ITEM_STACK -> buffer.readItemStack()
|
||||
EntityMetaDataDataTypes.ROTATION -> EntityRotation(buffer.readFloat(), buffer.readFloat(), buffer.readFloat())
|
||||
EntityMetaDataDataTypes.BLOCK_POSITION -> buffer.readBlockPosition()
|
||||
EntityMetaDataDataTypes.OPT_CHAT -> {
|
||||
if (buffer.readBoolean()) {
|
||||
buffer.readChatComponent()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
EntityMetaDataDataTypes.OPT_BLOCK_POSITION -> {
|
||||
if (buffer.readBoolean()) {
|
||||
buffer.readBlockPosition()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
EntityMetaDataDataTypes.OPT_CHAT -> buffer.readOptional { buffer.readChatComponent() }
|
||||
EntityMetaDataDataTypes.OPT_BLOCK_POSITION -> buffer.readOptional { buffer.readBlockPosition() }
|
||||
EntityMetaDataDataTypes.DIRECTION -> buffer.readDirection()
|
||||
EntityMetaDataDataTypes.OPT_UUID -> {
|
||||
if (buffer.readBoolean()) {
|
||||
buffer.readUUID()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
EntityMetaDataDataTypes.OPT_UUID -> buffer.readOptional { buffer.readUUID() }
|
||||
EntityMetaDataDataTypes.NBT -> buffer.readNBT()
|
||||
EntityMetaDataDataTypes.PARTICLE -> buffer.readParticle()
|
||||
EntityMetaDataDataTypes.POSE -> buffer.readPose()
|
||||
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class CraftingRecipeResponseS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val containerId = buffer.readUnsignedByte()
|
||||
var recipeId: Int? = null
|
||||
private set
|
||||
var recipeName: String? = null
|
||||
private set
|
||||
|
||||
init {
|
||||
if (buffer.versionId < ProtocolVersions.V_17W47A) { // ToDo: was this really in 346?
|
||||
recipeId = buffer.readVarInt()
|
||||
} else {
|
||||
recipeName = buffer.readString()
|
||||
}
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Crafting recipe response (containerId=$containerId, recipeId=$recipeId, recipeName=$recipeName)" }
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.effects.StatusEffect
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class EntityStatusEffectRemoveS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val entityId: Int = buffer.readEntityId()
|
||||
val effect: StatusEffect = buffer.connection.mapping.statusEffectRegistry.get(buffer.readUnsignedByte())
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
connection.world.entities[entityId]?.removeEffect(effect)
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Entity status effect remove (entityId=$entityId, effect=$effect)" }
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class HorseContainerOpenS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val containerId = buffer.readUnsignedByte()
|
||||
val slotCount: Int = buffer.readVarInt()
|
||||
val entityId: Int = buffer.readInt()
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Horse container open (containerId=$containerId, slotCount=$slotCount, entityId=$entityId" }
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_17W47A;
|
||||
|
||||
public class PacketCraftRecipeResponse extends PlayS2CPacket {
|
||||
private final byte windowId;
|
||||
private int recipeId;
|
||||
private String recipeName;
|
||||
|
||||
public PacketCraftRecipeResponse(PlayInByteBuffer buffer) {
|
||||
this.windowId = buffer.readByte();
|
||||
if (buffer.getVersionId() < V_17W47A) { // ToDo: was this really in 346?
|
||||
this.recipeId = buffer.readVarInt();
|
||||
} else {
|
||||
this.recipeName = buffer.readString();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Received Crafting recipe response (windowId=%d, recipeId=%d)", this.windowId, this.recipeId));
|
||||
}
|
||||
|
||||
public byte getWindowId() {
|
||||
return this.windowId;
|
||||
}
|
||||
|
||||
public int getRecipeId() {
|
||||
return this.recipeId;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
public class PacketOpenHorseWindow extends PlayS2CPacket {
|
||||
private final byte windowId;
|
||||
private final int slotCount;
|
||||
private final int entityId;
|
||||
|
||||
public PacketOpenHorseWindow(PlayInByteBuffer buffer) {
|
||||
this.windowId = buffer.readByte();
|
||||
this.slotCount = buffer.readVarInt();
|
||||
this.entityId = buffer.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Received open horse window packet (windowId=%d, slotCount=%d, entityId=%s)", this.windowId, this.slotCount, this.entityId));
|
||||
}
|
||||
|
||||
public byte getWindowId() {
|
||||
return this.windowId;
|
||||
}
|
||||
|
||||
public int getSlotCount() {
|
||||
return this.slotCount;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity;
|
||||
import de.bixilon.minosoft.data.mappings.effects.StatusEffect;
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection;
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
public class PacketRemoveEntityStatusEffect extends PlayS2CPacket {
|
||||
private final int entityId;
|
||||
private final StatusEffect effect;
|
||||
|
||||
public PacketRemoveEntityStatusEffect(PlayInByteBuffer buffer) {
|
||||
this.entityId = buffer.readEntityId();
|
||||
|
||||
this.effect = buffer.getConnection().getMapping().getStatusEffectRegistry().get(buffer.readByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayConnection connection) {
|
||||
Entity entity = connection.getWorld().getEntities().get(getEntityId());
|
||||
if (entity == null) {
|
||||
// thanks mojang
|
||||
return;
|
||||
}
|
||||
entity.removeEffect(getEffect());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Entity effect removed (entityId=%d, effect=%s)", this.entityId, this.effect));
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
public StatusEffect getEffect() {
|
||||
return this.effect;
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play;
|
||||
|
||||
import de.bixilon.minosoft.data.Trade;
|
||||
import de.bixilon.minosoft.data.entities.entities.npc.villager.data.VillagerLevels;
|
||||
import de.bixilon.minosoft.data.inventory.ItemStack;
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_14_3_PRE1;
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_14_4_PRE5;
|
||||
|
||||
public class PacketTradeList extends PlayS2CPacket {
|
||||
int windowId;
|
||||
Trade[] trades;
|
||||
VillagerLevels level;
|
||||
int experience;
|
||||
boolean isRegularVillager;
|
||||
boolean canRestock;
|
||||
|
||||
public PacketTradeList(PlayInByteBuffer buffer) {
|
||||
this.windowId = buffer.readVarInt();
|
||||
this.trades = new Trade[buffer.readByte()];
|
||||
for (int i = 0; i < this.trades.length; i++) {
|
||||
ItemStack input1 = buffer.readItemStack();
|
||||
ItemStack input2 = null;
|
||||
if (buffer.readBoolean()) {
|
||||
// second input available
|
||||
input2 = buffer.readItemStack();
|
||||
}
|
||||
boolean enabled = !buffer.readBoolean();
|
||||
int usages = buffer.readInt();
|
||||
int maxUsages = buffer.readInt();
|
||||
int xp = buffer.readInt();
|
||||
int specialPrice = buffer.readInt();
|
||||
float priceMultiplier = buffer.readFloat();
|
||||
int demand = 0;
|
||||
if (buffer.getVersionId() >= V_1_14_4_PRE5) {
|
||||
demand = buffer.readInt();
|
||||
}
|
||||
this.trades[i] = new Trade(input1, input2, enabled, usages, maxUsages, xp, specialPrice, priceMultiplier, demand);
|
||||
}
|
||||
this.level = VillagerLevels.Companion.getVALUES()[buffer.readVarInt()];
|
||||
this.experience = buffer.readVarInt();
|
||||
this.isRegularVillager = buffer.readBoolean();
|
||||
if (buffer.getVersionId() >= V_1_14_3_PRE1) {
|
||||
this.canRestock = buffer.readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Received select trade packet (windowId=%d, tradeLength=%d, level=%s, experience=%d, regularVillager=%s, canRestock=%s)", this.windowId, this.trades.length, this.level, this.experience, this.isRegularVillager, this.canRestock));
|
||||
}
|
||||
|
||||
public int getWindowId() {
|
||||
return this.windowId;
|
||||
}
|
||||
|
||||
public Trade[] getTrades() {
|
||||
return this.trades;
|
||||
}
|
||||
|
||||
public VillagerLevels getLevel() {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
public int getExperience() {
|
||||
return this.experience;
|
||||
}
|
||||
|
||||
public boolean isRegularVillager() {
|
||||
return this.isRegularVillager;
|
||||
}
|
||||
|
||||
public boolean canRestock() {
|
||||
return this.canRestock;
|
||||
}
|
||||
}
|
@ -38,9 +38,7 @@ class ResourcepackRequestS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
|
||||
init {
|
||||
if (buffer.versionId >= ProtocolVersions.V_21W15A) {
|
||||
if (buffer.readBoolean()) {
|
||||
promptText = buffer.readChatComponent()
|
||||
}
|
||||
promptText = buffer.readOptional { buffer.readChatComponent() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,7 @@ class TabListDataS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val property = PlayerProperty(
|
||||
PlayerProperties.byName(buffer.readString()),
|
||||
buffer.readString(),
|
||||
if (buffer.readBoolean()) {
|
||||
buffer.readString()
|
||||
} else {
|
||||
null
|
||||
},
|
||||
buffer.readOptional { buffer.readString() },
|
||||
)
|
||||
playerProperties[property.property] = property
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.data.Trade
|
||||
import de.bixilon.minosoft.data.entities.entities.npc.villager.data.VillagerLevels
|
||||
import de.bixilon.minosoft.data.inventory.ItemStack
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
|
||||
class VillagerTradesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val containerId: Int = buffer.readVarInt()
|
||||
val trades: List<Trade> = buffer.readArray(buffer.readUnsignedByte()) {
|
||||
val input1 = buffer.readItemStack()
|
||||
val input2: ItemStack? = buffer.readOptional { buffer.readItemStack() }
|
||||
val enabled = !buffer.readBoolean()
|
||||
val usages = buffer.readInt()
|
||||
val maxUsages = buffer.readInt()
|
||||
val xp = buffer.readInt()
|
||||
val specialPrice = buffer.readInt()
|
||||
val priceMultiplier = buffer.readFloat()
|
||||
var demand = 0
|
||||
if (buffer.versionId >= ProtocolVersions.V_1_14_4_PRE5) {
|
||||
demand = buffer.readInt()
|
||||
}
|
||||
|
||||
Trade(input1, input2, enabled, usages, maxUsages, xp, specialPrice, priceMultiplier, demand)
|
||||
}.toList()
|
||||
val level = VillagerLevels[buffer.readVarInt()]
|
||||
val experience = buffer.readVarInt()
|
||||
val regularVillager = buffer.readBoolean()
|
||||
var canRestock = false
|
||||
private set
|
||||
|
||||
init {
|
||||
if (buffer.versionId >= ProtocolVersions.V_1_14_3_PRE1) {
|
||||
canRestock = buffer.readBoolean()
|
||||
}
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, LogLevels.VERBOSE) { "Villager trades (containerId=$containerId, trades=$trades, level=$level, experience=$experience, regularVillager=$regularVillager, canRestock=$canRestock)" }
|
||||
}
|
||||
}
|
@ -416,4 +416,12 @@ open class InByteBuffer {
|
||||
fun readTagArray(length: Int = readVarInt()): Array<Tag> {
|
||||
return readArray(length) { readTag() }
|
||||
}
|
||||
|
||||
fun <T> readOptional(reader: () -> T): T? {
|
||||
return if (readBoolean()) {
|
||||
reader()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ class PacketTypes {
|
||||
PLAY_EXPLOSION({ ExplosionS2CP(it) }),
|
||||
PLAY_CHUNK_UNLOAD({ ChunkUnloadS2CP(it) }),
|
||||
PLAY_GAME_EVENT({ GameEventS2CP(it) }),
|
||||
PLAY_OPEN_HORSE_WINDOW({ PacketOpenHorseWindow(it) }),
|
||||
PLAY_HORSE_CONTAINER_OPEN({ HorseContainerOpenS2CP(it) }),
|
||||
PLAY_HEARTBEAT({ HeartbeatS2CP(it) }),
|
||||
PLAY_CHUNK_DATA({ ChunkDataS2CP(it) }),
|
||||
PLAY_WORLD_EVENT({ WorldEventS2CP(it) }),
|
||||
@ -196,7 +196,7 @@ class PacketTypes {
|
||||
PLAY_CHUNK_LIGHT_DATA({ ChunkLightDataS2CP(it) }),
|
||||
PLAY_JOIN_GAME({ JoinGameS2CP(it) }, isThreadSafe = false, errorHandler = JoinGameS2CP),
|
||||
PLAY_MAP_DATA({ PacketMapData(it) }),
|
||||
PLAY_TRADE_LIST({ PacketTradeList(it) }),
|
||||
PLAY_VILLAGER_TRADES({ VillagerTradesS2CP(it) }),
|
||||
PLAY_ENTITY_MOVE_AND_ROTATE({ EntityMoveAndRotateS2CP(it) }),
|
||||
PLAY_ENTITY_ROTATION({ EntityRotationS2CP(it) }),
|
||||
PLAY_ENTITY_RELATIVE_MOVE({ EntityRelativeMoveS2CP(it) }),
|
||||
@ -204,7 +204,7 @@ class PacketTypes {
|
||||
PLAY_BOOK_OPEN({ BookOpenS2CP(it) }),
|
||||
PLAY_CONTAINER_OPEN({ ContainerOpenS2CP(it) }),
|
||||
PLAY_SIGN_EDITOR_OPEN({ SignEditorOpenS2CP(it) }),
|
||||
PLAY_CRAFT_RECIPE_RESPONSE({ PacketCraftRecipeResponse(it) }),
|
||||
PLAY_CRAFTING_RECIPE_RESPONSE({ CraftingRecipeResponseS2CP(it) }),
|
||||
PLAY_PLAYER_ABILITIES({ PlayerAbilitiesS2CP(it) }),
|
||||
PLAY_COMBAT_EVENT({ CombatEventS2CF.createPacket(it) }),
|
||||
PLAY_COMBAT_EVENT_END({ CombatEventEndS2CP(it) }),
|
||||
@ -215,7 +215,7 @@ class PacketTypes {
|
||||
PLAY_POSITION_AND_ROTATION({ PositionAndRotationS2CP(it) }),
|
||||
PLAY_UNLOCK_RECIPES({ PacketUnlockRecipes(it) }),
|
||||
PLAY_ENTITY_DESTROY({ EntityDestroyS2CP(it) }),
|
||||
PLAY_REMOVE_ENTITY_EFFECT({ PacketRemoveEntityStatusEffect(it) }),
|
||||
PLAY_ENTITY_STATUS_EFFECT_REMOVE({ EntityStatusEffectRemoveS2CP(it) }),
|
||||
PLAY_RESOURCEPACK_REQUEST({ ResourcepackRequestS2CP(it) }),
|
||||
PLAY_RESPAWN({ RespawnS2CP(it) }, isThreadSafe = false),
|
||||
PLAY_ENTITY_HEAD_ROTATION({ EntityHeadRotationS2CP(it) }),
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user