Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Fix shulker boxes resetting data and set all shulker boxes as valid
Dieser Commit ist enthalten in:
Ursprung
e1db626529
Commit
acbcf4baf3
@ -82,7 +82,7 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||||||
// We can safely use this block
|
// We can safely use this block
|
||||||
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
|
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
|
||||||
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
|
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
|
||||||
setCustomName(session, session.getLastInteractionBlockPosition(), inventory);
|
setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||||||
session.sendUpstreamPacket(blockPacket);
|
session.sendUpstreamPacket(blockPacket);
|
||||||
inventory.setHolderPosition(position);
|
inventory.setHolderPosition(position);
|
||||||
|
|
||||||
setCustomName(session, position, inventory);
|
setCustomName(session, position, inventory, defaultJavaBlockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +108,7 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||||||
return this.validBlocks.contains(javaBlockString[0]);
|
return this.validBlocks.contains(javaBlockString[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setCustomName(GeyserSession session, Vector3i position, Inventory inventory) {
|
protected void setCustomName(GeyserSession session, Vector3i position, Inventory inventory, int javaBlockState) {
|
||||||
NbtMap tag = NbtMap.builder()
|
NbtMap tag = NbtMap.builder()
|
||||||
.putInt("x", position.getX())
|
.putInt("x", position.getX())
|
||||||
.putInt("y", position.getY())
|
.putInt("y", position.getY())
|
||||||
|
@ -53,6 +53,17 @@ public abstract class AbstractBlockInventoryTranslator extends BaseInventoryTran
|
|||||||
this.updater = updater;
|
this.updater = updater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param size the amount of slots that the inventory adds alongside the base inventory slots
|
||||||
|
* @param holder the custom block holder
|
||||||
|
* @param updater updater
|
||||||
|
*/
|
||||||
|
public AbstractBlockInventoryTranslator(int size, InventoryHolder holder, InventoryUpdater updater) {
|
||||||
|
super(size);
|
||||||
|
this.holder = holder;
|
||||||
|
this.updater = updater;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||||
holder.prepareInventory(this, session, inventory);
|
holder.prepareInventory(this, session, inventory);
|
||||||
|
@ -25,14 +25,45 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.inventory.translators;
|
package org.geysermc.connector.network.translators.inventory.translators;
|
||||||
|
|
||||||
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import com.nukkitx.nbt.NbtMap;
|
||||||
|
import com.nukkitx.nbt.NbtMapBuilder;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerSlotType;
|
||||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||||
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
import org.geysermc.connector.network.translators.inventory.BedrockContainerSlot;
|
||||||
|
import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder;
|
||||||
import org.geysermc.connector.network.translators.inventory.updater.ContainerInventoryUpdater;
|
import org.geysermc.connector.network.translators.inventory.updater.ContainerInventoryUpdater;
|
||||||
|
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
|
||||||
|
|
||||||
public class ShulkerInventoryTranslator extends AbstractBlockInventoryTranslator {
|
public class ShulkerInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||||
public ShulkerInventoryTranslator() {
|
public ShulkerInventoryTranslator() {
|
||||||
super(27, "minecraft:shulker_box[facing=north]", ContainerType.CONTAINER, ContainerInventoryUpdater.INSTANCE);
|
super(27, new BlockInventoryHolder("minecraft:shulker_box[facing=north]", ContainerType.CONTAINER) {
|
||||||
|
private final BlockEntityTranslator shulkerBoxTranslator = BlockEntityTranslator.BLOCK_ENTITY_TRANSLATORS.get("ShulkerBox");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidBlock(String[] javaBlockString) {
|
||||||
|
return javaBlockString[0].contains("shulker_box");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setCustomName(GeyserSession session, Vector3i position, Inventory inventory, int javaBlockState) {
|
||||||
|
NbtMapBuilder tag = NbtMap.builder()
|
||||||
|
.putInt("x", position.getX())
|
||||||
|
.putInt("y", position.getY())
|
||||||
|
.putInt("z", position.getZ())
|
||||||
|
.putString("CustomName", inventory.getTitle());
|
||||||
|
// Don't reset facing property
|
||||||
|
shulkerBoxTranslator.translateTag(tag, null, javaBlockState);
|
||||||
|
|
||||||
|
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
|
||||||
|
dataPacket.setData(tag.build());
|
||||||
|
dataPacket.setBlockPosition(position);
|
||||||
|
session.sendUpstreamPacket(dataPacket);
|
||||||
|
}
|
||||||
|
}, ContainerInventoryUpdater.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,10 +29,16 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||||||
import com.nukkitx.nbt.NbtMapBuilder;
|
import com.nukkitx.nbt.NbtMapBuilder;
|
||||||
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@BlockEntity(name = "ShulkerBox")
|
@BlockEntity(name = "ShulkerBox")
|
||||||
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
|
public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator {
|
||||||
|
/**
|
||||||
|
* Also used in {@link org.geysermc.connector.network.translators.inventory.translators.ShulkerInventoryTranslator}
|
||||||
|
* where {@code tag} is passed as null.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) {
|
public void translateTag(NbtMapBuilder builder, @Nullable CompoundTag tag, int blockState) {
|
||||||
byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
|
byte direction = BlockStateValues.getShulkerBoxDirection(blockState);
|
||||||
// Just in case...
|
// Just in case...
|
||||||
if (direction == -1) {
|
if (direction == -1) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren