Geyser/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/BedrockOnlyBlockEntity.java

81 lines
3.4 KiB
Java
Raw Normal View History

/*
2022-01-01 19:03:05 +00:00
* Copyright (c) 2019-2022 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.geyser.translator.level.block.entity;
2022-10-30 00:23:21 +00:00
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtType;
import org.geysermc.geyser.level.block.BlockStateValues;
2021-11-22 19:52:26 +00:00
import org.geysermc.geyser.session.GeyserSession;
/**
* Implemented only if a block is a block entity in Bedrock and not Java Edition.
*/
public interface BedrockOnlyBlockEntity extends RequiresBlockState {
/**
* Determines if block is part of class
* @param blockState BlockState to be compared
* @return true if part of the class
*/
boolean isBlock(int blockState);
/**
* Update the block on Bedrock Edition.
2021-11-22 19:52:26 +00:00
* @param session GeyserConnection.
* @param blockState The Java block state.
* @param position The Bedrock block position.
*/
2021-11-22 19:52:26 +00:00
void updateBlock(GeyserSession session, int blockState, Vector3i position);
/**
* Get the tag of the Bedrock-only block entity
* @param position Bedrock position of block.
* @param blockState Java BlockState of block.
* @return Bedrock tag, or null if not a Bedrock-only Block Entity
*/
2021-11-22 19:52:26 +00:00
static NbtMap getTag(GeyserSession session, Vector3i position, int blockState) {
if (FlowerPotBlockEntityTranslator.isFlowerBlock(blockState)) {
return FlowerPotBlockEntityTranslator.getTag(session, blockState, position);
} else if (PistonBlockEntityTranslator.isBlock(blockState)) {
return PistonBlockEntityTranslator.getTag(blockState, position);
Fix some item interactions (#3083) * Remove Bedrock only banner patterns from the creative inventory * Add sound for tadpole bucket * Fix lily pad and frogspawn placing on mobile/single stacks * Workaround? Fix? for bucket usage on mobile * Simplify math and update position+rotation whenever ServerboundUseItemPacket is sent * Rotate the player back after using an item and fix glass bottles * ITEM_USE actionType 1 does not need the rotation fix Increase delay for look back * Add some checks * Prevent buckets and spawn eggs from being unintentionally placed when interacting with special blocks As of 1.19 Bedrock no longer sends a PlayerActionPacket with action=BLOCK_INTERACT. Bedrock now sends action=ITEM_USE_ON_START before and action=ITEM_USE_ON_STOP after using an item on a block. However, this is not useful as it is sent for all block interactions. * Fix inventory transactions being rejected after restoreCorrectBlock The held item's netId is always 0 in the InventoryTransactionPacket. * Touch ups * Fix lookAt for different poses and sneaking + cauldron + bucket interactions Fix boat items being desynced when placing them very close to collision Fix bottles being desynced when tapping above water Resend the held item if we do encounter a desync * Avoid getting blockstate twice and fix comment * Use generated interaction data * Fix glass bottles being double filled and phantom water bottles/water buckets * Don't update the entire inventory on useItem * Use Geyser's inventory copy for check * Use ItemTranslator#getBedrockItemMapping to avoid NBT translation * mappings Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com>
2022-06-24 20:48:28 +00:00
} else if (BlockStateValues.isNonWaterCauldron(blockState)) {
// As of 1.18.30: this is required to make rendering not look weird on chunk load (lava and snow cauldrons look dim)
return NbtMap.builder()
.putString("id", "Cauldron")
.putByte("isMovable", (byte) 0)
.putShort("PotionId", (short) -1)
.putShort("PotionType", (short) -1)
.putList("Items", NbtType.END, NbtList.EMPTY)
.putInt("x", position.getX())
.putInt("y", position.getY())
.putInt("z", position.getZ())
.build();
}
return null;
}
}