mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 01:55:47 +01:00
Show notification on recipe add
This commit is contained in:
parent
4871977681
commit
3e3dad9e33
@ -57,6 +57,12 @@ import java.util.Set;
|
|||||||
|
|
||||||
public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_21_2, Protocol1_21To1_21_2> {
|
public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_21_2, Protocol1_21To1_21_2> {
|
||||||
|
|
||||||
|
private static final int RECIPE_NOTIFICATION_FLAG = 1 << 0;
|
||||||
|
private static final int RECIPE_HIGHLIGHT_FLAG = 1 << 1;
|
||||||
|
private static final int RECIPE_INIT = 0;
|
||||||
|
private static final int RECIPE_ADD = 1;
|
||||||
|
private static final int RECIPE_REMOVE = 2;
|
||||||
|
|
||||||
public BlockItemPacketRewriter1_21_2(final Protocol1_21To1_21_2 protocol) {
|
public BlockItemPacketRewriter1_21_2(final Protocol1_21To1_21_2 protocol) {
|
||||||
super(protocol,
|
super(protocol,
|
||||||
Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY,
|
Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY,
|
||||||
@ -194,9 +200,8 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_21.UPDATE_RECIPES, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_21.UPDATE_RECIPES, wrapper -> {
|
||||||
// TODO Handle resending. Updating them in newer versions isn't as easy anymore
|
|
||||||
final FullMappings recipeSerializerMappings = protocol.getMappingData().getRecipeSerializerMappings();
|
final FullMappings recipeSerializerMappings = protocol.getMappingData().getRecipeSerializerMappings();
|
||||||
final RecipeRewriter1_21_2 rewriter = new RecipeRewriter1_21_2(protocol); // Holds state, create a new one for each packet
|
final RecipeRewriter1_21_2 rewriter = new RecipeRewriter1_21_2(protocol);
|
||||||
wrapper.user().put(rewriter);
|
wrapper.user().put(rewriter);
|
||||||
|
|
||||||
final int size = wrapper.read(Types.VAR_INT);
|
final int size = wrapper.read(Types.VAR_INT);
|
||||||
@ -228,7 +233,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
// Read recipe keys from the packet
|
// Read recipe keys from the packet
|
||||||
final String[] recipes = wrapper.read(Types.STRING_ARRAY);
|
final String[] recipes = wrapper.read(Types.STRING_ARRAY);
|
||||||
Set<String> toHighlight = Set.of();
|
Set<String> toHighlight = Set.of();
|
||||||
if (state == 0) { // Init (1=Add, 2=Remove)
|
if (state == RECIPE_INIT) {
|
||||||
final String[] highlightRecipes = wrapper.read(Types.STRING_ARRAY);
|
final String[] highlightRecipes = wrapper.read(Types.STRING_ARRAY);
|
||||||
toHighlight = Set.of(highlightRecipes);
|
toHighlight = Set.of(highlightRecipes);
|
||||||
}
|
}
|
||||||
@ -242,8 +247,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
|
|
||||||
wrapper.clearPacket();
|
wrapper.clearPacket();
|
||||||
|
|
||||||
if (state == 2) {
|
if (state == RECIPE_REMOVE) {
|
||||||
// Remove recipes
|
|
||||||
wrapper.setPacketType(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE);
|
wrapper.setPacketType(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE);
|
||||||
|
|
||||||
final int[] ids = new int[recipes.length];
|
final int[] ids = new int[recipes.length];
|
||||||
@ -297,8 +301,13 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte flags = 0;
|
byte flags = 0;
|
||||||
if (toHighlight.contains(recipeKey)) {
|
if (state == RECIPE_ADD) {
|
||||||
flags |= (1 << 1); // Highlight
|
if (recipe.showNotification()) {
|
||||||
|
flags |= RECIPE_NOTIFICATION_FLAG;
|
||||||
|
}
|
||||||
|
flags |= RECIPE_HIGHLIGHT_FLAG;
|
||||||
|
} else if (toHighlight.contains(recipeKey)) {
|
||||||
|
flags |= RECIPE_HIGHLIGHT_FLAG;
|
||||||
}
|
}
|
||||||
wrapper.write(Types.BYTE, flags);
|
wrapper.write(Types.BYTE, flags);
|
||||||
}
|
}
|
||||||
|
@ -102,11 +102,10 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
|
|||||||
ingredients[i] = readIngredient(wrapper);
|
ingredients[i] = readIngredient(wrapper);
|
||||||
}
|
}
|
||||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||||
|
final boolean showNotification = wrapper.read(Types.BOOLEAN);
|
||||||
|
|
||||||
final ShapedRecipe recipe = new ShapedRecipe(recipesByKey.size(), currentRecipeIdentifier, group, category, width, height, ingredients, result);
|
final ShapedRecipe recipe = new ShapedRecipe(recipesByKey.size(), currentRecipeIdentifier, group, category, width, height, ingredients, result, showNotification);
|
||||||
addRecipe(recipe);
|
addRecipe(recipe);
|
||||||
|
|
||||||
wrapper.read(Types.BOOLEAN); // Show notification
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -218,6 +217,10 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default boolean showNotification() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int category();
|
int category();
|
||||||
|
|
||||||
void writeRecipeDisplay(PacketWrapper wrapper);
|
void writeRecipeDisplay(PacketWrapper wrapper);
|
||||||
@ -239,7 +242,7 @@ final class RecipeRewriter1_21_2 extends RecipeRewriter1_20_3<ClientboundPacket1
|
|||||||
}
|
}
|
||||||
|
|
||||||
record ShapedRecipe(int index, String identifier, int group, int category, int width, int height,
|
record ShapedRecipe(int index, String identifier, int group, int category, int width, int height,
|
||||||
Item[][] ingredients, Item result) implements Recipe {
|
Item[][] ingredients, Item result, boolean showNotification) implements Recipe {
|
||||||
@Override
|
@Override
|
||||||
public int recipeDisplayId() {
|
public int recipeDisplayId() {
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user