Skip to content

Commit

Permalink
Merge branch 'feature/1.16' into feature/mcee-1.16
Browse files Browse the repository at this point in the history
# Conflicts:
#	connector/pom.xml
#	connector/src/main/java/org/geysermc/connector/entity/living/animal/StriderEntity.java
#	connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java
#	connector/src/main/java/org/geysermc/connector/network/translators/BiomeTranslator.java
#	connector/src/main/resources/mappings
  • Loading branch information
bundabrg committed Jul 1, 2020
2 parents 00fbe6a + 81651cf commit 075cb1d
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t

Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have now joined us here!

### Currently supporting Minecraft Bedrock v1.16.0 and Minecraft Java v1.16.1.
### Currently supporting Minecraft Bedrock v1.16.0/1 and Minecraft Java v1.16.1.

## Setting Up
Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set up Geyser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
case 0:
if (entityMetadata.getType() == MetadataType.BYTE) {
byte xd = (byte) entityMetadata.getValue();
metadata.getFlags().setFlag(EntityFlag.ON_FIRE, (xd & 0x01) == 0x01);
metadata.getFlags().setFlag(EntityFlag.ON_FIRE, ((xd & 0x01) == 0x01) && !metadata.getFlags().getFlag(EntityFlag.FIRE_IMMUNE)); // Otherwise immune entities sometimes flicker onfire
metadata.getFlags().setFlag(EntityFlag.SNEAKING, (xd & 0x02) == 0x02);
metadata.getFlags().setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08);
metadata.getFlags().setFlag(EntityFlag.SWIMMING, ((xd & 0x10) == 0x10) && metadata.getFlags().getFlag(EntityFlag.SPRINTING)); // Otherwise swimming is enabled on older servers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.AttributeData;
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 com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.AttributeUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Getter
@Setter
Expand Down Expand Up @@ -98,4 +106,34 @@ public void updateEquipment(GeyserSession session) {
session.sendUpstreamPacket(handPacket);
session.sendUpstreamPacket(offHandPacket);
}

@Override
public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;

float maxHealth = this.attributes.containsKey(AttributeType.MAX_HEALTH) ? this.attributes.get(AttributeType.MAX_HEALTH).getValue() : getDefaultMaxHealth();

List<AttributeData> attributes = new ArrayList<>();
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
continue;

attributes.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
}
// Add health attribute to properly show hearts when mounting
attributes.add(new AttributeData("minecraft:health", 0.0f, maxHealth, metadata.getFloat(EntityData.HEALTH, 20f), maxHealth));

UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
updateAttributesPacket.setRuntimeEntityId(geyserId);
updateAttributesPacket.setAttributes(attributes);
session.sendUpstreamPacket(updateAttributesPacket);
}

