Skip to content

Commit

Permalink
Implement glow item frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 3, 2021
1 parent 5b7aa57 commit 1fe179c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<dependency>
<groupId>com.github.GeyserMC</groupId>
<artifactId>MCProtocolLib</artifactId>
<version>5f523d3</version>
<version>eb02688</version>
<!-- <groupId>com.github.steveice10</groupId>-->
<!-- <artifactId>mcprotocollib</artifactId>-->
<!-- <version>1.17-pre5-SNAPSHOT</version>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ItemFrameEntity(long entityId, long geyserId, EntityType entityType, Vect
@Override
public void spawnEntity(GeyserSession session) {
NbtMapBuilder blockBuilder = NbtMap.builder()
.putString("name", "minecraft:frame")
.putString("name", this.entityType == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_frame" : "minecraft:frame")
.putInt("version", session.getBlockTranslator().getBlockStateVersion());
blockBuilder.put("states", NbtMap.builder()
.putInt("facing_direction", direction.ordinal())
Expand Down Expand Up @@ -167,7 +167,7 @@ private NbtMap getDefaultTag() {
builder.putInt("y", bedrockPosition.getY());
builder.putInt("z", bedrockPosition.getZ());
builder.putByte("isMovable", (byte) 1);
builder.putString("id", "ItemFrame");
builder.putString("id", this.entityType == EntityType.GLOW_ITEM_FRAME ? "GlowItemFrame" : "ItemFrame");
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ public enum EntityType {
ZOGLIN(ZoglinEntity.class, 126, 1.4f, 1.3965f, 1.3965f, 0f, "minecraft:zoglin"),
PIGLIN(PiglinEntity.class, 123, 1.95f, 0.6f, 0.6f, 0f, "minecraft:piglin"),
PIGLIN_BRUTE(BasePiglinEntity.class, 127, 1.95f, 0.6f, 0.6f, 0f, "minecraft:piglin_brute"),
//TODO: AXOLOTL GLOW_ITEM_FRAME
AXOLOTL(AxolotlEntity.class, 0, 0.42f, 0.7f, 0.7f, 0f, "minecraft:axolotl"),
GLOW_SQUID(GlowSquidEntity.class, 0, 0.8f, 0.8f, 0.8f, 0f, "minecraft:glow_squid"),
GOAT(GoatEntity.class, 0, 1.3f, 0.9f, 0.9f, 0f, "minecraft:goat"),
Expand All @@ -171,6 +170,7 @@ public enum EntityType {
* Item frames are handled differently since they are a block in Bedrock.
*/
ITEM_FRAME(ItemFrameEntity.class, 0, 0, 0),
GLOW_ITEM_FRAME(ItemFrameEntity.class, 0, 0, 0),

/**
* Not an entity in Bedrock, so we replace it with an evoker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.BlockPickRequestPacket;
import org.geysermc.connector.entity.ItemFrameEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
Expand All @@ -53,7 +54,7 @@ public void translate(BlockPickRequestPacket packet, GeyserSession session) {
InventoryUtils.findOrCreateItem(session, entity.getHeldItem());
} else {
// Grab the frame as the item
InventoryUtils.findOrCreateItem(session, "minecraft:item_frame");
InventoryUtils.findOrCreateItem(session, entity.getEntityType() == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_item_frame" : "minecraft:item_frame");
}
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void translate(EntityPickRequestPacket packet, GeyserSession session) {
case ARMOR_STAND:
case END_CRYSTAL:
//case ITEM_FRAME: Not an entity in Bedrock Edition
//case GLOW_ITEM_FRAME:
case MINECART:
case PAINTING:
// No spawn egg, just an item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void translate(ServerSpawnEntityPacket packet, GeyserSession session) {
if (packet.getType() == EntityType.FALLING_BLOCK) {
entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, ((FallingBlockData) packet.getData()).getId());
} else if (packet.getType() == EntityType.ITEM_FRAME) {
} else if (packet.getType() == EntityType.ITEM_FRAME || packet.getType() == EntityType.GLOW_ITEM_FRAME) {
// Item frames need the hanging direction
entity = new ItemFrameEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation, (HangingDirection) packet.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ public BlockTranslator(String paletteFile) {

// Loop around again to find all item frame runtime IDs
for (Object2IntMap.Entry<NbtMap> entry : blockStateOrderedMap.object2IntEntrySet()) {
if (entry.getKey().getString("name").equals("minecraft:frame")) {
String name = entry.getKey().getString("name");
if (name.equals("minecraft:frame") || name.equals("minecraft:glow_frame")) {
itemFrames.put(entry.getKey(), entry.getIntValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ public static void updateBlock(GeyserSession session, int blockState, Vector3i p
if (itemFrameEntity != null) {
if (blockState == JAVA_AIR_ID) { // Item frame is still present and no block overrides that; refresh it
itemFrameEntity.updateBlock(session);
// Still update the chunk cache with the new block
session.getChunkCache().updateBlock(position.getX(), position.getY(), position.getZ(), blockState);
return;
}
// Otherwise, let's still store our reference to the item frame, but let the new block take precedence for now
Expand Down

0 comments on commit 1fe179c

Please sign in to comment.