Skip to content

Commit

Permalink
Bedrock 1.16 updating part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 23, 2020
1 parent 56f9330 commit ea1a9e5
Show file tree
Hide file tree
Showing 114 changed files with 660 additions and 594 deletions.
4 changes: 2 additions & 2 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</dependency>
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v390</artifactId>
<version>2.5.6-SNAPSHOT</version>
<artifactId>bedrock-v407</artifactId>
<version>2.6.0-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v390.Bedrock_v390;
import com.nukkitx.protocol.bedrock.v407.Bedrock_v407;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.common.AuthType;
Expand Down Expand Up @@ -70,10 +70,10 @@ public class GeyserConnector {

public static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);

public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v390.V390_CODEC;
public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v407.V392_CODEC;

public static final String NAME = "Geyser";
public static final String VERSION = "DEV"; // A fallback for running in IDEs
public static final String VERSION = "1.0-SNAPSHOT (git-feature/1.16-56f9330)"; // A fallback for running in IDEs

private final Map<InetSocketAddress, GeyserSession> players = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.world.particle.Particle;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.effect.EffectRegistry;
Expand All @@ -42,19 +42,19 @@ public AreaEffectCloudEntity(long entityId, long geyserId, EntityType entityType
metadata.put(EntityData.AREA_EFFECT_CLOUD_DURATION, 600);

// This disabled client side shrink of the cloud
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS_PER_TICK, 0.0f);
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, 0.0f);
}

