3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-08 17:20:20 +01:00

Merge branch 'master' of https://github.com/GeyserMC/Geyser into server-inventory

Dieser Commit ist enthalten in:
DoctorMacc 2020-12-09 11:57:46 -05:00
Commit f167ed2583
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6D6E7E059F186DB4
10 geänderte Dateien mit 47 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -32,15 +32,26 @@
<dependency> <dependency>
<groupId>com.nukkitx.protocol</groupId> <groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v422</artifactId> <artifactId>bedrock-v422</artifactId>
<version>2.6.0-SNAPSHOT</version> <version>2.6.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>net.sf.trove4j</groupId> <groupId>net.sf.trove4j</groupId>
<artifactId>trove</artifactId> <artifactId>trove</artifactId>
</exclusion> </exclusion>
<!-- Stay on the older version of Network while it's rewritten -->
<exclusion>
<groupId>com.nukkitx.network</groupId>
<artifactId>raknet</artifactId>
</exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.nukkitx.network</groupId>
<artifactId>raknet</artifactId>
<version>1.6.20</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.nukkitx.fastutil</groupId> <groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-int-int-maps</artifactId> <artifactId>fastutil-int-int-maps</artifactId>

Datei anzeigen

@ -48,9 +48,8 @@ public class BedrockProtocol {
static { static {
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v419.V419_CODEC.toBuilder() SUPPORTED_BEDROCK_CODECS.add(Bedrock_v419.V419_CODEC.toBuilder()
.minecraftVersion("1.16.100/1.16.101") // We change this as 1.16.100.60 (beta) crashes with Geyser .minecraftVersion("1.16.100/1.16.101") // We change this as 1.16.100.60 is a beta
.build() .build());
);
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC); SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
} }

Datei anzeigen

@ -69,11 +69,10 @@ import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.common.AuthType; import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.player.SkullPlayerEntity;
import org.geysermc.connector.entity.player.SessionPlayerEntity; import org.geysermc.connector.entity.player.SessionPlayerEntity;
import org.geysermc.connector.entity.player.SkullPlayerEntity;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.auth.AuthData; import org.geysermc.connector.network.session.auth.AuthData;
import org.geysermc.connector.network.session.auth.BedrockClientData; import org.geysermc.connector.network.session.auth.BedrockClientData;
@ -81,6 +80,7 @@ import org.geysermc.connector.network.session.cache.*;
import org.geysermc.connector.network.translators.BiomeTranslator; import org.geysermc.connector.network.translators.BiomeTranslator;
import org.geysermc.connector.network.translators.EntityIdentifierRegistry; import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry; import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.network.translators.collision.CollisionManager; import org.geysermc.connector.network.translators.collision.CollisionManager;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.skin.SkinManager; import org.geysermc.connector.skin.SkinManager;
@ -369,6 +369,9 @@ public class GeyserSession implements CommandSender {
startGame(); startGame();
this.remoteServer = remoteServer; this.remoteServer = remoteServer;
// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
upstream.getSession().getHardcodedBlockingId().set(ItemRegistry.SHIELD.getBedrockId());
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket(); BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();

Datei anzeigen

@ -38,6 +38,8 @@ import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.utils.InventoryUtils; import org.geysermc.connector.utils.InventoryUtils;
import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.LanguageUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class PlayerInventoryTranslator extends InventoryTranslator { public class PlayerInventoryTranslator extends InventoryTranslator {
@ -62,7 +64,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
for (int i = 36; i < 45; i++) { for (int i = 36; i < 45; i++) {
contents[i - 36] = inventory.getItem(i).getItemData(session); contents[i - 36] = inventory.getItem(i).getItemData(session);
} }
inventoryContentPacket.setContents(contents); inventoryContentPacket.setContents(Arrays.asList(contents));
session.sendUpstreamPacket(inventoryContentPacket); session.sendUpstreamPacket(inventoryContentPacket);
// Armor // Armor
@ -72,13 +74,13 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
for (int i = 5; i < 9; i++) { for (int i = 5; i < 9; i++) {
contents[i - 5] = inventory.getItem(i).getItemData(session); contents[i - 5] = inventory.getItem(i).getItemData(session);
} }
armorContentPacket.setContents(contents); armorContentPacket.setContents(Arrays.asList(contents));
session.sendUpstreamPacket(armorContentPacket); session.sendUpstreamPacket(armorContentPacket);
// Offhand // Offhand
InventoryContentPacket offhandPacket = new InventoryContentPacket(); InventoryContentPacket offhandPacket = new InventoryContentPacket();
offhandPacket.setContainerId(ContainerId.OFFHAND); offhandPacket.setContainerId(ContainerId.OFFHAND);
offhandPacket.setContents(new ItemData[]{inventory.getItem(45).getItemData(session)}); offhandPacket.setContents(Collections.singletonList(inventory.getItem(45).getItemData(session)));
session.sendUpstreamPacket(offhandPacket); session.sendUpstreamPacket(offhandPacket);
} }
@ -127,7 +129,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
} else if (slot == 45) { } else if (slot == 45) {
InventoryContentPacket offhandPacket = new InventoryContentPacket(); InventoryContentPacket offhandPacket = new InventoryContentPacket();
offhandPacket.setContainerId(ContainerId.OFFHAND); offhandPacket.setContainerId(ContainerId.OFFHAND);
offhandPacket.setContents(new ItemData[]{inventory.getItem(slot).getItemData(session)}); offhandPacket.setContents(Collections.singletonList(inventory.getItem(slot).getItemData(session)));
session.sendUpstreamPacket(offhandPacket); session.sendUpstreamPacket(offhandPacket);
} }
} }