/**
* Used for the health visual when mounting an entity.
* @return the default maximum health for the entity.
*/
protected float getDefaultMaxHealth() {
return 20f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,18 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.AttributeUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class PigEntity extends AnimalEntity {

// For updating the pig heart visual easier
private float health = 20f;

public PigEntity(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() == 8) {
health = (float) entityMetadata.getValue();
updateBedrockAttributes(session);
}

if (entityMetadata.getId() == 16) {
metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue());
Expand All @@ -62,23 +47,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;

float maxHealth = attributes.containsKey(AttributeType.MAX_HEALTH) ? attributes.get(AttributeType.MAX_HEALTH).getValue() : 20f;

List<AttributeData> attributesLocal = new ArrayList<>();
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
continue;

attributesLocal.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
}
attributesLocal.add(new AttributeData("minecraft:health", 0.0f, maxHealth, health, maxHealth));

UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
updateAttributesPacket.setRuntimeEntityId(geyserId);
updateAttributesPacket.setAttributes(attributesLocal);
session.sendUpstreamPacket(updateAttributesPacket);
protected float getDefaultMaxHealth() {
return 10f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ public class StriderEntity extends AnimalEntity {

public StriderEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);

metadata.getFlags().setFlag(EntityFlag.FIRE_IMMUNE, true);
metadata.getFlags().setFlag(EntityFlag.BREATHING, true);
}

@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 17) {
metadata.getFlags().setFlag(EntityFlag.ALWAYS_SHOW_NAME, (boolean) entityMetadata.getValue());
metadata.getFlags().setFlag(EntityFlag.BREATHING, !(boolean) entityMetadata.getValue());
metadata.getFlags().setFlag(EntityFlag.SHAKING, (boolean) entityMetadata.getValue());
}
if (entityMetadata.getId() == 18) {
metadata.getFlags().setFlag(EntityFlag.SADDLED, (boolean) entityMetadata.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,20 @@

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.living.animal.AnimalEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.AttributeUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AbstractHorseEntity extends AnimalEntity {

// For updating the horse visual easier
private float health = 20f;

public AbstractHorseEntity(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() == 8) {
health = (float) entityMetadata.getValue();
updateBedrockAttributes(session);
}

if (entityMetadata.getId() == 16) {
byte xd = (byte) entityMetadata.getValue();
metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x02) == 0x02);
Expand All @@ -71,25 +55,4 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s

super.updateBedrockMetadata(entityMetadata, session);
}

@Override
public void updateBedrockAttributes(GeyserSession session) {
if (!valid) return;

float maxHealth = attributes.containsKey(AttributeType.MAX_HEALTH) ? attributes.get(AttributeType.MAX_HEALTH).getValue() : 20f;

List<AttributeData> attributesLocal = new ArrayList<>();
for (Map.Entry<AttributeType, org.geysermc.connector.entity.attribute.Attribute> entry : this.attributes.entrySet()) {
if (!entry.getValue().getType().isBedrockAttribute())
continue;

attributesLocal.add(AttributeUtils.getBedrockAttribute(entry.getValue()));
}
attributesLocal.add(new AttributeData("minecraft:health", 0.0f, maxHealth, health, maxHealth));

UpdateAttributesPacket updateAttributesPacket = new UpdateAttributesPacket();
updateAttributesPacket.setRuntimeEntityId(geyserId);
updateAttributesPacket.setAttributes(attributesLocal);
session.sendUpstreamPacket(updateAttributesPacket);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2019-2020 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.monster;

import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;

public class ZombifiedPiglinEntity extends ZombieEntity {

public ZombifiedPiglinEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);

metadata.getFlags().setFlag(EntityFlag.FIRE_IMMUNE, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public enum EntityType {
CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f),
SKELETON(AbstractSkeletonEntity.class, 34, 1.8f, 0.6f, 0.6f, 1.62f),
SPIDER(SpiderEntity.class, 35, 0.9f, 1.4f, 1.4f, 1f),
ZOMBIFIED_PIGLIN(ZombieEntity.class, 36, 1.95f, 0.6f, 0.6f, 1.62f, "minecraft:zombie_pigman"),
ZOMBIFIED_PIGLIN(ZombifiedPiglinEntity.class, 36, 1.95f, 0.6f, 0.6f, 1.62f, "minecraft:zombie_pigman"),
SLIME(SlimeEntity.class, 37, 0.51f),
ENDERMAN(EndermanEntity.class, 38, 2.9f, 0.6f),
SILVERFISH(MonsterEntity.class, 39, 0.3f, 0.4f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,27 @@ public static byte[] toBedrockBiome(int[] biomeData) {
return bedrockData;
}

for (int z = 0; z < 16; z += 4) {
for (int x = 0; x < 16; x += 4) {
byte biomeId = biomeID(biomeData, x, z);
fillArray(z, x, bedrockData, biomeId);
fillArray(z + 1, x, bedrockData, biomeId);
fillArray(z + 2, x, bedrockData, biomeId);
fillArray(z + 3, x, bedrockData, biomeId);
for (int y = 0; y < 16; y += 4) {
for (int z = 0; z < 16; z += 4) {
for (int x = 0; x < 16; x += 4) {
byte biomeId = biomeID(biomeData, x, y, z);
int offset = ((z + (y / 4)) << 4) | x;
Arrays.fill(bedrockData, offset, offset + 4, biomeId);
}
}
}
return bedrockData;
}

private static void fillArray(int z, int x, byte[] legacyBiomeData, int biomeId) {
int offset = (z << 4) | x;
Arrays.fill(legacyBiomeData, offset, offset + 4, (byte) biomeId);
}

private static byte biomeID(int[] biomeData, int x, int z) {
return (byte) biomeData[((z >> 2) & 3) << 2 | ((x >> 2) & 3)];
private static byte biomeID(int[] biomeData, int x, int y, int z) {
int biomeId = biomeData[((y >> 2) & 63) << 4 | ((z >> 2) & 3) << 2 | ((x >> 2) & 3)];
if (biomeId == 0) {
biomeId = 42; // Ocean
} else if (biomeId >= 40 && biomeId <= 43) { // Java has multiple End dimensions that Bedrock doesn't recognize
biomeId = 9;
} else if (biomeId >= 170) { // Nether biomes. Dunno why it's like this :microjang:
biomeId = biomeId + 8;
}
return (byte) biomeId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ public static ItemEntry getItem(ItemData data) {
}
}

GeyserConnector.getInstance().getLogger().debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
// This will hide the message when the player clicks with an empty hand
if (data.getId() != 0 && data.getDamage() != 0) {
GeyserConnector.getInstance().getLogger().debug("Missing mapping for bedrock item " + data.getId() + ":" + data.getDamage());
}
return ItemEntry.AIR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) {
itemTag.put(new ListTag("Enchantments", enchantments));
}
if (!storedEnchantments.isEmpty()) {
itemTag.put(new ListTag("StoredEnchantments", enchantments));
itemTag.put(new ListTag("StoredEnchantments", storedEnchantments));
}
itemTag.remove("ench");
}


private CompoundTag remapEnchantment(CompoundTag tag) {
Tag javaEnchLvl = tag.get("lvl");
if (!(javaEnchLvl instanceof ShortTag))
if (!(javaEnchLvl instanceof ShortTag || javaEnchLvl instanceof IntTag))
return null;

Tag javaEnchId = tag.get("id");
Expand All @@ -137,7 +137,7 @@ private CompoundTag remapEnchantment(CompoundTag tag) {

CompoundTag bedrockTag = new CompoundTag("");
bedrockTag.put(new ShortTag("id", (short) enchantment.ordinal()));
bedrockTag.put(new ShortTag("lvl", ((ShortTag) javaEnchLvl).getValue()));
bedrockTag.put(new ShortTag("lvl", ((Number) javaEnchLvl.getValue()).shortValue()));
return bedrockTag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@

package org.geysermc.connector.network.translators.java;

import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.DimensionUtils;

import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;

import java.util.concurrent.ThreadLocalRandom;

@Translator(packet = ServerRespawnPacket.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,14 @@ private void updateOffset(Entity passenger, EntityType mountType, GeyserSession
case ARMOR_STAND:
yOffset = 1.3f;
break;
case STRIDER:
yOffset = 2.8200102f;
break;
}
Vector3f offset = Vector3f.from(0f, yOffset, 0f);
if (mountType == EntityType.STRIDER) {
offset = offset.add(0f, 0f, -0.2f);
}
// Without the X offset, more than one entity on a boat is stacked on top of each other
if (rider && moreThanOneEntity) {
offset = offset.add(Vector3f.from(0.2, 0, 0));
Expand Down
Loading

0 comments on commit 075cb1d

Please sign in to comment.