mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-28 07:20:28 +01:00
Implement remainder slot display recipes
This commit is contained in:
parent
52679f9f81
commit
8ba70f0fc8
11 changed files with 22 additions and 19 deletions
|
@ -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)
|
||||
|
|
|
@ -74,6 +74,7 @@ public class JavaFinishConfigurationTranslator extends PacketTranslator<Clientbo
|
|||
session.getUpstream().sendPacket(craftingDataPacket);
|
||||
session.getCraftingRecipes().clear();
|
||||
session.getJavaToBedrockRecipeIds().clear();
|
||||
session.getSmithingRecipes().clear();
|
||||
session.getStonecutterRecipes().clear();
|
||||
} else {
|
||||
session.getUpstream().queuePostStartGamePacket(craftingDataPacket);
|
||||
|
|
|
@ -67,6 +67,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemSta
|
|||
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;
|
||||
|
@ -208,6 +209,10 @@ public class JavaRecipeBookAddTranslator extends PacketTranslator<ClientboundRec
|
|||
.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()));
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.Set;
|
|||
@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) {
|
||||
|
@ -62,6 +62,7 @@ public class JavaSelectKnownPacksTranslator extends PacketTranslator<Clientbound
|
|||
|
||||
@Override
|
||||
public boolean shouldExecuteInEventLoop() {
|
||||
// This technically isn't correct behavior, but it prevents race conditions between MCProtocolLib's packet handler and ours.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -268,14 +268,12 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
|
|||
|
||||
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()
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.cloudburstmc.math.vector.Vector3f;
|
|||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.cloudburstmc.math.vector.Vector3f;
|
|||
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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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);
|
||||
|
|
|
@ -67,6 +67,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.ItemSlo
|
|||
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;
|
||||
|
@ -462,6 +463,9 @@ public class InventoryUtils {
|
|||
}
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue