Skip to content

Commit

Permalink
Implement remainder slot display recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Oct 30, 2024
1 parent 52679f9 commit 8ba70f0
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ public final class EntityDefinitions {
SALMON = EntityDefinition.inherited(abstractFishEntityBase.factory(), abstractFishEntityBase)
.type(EntityType.SALMON)
.height(0.5f).width(0.7f)
.addTranslator(null) // Scale/variant - TODO
.build();
TADPOLE = EntityDefinition.inherited(TadpoleEntity::new, abstractFishEntityBase)
.type(EntityType.TADPOLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void translate(GeyserSession session, ClientboundFinishConfigurationPacke
session.getUpstream().sendPacket(craftingDataPacket);
session.getCraftingRecipes().clear();
session.getJavaToBedrockRecipeIds().clear();
session.getSmithingRecipes().clear();
session.getStonecutterRecipes().clear();
} else {
session.getUpstream().queuePostStartGamePacket(craftingDataPacket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SmithingTrimDemoSlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.TagSlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.WithRemainderSlotDisplay;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundRecipeBookAddPacket;

import java.util.ArrayList;
Expand Down Expand Up @@ -208,6 +209,10 @@ private List<ItemDescriptorWithCount> translateToInput(GeyserSession session, Sl
.flatMap(List::stream)
.toList();
}
if (slotDisplay instanceof WithRemainderSlotDisplay remainder) {
// Don't need to worry about what will stay in the crafting table after crafting for the purposes of sending recipes to Bedrock
return translateToInput(session, remainder.input());
}
if (slotDisplay instanceof ItemSlotDisplay itemSlot) {
return Collections.singletonList(fromItem(session, itemSlot.item()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@Translator(packet = ClientboundSelectKnownPacks.class)
public class JavaSelectKnownPacksTranslator extends PacketTranslator<ClientboundSelectKnownPacks> {
// todo: dump from client?
private static final Set<String> KNOWN_PACK_IDS = Set.of("core", "update_1_21", "bundle", "trade_rebalance");
private static final Set<String> KNOWN_PACK_IDS = Set.of("core", "winter_drop", "trade_rebalance", "redstone_experiments", "minecart_improvements");

@Override
public void translate(GeyserSession session, ClientboundSelectKnownPacks packet) {
Expand All @@ -62,6 +62,7 @@ public void translate(GeyserSession session, ClientboundSelectKnownPacks packet)

@Override
public boolean shouldExecuteInEventLoop() {
// This technically isn't correct behavior, but it prevents race conditions between MCProtocolLib's packet handler and ours.
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,12 @@ private static void updateSmithingTableOutput(GeyserSession session, int slot, I

UUID uuid = UUID.randomUUID();

ItemData bedrockAddition = ItemTranslator.translateToBedrock(session, material.getItemStack());

CraftingDataPacket craftPacket = new CraftingDataPacket();
craftPacket.getCraftingData().add(SmithingTransformRecipeData.of(
uuid.toString(),
ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, template.getItemStack())),
ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, input.getItemStack())),
ItemDescriptorWithCount.fromItem(bedrockAddition),
ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, material.getItemStack())),
ItemTranslator.translateToBedrock(session, output),
"smithing_table",
session.getLastRecipeNetId().incrementAndGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.geyser.level.block.property.Properties;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
Expand All @@ -38,12 +39,10 @@ public class ComparatorSoundInteractionTranslator implements BlockSoundInteracti

@Override
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
boolean powered = identifier.contains("mode=compare");
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);
levelEventPacket.setType(LevelEvent.SOUND_CLICK); //TODO: New ID?
levelEventPacket.setData(powered ? 500 : 550);
levelEventPacket.setData(state.getValue(Properties.MODE_COMPARATOR).equals("compare") ? 500 : 550);
session.sendUpstreamPacket(levelEventPacket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
Expand All @@ -39,14 +38,13 @@ public class GrassPathInteractionTranslator implements BlockSoundInteractionTran

@Override
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position);
levelSoundEventPacket.setBabySound(false);
levelSoundEventPacket.setRelativeVolumeDisabled(false);
levelSoundEventPacket.setIdentifier(":");
levelSoundEventPacket.setSound(SoundEvent.ITEM_USE_ON);
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIER_TO_ID.get().getInt(identifier)));
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(state.javaId()));
session.sendUpstreamPacket(levelSoundEventPacket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
import org.geysermc.geyser.translator.sound.SoundTranslator;
Expand All @@ -39,14 +38,13 @@ public class HoeInteractionTranslator implements BlockSoundInteractionTranslator

@Override
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position);
levelSoundEventPacket.setBabySound(false);
levelSoundEventPacket.setRelativeVolumeDisabled(false);
levelSoundEventPacket.setIdentifier(":");
levelSoundEventPacket.setSound(SoundEvent.ITEM_USE_ON);
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(BlockRegistries.JAVA_IDENTIFIER_TO_ID.get().getInt(identifier)));
levelSoundEventPacket.setExtraData(session.getBlockMappings().getBedrockBlockId(state.javaId()));
session.sendUpstreamPacket(levelSoundEventPacket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.geyser.level.block.property.Properties;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
Expand All @@ -38,12 +39,10 @@ public class LeverSoundInteractionTranslator implements BlockSoundInteractionTra

@Override
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
boolean powered = identifier.contains("powered=true");
LevelEventPacket levelEventPacket = new LevelEventPacket();
levelEventPacket.setPosition(position);
levelEventPacket.setType(LevelEvent.SOUND_CLICK);
levelEventPacket.setData(powered ? 600 : 500);
levelEventPacket.setData(state.getValue(Properties.POWERED) ? 600 : 500);
session.sendUpstreamPacket(levelEventPacket);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
package org.geysermc.geyser.translator.sound.block;

import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket;
import org.cloudburstmc.protocol.bedrock.packet.LevelSoundEventPacket;
import org.geysermc.geyser.level.block.property.Properties;
import org.geysermc.geyser.level.block.type.BlockState;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator;
Expand All @@ -42,7 +41,7 @@ public class OpenableSoundInteractionTranslator implements BlockSoundInteraction
public void translate(GeyserSession session, Vector3f position, BlockState state) {
String identifier = state.toString();
if (identifier.contains("iron")) return;
SoundEvent event = getSound(identifier.contains("open=true"), identifier);
SoundEvent event = getSound(state.getValue(Properties.OPEN, false), identifier);
LevelSoundEventPacket levelSoundEventPacket = new LevelSoundEventPacket();
levelSoundEventPacket.setPosition(position.add(0.5, 0.5, 0.5));
levelSoundEventPacket.setBabySound(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemStackSlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.TagSlotDisplay;
import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.WithRemainderSlotDisplay;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
Expand Down Expand Up @@ -462,6 +463,9 @@ public static boolean acceptsAsInput(GeyserSession session, SlotDisplay slotDisp
}
return compositeSlotDisplay.contents().stream().anyMatch(aSlotDisplay -> acceptsAsInput(session, aSlotDisplay, itemStack));
}
if (slotDisplay instanceof WithRemainderSlotDisplay remainderSlotDisplay) {
return acceptsAsInput(session, remainderSlotDisplay.input(), itemStack);
}
if (slotDisplay instanceof ItemSlotDisplay itemSlotDisplay) {
return itemStack.getJavaId() == itemSlotDisplay.item();
}
Expand Down

0 comments on commit 8ba70f0

Please sign in to comment.