mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Use integrated world managers for decorated pot animation
This commit is contained in:
parent
6884a0f7db
commit
2c47330509
4 changed files with 75 additions and 0 deletions
|
@ -43,9 +43,11 @@ import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemCodecHel
|
|||
import org.geysermc.mcprotocollib.protocol.data.game.setting.Difficulty;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
|
@ -209,6 +211,13 @@ public abstract class WorldManager {
|
|||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves decorated pot sherds from the server. Used to ensure the data is not erased on animation sent
|
||||
* through the BlockEntityDataPacket.
|
||||
*/
|
||||
public void getDecoratedPotData(GeyserSession session, Vector3i pos, Consumer<List<String>> apply) {
|
||||
}
|
||||
|
||||
protected static final Function<Int2ObjectMap<byte[]>, DataComponents> RAW_TRANSFORMER = map -> {
|
||||
try {
|
||||
Map<DataComponentType<?>, DataComponent<?, ?>> components = new HashMap<>();
|
||||
|
|
|
@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.protocol.java.level;
|
|||
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||
import org.cloudburstmc.nbt.NbtType;
|
||||
import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket;
|
||||
import org.geysermc.geyser.api.util.PlatformType;
|
||||
|
@ -126,6 +127,26 @@ public class JavaBlockEventTranslator extends PacketTranslator<ClientboundBlockE
|
|||
|
||||
blockEntityPacket.setData(builder.build());
|
||||
session.sendUpstreamPacket(blockEntityPacket);
|
||||
} else if (value instanceof DecoratedPotValue potValue) {
|
||||
// Decorated pots - wobble wobble
|
||||
// We need to send the sherd data with the client, but we don't really care about latency here so we
|
||||
// can safely get this from the server
|
||||
session.getGeyser().getWorldManager().getDecoratedPotData(session, position, sherds -> {
|
||||
BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket();
|
||||
blockEntityPacket.setBlockPosition(position);
|
||||
|
||||
NbtMapBuilder builder = BlockEntityTranslator.getConstantBedrockTag("DecoratedPot", position);
|
||||
builder.putList("sherds", NbtType.STRING, sherds);
|
||||
builder.putByte("animation", switch (potValue.getWobbleStyle()) {
|
||||
case POSITIVE -> (byte) 2;
|
||||
case NEGATIVE -> (byte) 1;
|
||||
});
|
||||
|
||||
blockEntityPacket.setData(builder.build());
|
||||
session.sendUpstreamPacket(blockEntityPacket);
|
||||
});
|
||||
} else if (session.getGeyser().getLogger().isDebug()) {
|
||||
session.getGeyser().getLogger().debug("Unhandled block event packet: " + packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue