Skip to content

Commit 1c1684c

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents bbd3d25 + 861ee61 commit 1c1684c

File tree

10 files changed

+131
-48
lines changed

10 files changed

+131
-48
lines changed

core/src/main/java/org/geysermc/geyser/level/block/Blocks.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public final class Blocks {
630630
public static final Block REDSTONE_WALL_TORCH = register(new Block("redstone_wall_torch", builder().pushReaction(PistonBehavior.DESTROY)
631631
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
632632
.booleanState(LIT)));
633-
public static final Block STONE_BUTTON = register(new Block("stone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
633+
public static final Block STONE_BUTTON = register(new ButtonBlock("stone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
634634
.enumState(ATTACH_FACE)
635635
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
636636
.booleanState(POWERED)));
@@ -997,43 +997,43 @@ public final class Blocks {
997997
.intState(AGE_7)));
998998
public static final Block POTATOES = register(new Block("potatoes", builder().pushReaction(PistonBehavior.DESTROY)
999999
.intState(AGE_7)));
1000-
public static final Block OAK_BUTTON = register(new Block("oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1000+
public static final Block OAK_BUTTON = register(new ButtonBlock("oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10011001
.enumState(ATTACH_FACE)
10021002
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10031003
.booleanState(POWERED)));
1004-
public static final Block SPRUCE_BUTTON = register(new Block("spruce_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1004+
public static final Block SPRUCE_BUTTON = register(new ButtonBlock("spruce_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10051005
.enumState(ATTACH_FACE)
10061006
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10071007
.booleanState(POWERED)));
1008-
public static final Block BIRCH_BUTTON = register(new Block("birch_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1008+
public static final Block BIRCH_BUTTON = register(new ButtonBlock("birch_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10091009
.enumState(ATTACH_FACE)
10101010
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10111011
.booleanState(POWERED)));
1012-
public static final Block JUNGLE_BUTTON = register(new Block("jungle_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1012+
public static final Block JUNGLE_BUTTON = register(new ButtonBlock("jungle_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10131013
.enumState(ATTACH_FACE)
10141014
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10151015
.booleanState(POWERED)));
1016-
public static final Block ACACIA_BUTTON = register(new Block("acacia_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1016+
public static final Block ACACIA_BUTTON = register(new ButtonBlock("acacia_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10171017
.enumState(ATTACH_FACE)
10181018
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10191019
.booleanState(POWERED)));
1020-
public static final Block CHERRY_BUTTON = register(new Block("cherry_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1020+
public static final Block CHERRY_BUTTON = register(new ButtonBlock("cherry_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10211021
.enumState(ATTACH_FACE)
10221022
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10231023
.booleanState(POWERED)));
1024-
public static final Block DARK_OAK_BUTTON = register(new Block("dark_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1024+
public static final Block DARK_OAK_BUTTON = register(new ButtonBlock("dark_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10251025
.enumState(ATTACH_FACE)
10261026
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10271027
.booleanState(POWERED)));
1028-
public static final Block PALE_OAK_BUTTON = register(new Block("pale_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1028+
public static final Block PALE_OAK_BUTTON = register(new ButtonBlock("pale_oak_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10291029
.enumState(ATTACH_FACE)
10301030
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10311031
.booleanState(POWERED)));
1032-
public static final Block MANGROVE_BUTTON = register(new Block("mangrove_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1032+
public static final Block MANGROVE_BUTTON = register(new ButtonBlock("mangrove_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10331033
.enumState(ATTACH_FACE)
10341034
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10351035
.booleanState(POWERED)));
1036-
public static final Block BAMBOO_BUTTON = register(new Block("bamboo_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
1036+
public static final Block BAMBOO_BUTTON = register(new ButtonBlock("bamboo_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
10371037
.enumState(ATTACH_FACE)
10381038
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
10391039
.booleanState(POWERED)));
@@ -2232,11 +2232,11 @@ public final class Blocks {
22322232
.enumState(HALF)
22332233
.enumState(STAIRS_SHAPE)
22342234
.booleanState(WATERLOGGED)));
2235-
public static final Block CRIMSON_BUTTON = register(new Block("crimson_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
2235+
public static final Block CRIMSON_BUTTON = register(new ButtonBlock("crimson_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
22362236
.enumState(ATTACH_FACE)
22372237
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
22382238
.booleanState(POWERED)));
2239-
public static final Block WARPED_BUTTON = register(new Block("warped_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
2239+
public static final Block WARPED_BUTTON = register(new ButtonBlock("warped_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
22402240
.enumState(ATTACH_FACE)
22412241
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
22422242
.booleanState(POWERED)));
@@ -2336,7 +2336,7 @@ public final class Blocks {
23362336
.booleanState(WATERLOGGED)));
23372337
public static final Block POLISHED_BLACKSTONE_PRESSURE_PLATE = register(new Block("polished_blackstone_pressure_plate", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
23382338
.booleanState(POWERED)));
2339-
public static final Block POLISHED_BLACKSTONE_BUTTON = register(new Block("polished_blackstone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
2339+
public static final Block POLISHED_BLACKSTONE_BUTTON = register(new ButtonBlock("polished_blackstone_button", builder().destroyTime(0.5f).pushReaction(PistonBehavior.DESTROY)
23402340
.enumState(ATTACH_FACE)
23412341
.enumState(HORIZONTAL_FACING, Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST)
23422342
.booleanState(POWERED)));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2025 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.level.block.type;
27+
28+
public class ButtonBlock extends Block {
29+
public ButtonBlock(String javaIdentifier, Builder builder) {
30+
super(javaIdentifier, builder);
31+
}
32+
}

core/src/main/java/org/geysermc/geyser/registry/loader/SoundRegistryLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.geysermc.geyser.registry.loader;
2727

2828
import com.fasterxml.jackson.databind.JsonNode;
29+
import com.fasterxml.jackson.databind.ObjectMapper;
2930
import org.geysermc.geyser.GeyserImpl;
3031
import org.geysermc.geyser.registry.type.SoundMapping;
3132

@@ -39,7 +40,6 @@
3940
* Loads sounds from the given input.
4041
*/
4142
public class SoundRegistryLoader implements RegistryLoader<String, Map<String, SoundMapping>> {
42-
4343
@Override
4444
public Map<String, SoundMapping> load(String input) {
4545
JsonNode soundsTree;
@@ -51,7 +51,7 @@ public Map<String, SoundMapping> load(String input) {
5151

5252
Map<String, SoundMapping> soundMappings = new HashMap<>();
5353
Iterator<Map.Entry<String, JsonNode>> soundsIterator = soundsTree.fields();
54-
while(soundsIterator.hasNext()) {
54+
while (soundsIterator.hasNext()) {
5555
Map.Entry<String, JsonNode> next = soundsIterator.next();
5656
JsonNode brMap = next.getValue();
5757
String javaSound = next.getKey();
@@ -61,7 +61,8 @@ public Map<String, SoundMapping> load(String input) {
6161
brMap.has("playsound_mapping") && brMap.get("playsound_mapping").isTextual() ? brMap.get("playsound_mapping").asText() : null,
6262
brMap.has("extra_data") && brMap.get("extra_data").isInt() ? brMap.get("extra_data").asInt() : -1,
6363
brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null,
64-
brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean()
64+
brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean(),
65+
brMap.has("pitch_adjust") && brMap.get("pitch_adjust").isNumber() ? brMap.get("pitch_adjust").floatValue() : 1.0f
6566
)
6667
);
6768
}

core/src/main/java/org/geysermc/geyser/registry/type/SoundMapping.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,15 @@
2525

2626
package org.geysermc.geyser.registry.type;
2727

28-
import lombok.Value;
29-
30-
@Value
31-
public class SoundMapping {
32-
String java;
33-
String bedrock;
34-
String playsound;
35-
int extraData;
36-
String identifier;
37-
boolean levelEvent;
38-
39-
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier, boolean levelEvent) {
28+
public record SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier,
29+
boolean levelEvent, float pitchAdjust) {
30+
public SoundMapping(String java, String bedrock, String playsound, int extraData, String identifier, boolean levelEvent, float pitchAdjust) {
4031
this.java = java;
4132
this.bedrock = bedrock == null || bedrock.isEmpty() ? null : bedrock;
4233
this.playsound = playsound == null || playsound.isEmpty() ? null : playsound;
4334
this.extraData = extraData;
4435
this.identifier = identifier == null || identifier.isEmpty() ? ":" : identifier;
4536
this.levelEvent = levelEvent;
37+
this.pitchAdjust = pitchAdjust;
4638
}
4739
}

core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.geysermc.geyser.level.block.property.Properties;
6363
import org.geysermc.geyser.level.block.type.Block;
6464
import org.geysermc.geyser.level.block.type.BlockState;
65+
import org.geysermc.geyser.level.block.type.ButtonBlock;
6566
import org.geysermc.geyser.level.block.type.CauldronBlock;
6667
import org.geysermc.geyser.level.block.type.SkullBlock;
6768
import org.geysermc.geyser.registry.BlockRegistries;
@@ -279,8 +280,14 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
279280
Block place checks end - client is good to go
280281
*/
281282

283+
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
284+
285+
// Buttons on Java Edition cannot be interacted with when they are powered
286+
if (blockState.block() instanceof ButtonBlock && blockState.getValue(Properties.POWERED)) {
287+
return;
288+
}
289+
282290
if (packet.getItemInHand() != null && session.getItemMappings().getMapping(packet.getItemInHand()).getJavaItem() instanceof SpawnEggItem) {
283-
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
284291
if (blockState.is(Blocks.WATER) && blockState.getValue(Properties.LEVEL) == 0) {
285292
// Otherwise causes multiple mobs to spawn - just send a use item packet
286293
useItem(session, packet, blockState.javaId());
@@ -304,7 +311,6 @@ public void translate(GeyserSession session, InventoryTransactionPacket packet)
304311
Item item = session.getPlayerInventory().getItemInHand().asItem();
305312
if (packet.getItemInHand() != null) {
306313
ItemDefinition definition = packet.getItemInHand().getDefinition();
307-
BlockState blockState = session.getGeyser().getWorldManager().blockAt(session, packet.getBlockPosition());
308314
// Otherwise boats will not be able to be placed in survival and buckets, lily pads, frogspawn, and glass bottles won't work on mobile
309315
if (item instanceof BoatItem || item == Items.LILY_PAD || item == Items.FROGSPAWN) {
310316
useItem(session, packet, blockState.javaId());

core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/input/BedrockBlockActions.java

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ private static void handle(GeyserSession session, PlayerBlockActionData blockAct
7070
PlayerActionType action = blockActionData.getAction();
7171
Vector3i vector = blockActionData.getBlockPosition();
7272
int blockFace = blockActionData.getFace();
73-
7473
switch (action) {
7574
case DROP_ITEM -> {
7675
ServerboundPlayerActionPacket dropItemPacket = new ServerboundPlayerActionPacket(PlayerAction.DROP_ITEM,

core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelEventTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void translate(GeyserSession session, ClientboundLevelEventPacket packet)
9090
SoundMapping mapping = Registries.SOUNDS.get(jukeboxSong.soundEvent().replace("minecraft:", ""));
9191
SoundEvent soundEvent = null;
9292
if (mapping != null) {
93-
String bedrock = mapping.getBedrock();
93+
String bedrock = mapping.bedrock();
9494
if (bedrock != null && !bedrock.isEmpty()) {
9595
soundEvent = SoundUtils.toSoundEvent(bedrock);
9696
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.translator.sound.block;
27+
28+
import org.cloudburstmc.math.vector.Vector3f;
29+
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
30+
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
31+
import org.geysermc.geyser.GeyserImpl;
32+
import org.geysermc.geyser.level.block.property.Properties;
33+
import org.geysermc.geyser.level.block.type.BlockState;
34+
import org.geysermc.geyser.session.GeyserSession;
35+
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
36+
import org.geysermc.geyser.translator.sound.SoundTranslator;
37+
38+
@SoundTranslator(blocks = "button")
39+
public class ButtonSoundInteractionTranslator implements BlockSoundInteractionTranslator {
40+
@Override
41+
public void translate(GeyserSession session, Vector3f position, BlockState state) {
42+
SoundEvent event = state.getValue(Properties.POWERED, false) ? SoundEvent.BUTTON_CLICK_ON : SoundEvent.BUTTON_CLICK_OFF;
43+
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
44+
levelSoundEventPacket.setPosition(position.add(0.5, 0.5, 0.5));
45+
levelSoundEventPacket.setBabySound(false);
46+
levelSoundEventPacket.setRelativeVolumeDisabled(false);
47+
levelSoundEventPacket.setIdentifier(":");
48+
levelSoundEventPacket.setSound(event);
49+
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlock(state).getRuntimeId());
50+
51+
session.sendUpstreamPacket(levelSoundEventPacket);
52+
}
53+
}

0 commit comments

Comments
 (0)