Merge remote-tracking branch 'origin/master' into block-entities

This commit is contained in:
RednedEpic 2019-12-23 13:49:20 -06:00
commit e1ba1fa3e8
28 changed files with 6236 additions and 5793 deletions

View file

@ -4,7 +4,7 @@
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Build Status](https://ci.nukkitx.com/job/Geyser/job/master/badge/icon)](https://ci.nukkitx.com/job/Geyser/job/master/)
[![Discord](https://img.shields.io/discord/597838753859633172.svg?color=%237289da&label=discord)](http://discord.geysermc.org/)
[![Discord](https://img.shields.io/discord/613163671870242838.svg?color=%237289da&label=discord)](http://discord.geysermc.org/)
[![HitCount](http://hits.dwyl.io/Geyser/GeyserMC.svg)](http://hits.dwyl.io/Geyser/GeyserMC)
Geyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Edition, closing the gap from those wanting to play true cross-platform.
@ -13,39 +13,31 @@ Geyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Editio
Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers.
The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible.
### Please note, this project is still a work in progress and should not be used on production.
### Please note, this project is still a work in progress and should not be used on production. Expect bugs!
## Setting Up
Please note, Geyser is **not** a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up.
Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up.
[![YouTube Video](https://img.youtube.com/vi/OmLxwl7_UzQ/0.jpg)](https://www.youtube.com/watch?v=OmLxwl7_UzQ)
[![YouTube Video](https://img.youtube.com/vi/U7dZZ8w7Gi4/0.jpg)](https://www.youtube.com/watch?v=U7dZZ8w7Gi4)
Links:
## Links:
- Website: https://geysermc.org
- Docs: https://github.com/GeyserMC/Geyser/wiki
- Download: http://ci.geysermc.org
- Discord: http://discord.geysermc.org/
- Donate: https://patreon.com/GeyserMC
## What's Completed
- [x] Server recognized in server list
- [x] Join detection from remote
- [x] Online mode/auth support
- [x] Chat/command support
- [x] Scoreboard
- [ ] Inventory support
- [x] Inventory viewing
- [x] NBT data
- [ ] Inventory movement (transactions)
- [x] Player movement support
- [x] Entity support
- [x] Player support
- [ ] Chunks
- [x] Block translation (may be missing mappings)
- [x] Block updates
- [ ] Block entities
- [x] Extra data
- [ ] Biome colors
- [x] Block break/place support
## What's Left to be Added/Fixed
- Inventories ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- Crafting ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- Creative Mode ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- Sounds
- Block Particles
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
- Biome Colors
- Some Entity Flags
- Proper Movement
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
## Compiling
1. Clone the repo to your computer

View file

@ -59,12 +59,6 @@
<version>1.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
@ -73,8 +67,8 @@
</dependency>
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v388</artifactId>
<version>2.4.0</version>
<artifactId>bedrock-v389</artifactId>
<version>2.4.4</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -110,7 +104,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>1.14.4-2-SNAPSHOT</version>
<version>1.15.1-1-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
@ -129,7 +123,7 @@
</dependency>
</dependencies>
<build>
<finalName>${outputName}-noshade</finalName>
<finalName>${project.parent.name}-noshade</finalName>
<directory>../target</directory>
<plugins>
<plugin>
@ -147,7 +141,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<finalName>${outputName}</finalName>
<finalName>${project.parent.name}</finalName>
</configuration>
</plugin>
<plugin>
@ -162,7 +156,7 @@
</execution>
</executions>
<configuration>
<finalName>${outputName}</finalName>
<finalName>${project.parent.name}</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
</configuration>

View file

@ -27,7 +27,7 @@ package org.geysermc.connector;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v388.Bedrock_v388;
import com.nukkitx.protocol.bedrock.v389.Bedrock_v389;
import lombok.Getter;
import org.fusesource.jansi.AnsiConsole;
@ -67,7 +67,7 @@ import java.util.concurrent.TimeUnit;
@Getter
public class GeyserConnector implements Connector {
public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v388.V388_CODEC;
public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v389.V389_CODEC;
public static final String NAME = "Geyser";
public static final String VERSION = "1.0-SNAPSHOT";

View file

@ -39,10 +39,6 @@ public class AbstractHorseEntity extends AnimalEntity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 17) {
metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue());
}
super.updateBedrockMetadata(entityMetadata, session);
}
}

View file

@ -39,7 +39,7 @@ public class AgeableEntity extends CreatureEntity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 14) {
if (entityMetadata.getId() == 15) {
metadata.getFlags().setFlag(EntityFlag.BABY, (boolean) entityMetadata.getValue());
}

View file

@ -41,7 +41,7 @@ public class InsentientEntity extends LivingEntity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 13 && entityMetadata.getType() == MetadataType.BYTE) {
if (entityMetadata.getId() == 14 && entityMetadata.getType() == MetadataType.BYTE) {
byte xd = (byte) entityMetadata.getValue();
metadata.getFlags().setFlag(EntityFlag.NO_AI, (xd & 0x01) == 0x01);
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.entity.living.horse;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import org.geysermc.connector.entity.living.AbstractHorseEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
public class HorseEntity extends AbstractHorseEntity {
public HorseEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 18) {
metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue());
}
super.updateBedrockMetadata(entityMetadata, session);
}
}

View file

@ -0,0 +1,37 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.entity.living.horse;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.living.ChestedHorseEntity;
import org.geysermc.connector.entity.type.EntityType;
public class LlamaEntity extends ChestedHorseEntity {
public LlamaEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}
}

View file

@ -41,7 +41,7 @@ public class GuardianEntity extends MonsterEntity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 15) {
if (entityMetadata.getId() == 16) {
Entity entity = session.getEntityCache().getEntityByJavaId((int) entityMetadata.getValue());
if (entity != null) {
metadata.put(EntityData.TARGET_EID, entity.getGeyserId());

View file

@ -28,6 +28,8 @@ package org.geysermc.connector.entity.type;
import lombok.Getter;
import org.geysermc.connector.entity.*;
import org.geysermc.connector.entity.living.*;
import org.geysermc.connector.entity.living.horse.HorseEntity;
import org.geysermc.connector.entity.living.horse.LlamaEntity;
import org.geysermc.connector.entity.living.monster.GuardianEntity;
import org.geysermc.connector.entity.living.monster.ZombieEntity;
@ -46,14 +48,15 @@ public enum EntityType {
BAT(AmbientEntity.class, 19, 0.9f, 0.5f),
IRON_GOLEM(GolemEntity.class, 20, 2.7f, 1.4f),
SNOW_GOLEM(GolemEntity.class, 21, 1.9f, 0.7f),
OCELOT(TameableEntity.class, 22, 0.35f, 0.3f),
HORSE(AbstractHorseEntity.class, 23, 1.6f, 1.3965f),
OCELOT(AgeableEntity.class, 22, 0.35f, 0.3f),
HORSE(HorseEntity.class, 23, 1.6f, 1.3965f),
DONKEY(ChestedHorseEntity.class, 24, 1.6f, 1.3965f),
MULE(ChestedHorseEntity.class, 25, 1.6f, 1.3965f),
SKELETON_HORSE(AbstractHorseEntity.class, 26, 1.6f, 1.3965f),
ZOMBIE_HORSE(AbstractHorseEntity.class, 27, 1.6f, 1.3965f),
POLAR_BEAR(AnimalEntity.class, 28, 1.4f, 1.3f),
LLAMA(ChestedHorseEntity.class, 29, 1.87f, 0.9f),
LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f),
TRADER_LLAMA(LlamaEntity.class, 29, 1.187f, 0.9f),
PARROT(TameableEntity.class, 30, 0.9f, 0.5f),
DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f),
ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f),
@ -101,8 +104,7 @@ public enum EntityType {
FIREWORK_ROCKET(Entity.class, 72, 0f),
TRIDENT(ArrowEntity.class, 73, 0f),
TURTLE(AnimalEntity.class, 74, 0.4f, 1.2f),
// TODO CAT (need to figure out how to deal with baby cats) https://github.com/NukkitX/Nukkit/blob/master/src/main/java/cn/nukkit/entity/passive/EntityCat.java
CAT(TameableEntity.class, 75, 0.35f, 0.3f),
SHULKER_BULLET(Entity.class, 76, 0f),
FISHING_BOBBER(Entity.class, 77, 0f),
CHALKBOARD(Entity.class, 78, 0f),
@ -140,7 +142,8 @@ public enum EntityType {
TROPICAL_FISH(AbstractFishEntity.class, 111, 0.6f, 0.6f),
COD(AbstractFishEntity.class, 112, 0.25f, 0.5f),
PANDA(AnimalEntity.class, 113, 1.25f, 1.125f, 1.825f),
FOX(AnimalEntity.class, 121, 0.5f, 1.25f);
FOX(AnimalEntity.class, 121, 0.5f, 1.25f),
BEE(InsentientEntity.class, 122, 0.6f, 0.6f);
private Class<? extends Entity> entityClass;
private final int type;

View file

@ -46,7 +46,6 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
@Override
public boolean handle(LoginPacket loginPacket) {
if (loginPacket.getProtocolVersion() != GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()) {
connector.getLogger().debug("unsupported");
session.getUpstream().disconnect("Unsupported Bedrock version. Are you running an outdated version?");
return true;
}
@ -73,7 +72,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
ResourcePackStackPacket stack = new ResourcePackStackPacket();
stack.setExperimental(false);
stack.setForcedToAccept(false);
stack.setGameVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
stack.setGameVersion("*");
session.getUpstream().sendPacket(stack);
break;
default:
@ -132,4 +131,4 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
public boolean handle(InventoryTransactionPacket packet) {
return translateAndDefault(packet);
}
}
}

View file

@ -295,7 +295,7 @@ public class GeyserSession implements Player {
startGamePacket.setLevelGamemode(0);
startGamePacket.setDifficulty(1);
startGamePacket.setDefaultSpawn(Vector3i.ZERO);
startGamePacket.setAcheivementsDisabled(true);
startGamePacket.setAchievementsDisabled(true);
startGamePacket.setTime(-1);
startGamePacket.setEduEditionOffers(0);
startGamePacket.setEduFeaturesEnabled(false);
@ -328,7 +328,7 @@ public class GeyserSession implements Player {
startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setBlockPalette(Toolbox.BLOCKS);
startGamePacket.setItemEntries(Toolbox.ITEMS);
startGamePacket.setVanillaVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
startGamePacket.setVanillaVersion("*");
// startGamePacket.setMovementServerAuthoritative(true);
upstream.sendPacket(startGamePacket);
}

View file

@ -79,7 +79,7 @@ public class ChunkCache {
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
if (chunk != null) {
BlockState blockState = chunk.get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
return TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
return TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
}
return BlockEntry.AIR;

View file

@ -25,23 +25,30 @@
package org.geysermc.connector.network.translators.block;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class BlockEntry {
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0, 0);
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0);
private String javaIdentifier;
private int javaId;
private final String javaIdentifier;
private final int javaId;
private final int bedrockRuntimeId;
private final boolean waterlogged;
private int bedrockId;
private int bedrockData;
public BlockEntry(String javaIdentifier, int javaId, int bedrockRuntimeId) {
this.javaIdentifier = javaIdentifier;
this.javaId = javaId;
this.bedrockRuntimeId = bedrockRuntimeId;
this.waterlogged = (javaIdentifier.contains("waterlogged=true")
|| javaIdentifier.startsWith("minecraft:kelp")
|| javaIdentifier.contains("seagrass")
|| javaIdentifier.startsWith("minecraft:bubble_column"));
}
@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof BlockEntry && ((BlockEntry) obj).getBedrockId() == this.getBedrockId() && ((BlockEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier()));
return obj == this || (obj instanceof BlockEntry && ((BlockEntry) obj).getBedrockRuntimeId() == this.getBedrockRuntimeId() && ((BlockEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier()));
}
}

View file

@ -3,9 +3,18 @@ package org.geysermc.connector.network.translators.block;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.utils.Toolbox;
public class BlockTranslator {
import java.util.HashMap;
import java.util.Map;
public BlockEntry getBedrockBlock(BlockState state) {
public class BlockTranslator {
private final Map<String, BlockEntry> javaIdentifierMap = new HashMap<>();
public BlockEntry getBlockEntry(BlockState state) {
return Toolbox.BLOCK_ENTRIES.get(state.getId());
}
public BlockEntry getBlockEntry(String javaIdentifier) {
return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values()
.stream().filter(blockEntry -> blockEntry.getJavaIdentifier().equals(key)).findFirst().orElse(null));
}
}

View file

@ -26,13 +26,9 @@
package org.geysermc.connector.network.translators.java.entity.player;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.utils.ChunkUtils;
public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> {
@ -40,18 +36,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
public void translate(ServerPlayerActionAckPacket packet, GeyserSession session) {
switch (packet.getAction()) {
case FINISH_DIGGING:
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
packet.getPosition().getX(),
packet.getPosition().getY(),
packet.getPosition().getZ()));
BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
ChunkUtils.updateBlock(session, packet.getNewState(), packet.getPosition());
break;
}
}

View file

@ -1,31 +1,14 @@
package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.utils.ChunkUtils;
public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> {
@Override
public void translate(ServerBlockChangePacket packet, GeyserSession session) {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
BlockChangeRecord record = packet.getRecord();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
record.getPosition().getX(),
record.getPosition().getY(),
record.getPosition().getZ()
));
BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
ChunkUtils.updateBlock(session, packet.getRecord().getBlock(), packet.getRecord().getPosition());
}
}

View file

@ -27,32 +27,16 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.utils.ChunkUtils;
public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> {
@Override
public void translate(ServerMultiBlockChangePacket packet, GeyserSession session) {
for (BlockChangeRecord record : packet.getRecords()) {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
record.getPosition().getX(),
record.getPosition().getY(),
record.getPosition().getZ()
));
BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(blockEntry.getBedrockId() << 4 | blockEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
ChunkUtils.updateBlock(session, record.getBlock(), record.getPosition());
}
}
}

View file

@ -2,10 +2,15 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.geysermc.connector.console.GeyserLogger;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.network.translators.block.entity.BlockEntityTranslator;
@ -39,24 +44,14 @@ public class ChunkUtils {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
BlockState blockState = chunk.get(x, y, z);
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState);
// Block entity data for signs is not sent in this packet, which is needed
// for bedrock, so we need to check the block itself
// if (block.getJavaIdentifier().contains("sign")) {
//// SignBlockEntityTranslator sign = (SignBlockEntityTranslator) BlockEntityUtils.getBlockEntityTranslator("Sign");
//// blockEntities.add(sign.getDefaultJavaTag(x, y, z));
// section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), 0);
//// System.out.println("Found sign at " + x + " " + y + " " + z);
// continue;
// }
BlockEntry block = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
block.getBedrockId() << 4 | block.getBedrockData());
block.getBedrockRuntimeId());
if (block.getJavaIdentifier().contains("waterlogged=true")) {
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z),
9 << 4); // water id
if (block.isWaterlogged()) {
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), water.getBedrockRuntimeId());
}
}
}
@ -80,6 +75,29 @@ public class ChunkUtils {
return chunkData;
}
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(pos);
updateBlockPacket.setRuntimeId(blockEntry.getBedrockRuntimeId());
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
UpdateBlockPacket waterPacket = new UpdateBlockPacket();
waterPacket.setDataLayer(1);
waterPacket.setBlockPosition(pos);
if (blockEntry.isWaterlogged()) {
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
waterPacket.setRuntimeId(water.getBedrockRuntimeId());
} else {
waterPacket.setRuntimeId(0);
}
session.getUpstream().sendPacket(waterPacket);
}
public static final class ChunkData {
public ChunkSection[] sections;

View file

@ -165,10 +165,10 @@ public class SkinProvider {
Geyser.getLogger().debug("Downloaded " + imageUrl);
if (cape) {
image = image.getWidth() > 64 ? scale(image) : image;
BufferedImage newImage = new BufferedImage(64, 32, BufferedImage.TYPE_INT_RGB);
Graphics g = newImage.createGraphics();
g.drawImage(image, 0, 0, 64, 32, null);
g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
g.dispose();
image = newImage;
}
@ -193,6 +193,15 @@ public class SkinProvider {
}
}
private static BufferedImage scale (BufferedImage bufferedImage) {
BufferedImage resized = new BufferedImage(bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = resized.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2.drawImage(bufferedImage, 0, 0, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2, null);
g2.dispose();
return resized;
}
public static <T> T getOrDefault(CompletableFuture<T> future, T defaultValue, int timeoutInSeconds) {
try {
return future.get(timeoutInSeconds, TimeUnit.SECONDS);

View file

@ -5,6 +5,7 @@ import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag;
import com.nukkitx.nbt.tag.Tag;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -13,7 +14,6 @@ import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import java.io.InputStream;
import java.util.*;
@ -32,7 +32,6 @@ public class Toolbox {
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
}
Map<String, Integer> blockIdToIdentifier = new HashMap<>();
ListTag<CompoundTag> blocksTag;
NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream);
@ -44,15 +43,6 @@ public class Toolbox {
throw new AssertionError(ex);
}
for (CompoundTag entry : blocksTag.getValue()) {
String name = entry.getAsCompound("block").getAsString("name");
int id = entry.getAsShort("id");
int data = entry.getAsShort("meta");
blockIdToIdentifier.put(name, id);
GlobalBlockPalette.registerMapping(id << 4 | data);
}
BLOCKS = blocksTag;
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json");
if (stream2 == null) {
@ -97,16 +87,38 @@ public class Toolbox {
ex.printStackTrace();
}
int blockIndex = 0;
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) {
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) {
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!");
BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block
} else {
BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data")));
}
int javaIndex = -1;
javaLoop:
for (Map.Entry<String, Map<String, Object>> javaEntry : blocks.entrySet()) {
javaIndex++;
String wantedIdentifier = (String) javaEntry.getValue().get("bedrock_identifier");
Map<String, Object> wantedStates = (Map<String, Object>) javaEntry.getValue().get("bedrock_states");
blockIndex++;
int bedrockIndex = -1;
bedrockLoop:
for (CompoundTag bedrockEntry : BLOCKS.getValue()) {
bedrockIndex++;
CompoundTag blockTag = bedrockEntry.getAsCompound("block");
if (blockTag.getAsString("name").equals(wantedIdentifier)) {
if (wantedStates != null) {
Map<String, Tag<?>> bedrockStates = blockTag.getAsCompound("states").getValue();
for (Map.Entry<String, Object> stateEntry : wantedStates.entrySet()) {
Tag<?> bedrockStateTag = bedrockStates.get(stateEntry.getKey());
if (bedrockStateTag == null)
continue bedrockLoop;
Object bedrockStateValue = bedrockStateTag.getValue();
if (bedrockStateValue instanceof Byte)
bedrockStateValue = ((Byte) bedrockStateValue).intValue();
if (!stateEntry.getValue().equals(bedrockStateValue))
continue bedrockLoop;
}
}
BlockEntry blockEntry = new BlockEntry(javaEntry.getKey(), javaIndex, bedrockIndex);
BLOCK_ENTRIES.put(javaIndex, blockEntry);
continue javaLoop;
}
}
GeyserLogger.DEFAULT.debug("Mapping " + javaEntry.getKey() + " was not found for bedrock edition!");
}
}
}

View file

@ -1,47 +0,0 @@
package org.geysermc.connector.world;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Adapted from NukkitX: https://github.com/NukkitX/Nukkit
*/
public class GlobalBlockPalette {
private static final Int2IntMap legacyToRuntimeId = new Int2IntOpenHashMap();
private static final Int2IntMap runtimeIdToLegacy = new Int2IntOpenHashMap();
private static final AtomicInteger runtimeIdAllocator = new AtomicInteger(0);
static {
legacyToRuntimeId.defaultReturnValue(-1);
runtimeIdToLegacy.defaultReturnValue(-1);
}
public static int getOrCreateRuntimeId(int id, int meta) {
return getOrCreateRuntimeId((id << 4) | meta);
}
public static int getOrCreateRuntimeId(int legacyId) throws NoSuchElementException {
int runtimeId = legacyToRuntimeId.get(legacyId);
if (!legacyToRuntimeId.containsKey(legacyId) || runtimeId == -1) {
//runtimeId = registerMapping(runtimeIdAllocator.incrementAndGet(), legacyId);
// throw new NoSuchElementException("Unmapped block registered id:" + (legacyId >>> 4) + " meta:" + (legacyId & 0xf));
return 0;
}
return runtimeId;
}
public static int registerMapping(int legacyId) {
int runtimeId = runtimeIdAllocator.getAndIncrement();
runtimeIdToLegacy.put(runtimeId, legacyId);
legacyToRuntimeId.put(legacyId, runtimeId);
return runtimeId;
}
public static int getLegacyId(int runtimeId) {
return runtimeIdToLegacy.get(runtimeId);
}
}

View file

@ -4,7 +4,6 @@ import com.nukkitx.network.VarInts;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.world.chunk.bitarray.BitArray;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
@ -44,11 +43,11 @@ public class BlockStorage {
}
public synchronized int getFullBlock(int index) {
return this.legacyIdFor(this.bitArray.get(index));
return this.palette.getInt(this.bitArray.get(index));
}
public synchronized void setFullBlock(int index, int legacyId) {
int idx = this.idFor(legacyId);
public synchronized void setFullBlock(int index, int runtimeId) {
int idx = this.idFor(runtimeId);
this.bitArray.set(index, idx);
}
@ -72,8 +71,7 @@ public class BlockStorage {
this.bitArray = newBitArray;
}
private int idFor(int legacyId) {
int runtimeId = GlobalBlockPalette.getOrCreateRuntimeId(legacyId);
private int idFor(int runtimeId) {
int index = this.palette.indexOf(runtimeId);
if (index != -1) {
return index;
@ -91,11 +89,6 @@ public class BlockStorage {
return index;
}
private int legacyIdFor(int index) {
int runtimeId = this.palette.get(index);
return GlobalBlockPalette.getLegacyId(runtimeId);
}
public boolean isEmpty() {
if (this.palette.size() == 1) {
return true;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

@ -1 +1 @@
Subproject commit 5ec6f1f339506129514de59d0e09e9b2c612e8be
Subproject commit b9308a64699fabb7510a05d3b270ccd6dd52b635

View file

@ -7,7 +7,7 @@
<artifactId>geyser-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>GeyserMC</name>
<name>Geyser</name>
<description>Allows for players from Minecraft Bedrock Edition to join Minecraft Java Edition servers.</description>
<url>https://geysermc.org</url>