Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser into floo…
Browse files Browse the repository at this point in the history
…dgate-2.0
  • Loading branch information
Camotoy committed May 9, 2021
2 parents 3b9674a + 0691bb6 commit 41e0ad3
Show file tree
Hide file tree
Showing 44 changed files with 485 additions and 168 deletions.
2 changes: 1 addition & 1 deletion connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
<artifactId>bedrock-v431</artifactId>
<version>f8ecf54</version>
<version>9947665</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import lombok.Getter;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;
Expand Down Expand Up @@ -69,6 +70,11 @@ public class ItemFrameEntity extends Entity {
* Cached item frame's Bedrock compound tag.
*/
private NbtMap cachedTag;
/**
* The item currently in the item frame. Used for block picking.
*/
@Getter
private ItemStack heldItem = null;

public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, HangingDirection direction) {
super(entityId, geyserId, entityType, position, motion, rotation);
Expand All @@ -87,7 +93,8 @@ public void spawnEntity(GeyserSession session) {
bedrockRuntimeId = session.getBlockTranslator().getItemFrame(blockBuilder.build());
bedrockPosition = Vector3i.from(position.getFloorX(), position.getFloorY(), position.getFloorZ());

session.getItemFrameCache().put(bedrockPosition, entityId);
session.getItemFrameCache().put(bedrockPosition, this);

// Delay is required, or else loading in frames on chunk load is sketchy at best
session.getConnector().getGeneralThreadPool().schedule(() -> {
updateBlock(session);
Expand All @@ -99,13 +106,14 @@ public void spawnEntity(GeyserSession session) {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 7 && entityMetadata.getValue() != null) {
ItemData itemData = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
this.heldItem = (ItemStack) entityMetadata.getValue();
ItemData itemData = ItemTranslator.translateToBedrock(session, heldItem);
ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue());
NbtMapBuilder builder = NbtMap.builder();

builder.putByte("Count", (byte) itemData.getCount());
if (itemData.getTag() != null) {
builder.put("tag", itemData.getTag().toBuilder().build());
builder.put("tag", itemData.getTag());
}
builder.putShort("Damage", (short) itemData.getDamage());
builder.putString("Name", itemEntry.getBedrockIdentifier());
Expand Down Expand Up @@ -146,7 +154,9 @@ public boolean despawnEntity(GeyserSession session) {
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NETWORK);
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.sendUpstreamPacket(updateBlockPacket);
session.getItemFrameCache().remove(position, entityId);

session.getItemFrameCache().remove(bedrockPosition, this);

valid = false;
return true;
}
Expand Down Expand Up @@ -192,16 +202,7 @@ public void updateBlock(GeyserSession session) {
* @param session GeyserSession.
* @return Java entity ID or -1 if not found.
*/
public static long getItemFrameEntityId(GeyserSession session, Vector3i position) {
return session.getItemFrameCache().getOrDefault(position, -1);
}

/**
* Force-remove from the position-to-ID map so it doesn't cause conflicts.
* @param session GeyserSession.
* @param position position of the removed item frame.
*/
public static void removePosition(GeyserSession session, Vector3i position) {
session.getItemFrameCache().remove(position);
public static ItemFrameEntity getItemFrameEntity(GeyserSession session, Vector3i position) {
return session.getItemFrameCache().get(position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), rotation, isOnGround, teleported);
}

@Override
public Vector3f getBedrockRotation() {
// Note: minecart rotation on rails does not care about the actual rotation value
return Vector3f.from(0, rotation.getX(), 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.living.AgeableEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class AnimalEntity extends AgeableEntity {

Expand All @@ -40,7 +42,7 @@ public AnimalEntity(long entityId, long geyserId, EntityType entityType, Vector3
* <code>wheat</code>.
* @return true if this is a valid item to breed with for this animal.
*/
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
// This is what it defaults to. OK.
return javaIdentifierStripped.equals("wheat");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,16 @@
package org.geysermc.connector.entity.living.animal;

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.google.common.collect.ImmutableSet;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

import java.util.Set;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class BeeEntity extends AnimalEntity {
/**
* A list of all flowers. Used for feeding bees.
*/
private static final Set<String> FLOWERS = ImmutableSet.of("dandelion", "poppy", "blue_orchid", "allium", "azure_bluet",
"red_tulip", "pink_tulip", "white_tulip", "orange_tulip", "cornflower", "lily_of_the_valley", "wither_rose",
"sunflower", "lilac", "rose_bush", "peony");

public BeeEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
Expand Down Expand Up @@ -74,7 +66,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
return FLOWERS.contains(javaIdentifierStripped);
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return session.getTagCache().isFlower(itemEntry);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import com.nukkitx.math.vector.Vector3f;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class ChickenEntity extends AnimalEntity {

Expand All @@ -35,7 +37,7 @@ public ChickenEntity(long entityId, long geyserId, EntityType entityType, Vector
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.contains("seeds");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class FoxEntity extends AnimalEntity {

Expand All @@ -54,7 +55,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("sweet_berries");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.utils.DimensionUtils;

public class HoglinEntity extends AnimalEntity {
Expand All @@ -49,7 +50,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("crimson_fungus");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class OcelotEntity extends AnimalEntity {

Expand All @@ -46,7 +47,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("cod") || javaIdentifierStripped.equals("salmon");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry;

public class PandaEntity extends AnimalEntity {
Expand Down Expand Up @@ -80,7 +81,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("bamboo");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class PigEntity extends AnimalEntity {

Expand All @@ -47,7 +48,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("carrot") || javaIdentifierStripped.equals("potato") || javaIdentifierStripped.equals("beetroot");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class PolarBearEntity extends AnimalEntity {

Expand All @@ -46,7 +47,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class RabbitEntity extends AnimalEntity {

Expand Down Expand Up @@ -61,7 +62,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("dandelion") || javaIdentifierStripped.equals("carrot") || javaIdentifierStripped.equals("golden_carrot");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class StriderEntity extends AnimalEntity {

Expand Down Expand Up @@ -87,7 +88,7 @@ public void updateBedrockMetadata(GeyserSession session) {
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("warped_fungus");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class TurtleEntity extends AnimalEntity {

Expand All @@ -48,7 +49,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("seagrass");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry;

import java.util.Set;
Expand Down Expand Up @@ -112,7 +113,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return DONKEY_AND_HORSE_FOODS.contains(javaIdentifierStripped);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry;

public class LlamaEntity extends ChestedHorseEntity {
Expand Down Expand Up @@ -77,7 +78,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("wheat") || javaIdentifierStripped.equals("hay_block");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemEntry;

public class CatEntity extends TameableEntity {

Expand Down Expand Up @@ -85,7 +86,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.equals("cod") || javaIdentifierStripped.equals("salmon");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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.item.ItemEntry;

public class ParrotEntity extends TameableEntity {

Expand All @@ -47,7 +48,7 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
}

@Override
public boolean canEat(String javaIdentifierStripped) {
public boolean canEat(GeyserSession session, String javaIdentifierStripped, ItemEntry itemEntry) {
return javaIdentifierStripped.contains("seeds") || javaIdentifierStripped.equals("cookie");
}
}
Loading

0 comments on commit 41e0ad3

Please sign in to comment.