@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 7) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, (float) entityMetadata.getValue());
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, entityMetadata.getValue());
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * (float) entityMetadata.getValue());
} else if (entityMetadata.getId() == 10) {
Particle particle = (Particle) entityMetadata.getValue();
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, EffectRegistry.getParticleString(particle.getType()));
} else if (entityMetadata.getId() == 8) {
metadata.put(EntityData.POTION_COLOR, entityMetadata.getValue());
metadata.put(EntityData.POTION_AUX_VALUE, entityMetadata.getValue());
}
super.updateBedrockMetadata(entityMetadata, session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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 com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

Expand Down Expand Up @@ -92,7 +92,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
} else if (entityMetadata.getId() == 11) {
isPaddlingLeft = (boolean) entityMetadata.getValue();
if (!isPaddlingLeft) {
metadata.put(EntityData.PADDLE_TIME_LEFT, 0f);
metadata.put(EntityData.ROW_TIME_LEFT, 0f);
}
else {
// Java sends simply "true" and "false" (is_paddling_left), Bedrock keeps sending packets as you're rowing
Expand All @@ -106,7 +106,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
else if (entityMetadata.getId() == 12) {
isPaddlingRight = (boolean) entityMetadata.getValue();
if (!isPaddlingRight) {
metadata.put(EntityData.PADDLE_TIME_RIGHT, 0f);
metadata.put(EntityData.ROW_TIME_RIGHT, 0f);
} else {
paddleTimeRight = 0f;
session.getConnector().getGeneralThreadPool().execute(() ->
Expand All @@ -124,7 +124,7 @@ else if (entityMetadata.getId() == 12) {
public void updateLeftPaddle(GeyserSession session, EntityMetadata entityMetadata) {
if (isPaddlingLeft) {
paddleTimeLeft += ROWING_SPEED;
metadata.put(EntityData.PADDLE_TIME_LEFT, paddleTimeLeft);
metadata.put(EntityData.ROW_TIME_LEFT, paddleTimeLeft);
super.updateBedrockMetadata(entityMetadata, session);
session.getConnector().getGeneralThreadPool().schedule(() ->
updateLeftPaddle(session, entityMetadata),
Expand All @@ -136,7 +136,7 @@ public void updateLeftPaddle(GeyserSession session, EntityMetadata entityMetadat
public void updateRightPaddle(GeyserSession session, EntityMetadata entityMetadata) {
if (isPaddlingRight) {
paddleTimeRight += ROWING_SPEED;
metadata.put(EntityData.PADDLE_TIME_RIGHT, paddleTimeRight);
metadata.put(EntityData.ROW_TIME_RIGHT, paddleTimeRight);
super.updateBedrockMetadata(entityMetadata, session);
session.getConnector().getGeneralThreadPool().schedule(() ->
updateRightPaddle(session, entityMetadata),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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 com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
Expand All @@ -45,7 +45,7 @@ public DefaultBlockMinecartEntity(long entityId, long geyserId, EntityType entit
super(entityId, geyserId, entityType, position, motion, rotation);

updateDefaultBlockMetadata();
metadata.put(EntityData.HAS_DISPLAY, (byte) 1);
metadata.put(EntityData.CUSTOM_DISPLAY, (byte) 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

Expand Down
33 changes: 17 additions & 16 deletions connector/src/main/java/org/geysermc/connector/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.EntityFlags;
import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlags;
import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import lombok.Getter;
Expand Down Expand Up @@ -106,9 +107,9 @@ public Entity(long entityId, long geyserId, EntityType entityType, Vector3f posi

metadata.put(EntityData.SCALE, 1f);
metadata.put(EntityData.COLOR, 0);
metadata.put(EntityData.MAX_AIR, (short) 300);
metadata.put(EntityData.AIR, (short) 0);
metadata.put(EntityData.LEAD_HOLDER_EID, -1L);
metadata.put(EntityData.MAX_AIR_SUPPLY, (short) 300);
metadata.put(EntityData.AIR_SUPPLY, (short) 0);
metadata.put(EntityData.LEASH_HOLDER_EID, -1L);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight());
metadata.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth());
EntityFlags flags = new EntityFlags();
Expand Down Expand Up @@ -240,7 +241,7 @@ public void updateRotation(GeyserSession session, float yaw, float pitch, boolea
public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;

List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>();
List<AttributeData> attributes = new ArrayList<>();
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
continue;
Expand Down Expand Up @@ -291,17 +292,17 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}
} else if (session.getPlayerEntity().getEntityId() == entityId && !metadata.getFlags().getFlag(EntityFlag.SNEAKING) && metadata.getFlags().getFlag(EntityFlag.BLOCKING)) {
metadata.getFlags().setFlag(EntityFlag.BLOCKING, false);
metadata.getFlags().setFlag(EntityFlag.DISABLE_BLOCKING, true);
metadata.getFlags().setFlag(EntityFlag.IS_AVOIDING_BLOCK, true); //TODO: CHECK
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(0, 0, 0), BlockFace.DOWN);
session.sendDownstreamPacket(releaseItemPacket);
}
}
break;
case 1: // Air/bubbles
if ((int) entityMetadata.getValue() == 300) {
metadata.put(EntityData.AIR, (short) 0); // Otherwise the bubble counter remains in the UI
metadata.put(EntityData.AIR_SUPPLY, (short) 0); // Otherwise the bubble counter remains in the UI
} else {
metadata.put(EntityData.AIR, (short) (int) entityMetadata.getValue());
metadata.put(EntityData.AIR_SUPPLY, (short) (int) entityMetadata.getValue());
}
break;
case 2: // custom name
Expand All @@ -317,7 +318,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
break;
case 3: // is custom name visible
if (!this.is(PlayerEntity.class))
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
metadata.put(EntityData.NAMETAG_ALWAYS_SHOW, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
break;
case 4: // silent
metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue());
Expand All @@ -329,26 +330,26 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
if (entityMetadata.getValue().equals(Pose.SLEEPING)) {
metadata.getFlags().setFlag(EntityFlag.SLEEPING, true);
// Has to be a byte or it does not work
metadata.put(EntityData.CAN_START_SLEEP, (byte) 2);
metadata.put(EntityData.PLAYER_FLAGS, (byte) 2); //TODO: CHECK
if (entityId == session.getPlayerEntity().getEntityId()) {
Vector3i lastInteractionPos = session.getLastInteractionPosition();
metadata.put(EntityData.BED_RESPAWN_POS, lastInteractionPos);
metadata.put(EntityData.BED_POSITION, lastInteractionPos);
if (session.getConnector().getConfig().isCacheChunks()) {
int bed = session.getConnector().getWorldManager().getBlockAt(session, lastInteractionPos.getX(),
lastInteractionPos.getY(), lastInteractionPos.getZ());
// Bed has to be updated, or else player is floating in the air
ChunkUtils.updateBlock(session, bed, lastInteractionPos);
}
} else {
metadata.put(EntityData.BED_RESPAWN_POS, Vector3i.from(position.getFloorX(), position.getFloorY() - 2, position.getFloorZ()));
metadata.put(EntityData.BED_POSITION, Vector3i.from(position.getFloorX(), position.getFloorY() - 2, position.getFloorZ()));
}
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f);
} else if (metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
metadata.getFlags().setFlag(EntityFlag.SLEEPING, false);
metadata.put(EntityData.BOUNDING_BOX_WIDTH, getEntityType().getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, getEntityType().getHeight());
metadata.put(EntityData.CAN_START_SLEEP, (byte) 0);
metadata.put(EntityData.PLAYER_FLAGS, (byte) 0);
}
break;
case 7: // blocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.geysermc.connector.entity;

import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
package org.geysermc.connector.entity;

import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.object.ProjectileData;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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 com.nukkitx.protocol.bedrock.data.entity.EntityData;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
Expand Down Expand Up @@ -150,7 +150,7 @@ public boolean despawnEntity(GeyserSession session) {
updateBlockPacket.setBlockPosition(bedrockPosition);
updateBlockPacket.setRuntimeId(0);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NONE);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NO_GRAPHIC); //TODO: Used to be NONE
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.sendUpstreamPacket(updateBlockPacket);
session.getItemFrameCache().remove(position, entityId);
Expand Down Expand Up @@ -178,7 +178,7 @@ public void updateBlock(GeyserSession session) {
updateBlockPacket.setBlockPosition(bedrockPosition);
updateBlockPacket.setRuntimeId(bedrockRuntimeId);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.PRIORITY);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NONE);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NO_GRAPHIC); //TODO Same
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.sendUpstreamPacket(updateBlockPacket);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.ContainerId;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;

import lombok.Getter;
import lombok.Setter;

import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

Expand All @@ -58,13 +56,13 @@ public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
switch (entityMetadata.getId()) {
case 8:
metadata.put(EntityData.HEALTH, (float) entityMetadata.getValue());
metadata.put(EntityData.HEALTH, entityMetadata.getValue());
break;
case 9:
metadata.put(EntityData.POTION_COLOR, (int) entityMetadata.getValue());
metadata.put(EntityData.POTION_AUX_VALUE, entityMetadata.getValue()); //TODO: CHECK THIS AND THE BOTTOM ONE
break;
case 10:
metadata.put(EntityData.POTION_AMBIENT, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
metadata.put(EntityData.EFFECT_AMBIENT, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
break;
}

Expand Down
Loading

0 comments on commit ea1a9e5

Please sign in to comment.