Datei anzeigen

@ -32,10 +32,12 @@ import lombok.AllArgsConstructor;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.utils.InventoryUtils; import org.geysermc.connector.utils.InventoryUtils;
import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.LanguageUtils;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class ChestInventoryUpdater extends InventoryUpdater { public class ChestInventoryUpdater extends InventoryUpdater {
private static final ItemData UNUSUABLE_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.slot")); private static final ItemData UNUSUABLE_SPACE_BLOCK = InventoryUtils.createUnusableSpaceBlock(LanguageUtils.getLocaleStringLog("geyser.inventory.unusable_item.slot"));
@ -46,12 +48,12 @@ public class ChestInventoryUpdater extends InventoryUpdater {
public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
super.updateInventory(translator, session, inventory); super.updateInventory(translator, session, inventory);
ItemData[] bedrockItems = new ItemData[paddedSize]; List<ItemData> bedrockItems = new ArrayList<>(paddedSize);
for (int i = 0; i < bedrockItems.length; i++) { for (int i = 0; i < paddedSize; i++) {
if (i < translator.size) { if (i < translator.size) {
bedrockItems[i] = inventory.getItem(i).getItemData(session); bedrockItems.add(inventory.getItem(i).getItemData(session));
} else { } else {
bedrockItems[i] = UNUSUABLE_SPACE_BLOCK; bedrockItems.add(UNUSUABLE_SPACE_BLOCK);
} }
} }

Datei anzeigen

@ -33,6 +33,8 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import java.util.Arrays;
public class ContainerInventoryUpdater extends InventoryUpdater { public class ContainerInventoryUpdater extends InventoryUpdater {
@Override @Override
public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
@ -45,7 +47,7 @@ public class ContainerInventoryUpdater extends InventoryUpdater {
InventoryContentPacket contentPacket = new InventoryContentPacket(); InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(inventory.getId()); contentPacket.setContainerId(inventory.getId());
contentPacket.setContents(bedrockItems); contentPacket.setContents(Arrays.asList(bedrockItems));
session.sendUpstreamPacket(contentPacket); session.sendUpstreamPacket(contentPacket);
} }

Datei anzeigen

@ -34,6 +34,8 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import java.util.Arrays;
public abstract class InventoryUpdater { public abstract class InventoryUpdater {
public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void updateInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
ItemData[] bedrockItems = new ItemData[36]; ItemData[] bedrockItems = new ItemData[36];
@ -43,7 +45,7 @@ public abstract class InventoryUpdater {
} }
InventoryContentPacket contentPacket = new InventoryContentPacket(); InventoryContentPacket contentPacket = new InventoryContentPacket();
contentPacket.setContainerId(ContainerId.INVENTORY); contentPacket.setContainerId(ContainerId.INVENTORY);
contentPacket.setContents(bedrockItems); contentPacket.setContents(Arrays.asList(bedrockItems));
session.sendUpstreamPacket(contentPacket); session.sendUpstreamPacket(contentPacket);
} }

Datei anzeigen

@ -166,19 +166,19 @@ public class RecipeRegistry {
letterToRecipe.put(entry.getKey(), ItemRegistry.getBedrockItemFromJson(entry.getValue())); letterToRecipe.put(entry.getKey(), ItemRegistry.getBedrockItemFromJson(entry.getValue()));
} }
ItemData[] inputs = new ItemData[shape.size() * shape.get(0).length()]; List<ItemData> inputs = new ArrayList<>(shape.size() * shape.get(0).length());
int i = 0; int i = 0;
// Create a linear array of items from the "cube" of the shape // Create a linear array of items from the "cube" of the shape
for (int j = 0; i < shape.size() * shape.get(0).length(); j++) { for (int j = 0; i < shape.size() * shape.get(0).length(); j++) {
for (char c : shape.get(j).toCharArray()) { for (char c : shape.get(j).toCharArray()) {
ItemData data = letterToRecipe.getOrDefault(String.valueOf(c), ItemData.AIR); ItemData data = letterToRecipe.getOrDefault(String.valueOf(c), ItemData.AIR);
inputs[i] = data; inputs.add(data);
i++; i++;
} }
} }
return CraftingData.fromShaped(uuid.toString(), shape.get(0).length(), shape.size(), return CraftingData.fromShaped(uuid.toString(), shape.get(0).length(), shape.size(),
inputs, new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++); inputs, Collections.singletonList(output), uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
} }
List<ItemData> inputs = new ObjectArrayList<>(); List<ItemData> inputs = new ObjectArrayList<>();
for (JsonNode entry : node.get("input")) { for (JsonNode entry : node.get("input")) {
@ -187,10 +187,10 @@ public class RecipeRegistry {
if (node.get("type").asInt() == 5) { if (node.get("type").asInt() == 5) {
// Shulker box // Shulker box
return CraftingData.fromShulkerBox(uuid.toString(), return CraftingData.fromShulkerBox(uuid.toString(),
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++); inputs, Collections.singletonList(output), uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
} }
return CraftingData.fromShapeless(uuid.toString(), return CraftingData.fromShapeless(uuid.toString(),
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++); inputs, Collections.singletonList(output), uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
} }
public static void init() { public static void init() {

Datei anzeigen

@ -68,7 +68,7 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
for (ItemData[] inputs : inputCombinations) { for (ItemData[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(), craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
inputs, new ItemData[]{output}, uuid, "crafting_table", 0, netId)); Arrays.asList(inputs), Collections.singletonList(output), uuid, "crafting_table", 0, netId));
recipeMap.put(netId++, recipe); recipeMap.put(netId++, recipe);
} }
break; break;
@ -81,8 +81,8 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
for (ItemData[] inputs : inputCombinations) { for (ItemData[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(), craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
shapedRecipeData.getWidth(), shapedRecipeData.getHeight(), inputs, shapedRecipeData.getWidth(), shapedRecipeData.getHeight(), Arrays.asList(inputs),
new ItemData[]{output}, uuid, "crafting_table", 0, netId)); Collections.singletonList(output), uuid, "crafting_table", 0, netId));
recipeMap.put(netId++, recipe); recipeMap.put(netId++, recipe);
} }
break; break;