Skip to content

Commit

Permalink
Fix: Workaround for recipes involving custom items to show up in the …
Browse files Browse the repository at this point in the history
…recipe book (GeyserMC#4484)

* Allow adding custom items to the creative inventory in order for recipes outputting said custom items to work

* yeet includeInCreativeInventory as it would break existing nonvanilla extensions - and is pretty pointless anyways

* rename mappings to `creative_group` and `creative_category`

* delete outdated comment
  • Loading branch information
onebeastchris authored Mar 10, 2024
1 parent 527eab0 commit 0ad7c43
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public interface CustomBlockData {
boolean includedInCreativeInventory();

/**
* Gets the item's creative category, or tab id.
* Gets the block's creative category, or tab id.
*
* @return the item's creative category
* @return the block's creative category
*/
@Nullable CreativeCategory creativeCategory();

/**
* Gets the item's creative group.
* Gets the block's creative group.
*
* @return the item's creative group
* @return the block's creative group
*/
@Nullable String creativeGroup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;

import java.util.OptionalInt;
import java.util.Set;

/**
Expand Down Expand Up @@ -77,6 +78,20 @@ public interface CustomItemData {
*/
boolean displayHandheld();

/**
* Gets the item's creative category, or tab id.
*
* @return the item's creative category
*/
@NonNull OptionalInt creativeCategory();

/**
* Gets the item's creative group.
*
* @return the item's creative group
*/
@Nullable String creativeGroup();

/**
* Gets the item's texture size. This is to resize the item if the texture is not 16x16.
*
Expand Down Expand Up @@ -119,6 +134,10 @@ interface Builder {

Builder displayHandheld(boolean displayHandheld);

Builder creativeCategory(int creativeCategory);

Builder creativeGroup(@Nullable String creativeGroup);

Builder textureSize(int textureSize);

Builder renderOffsets(@Nullable CustomRenderOffsets renderOffsets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;

import java.util.OptionalInt;
import java.util.Set;

/**
Expand Down Expand Up @@ -107,20 +106,6 @@ public interface NonVanillaCustomItemData extends CustomItemData {
*/
@Nullable Set<String> repairMaterials();

/**
* Gets the item's creative category, or tab id.
*
* @return the item's creative category
*/
@NonNull OptionalInt creativeCategory();

/**
* Gets the item's creative group.
*
* @return the item's creative group
*/
@Nullable String creativeGroup();

/**
* Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and
* normally allow the player to equip it. This is not meant for armor.
Expand Down Expand Up @@ -196,10 +181,6 @@ interface Builder extends CustomItemData.Builder {

Builder repairMaterials(@Nullable Set<String> repairMaterials);

Builder creativeCategory(int creativeCategory);

Builder creativeGroup(@Nullable String creativeGroup);

Builder hat(boolean isHat);

Builder foil(boolean isFoil);
Expand All @@ -218,6 +199,12 @@ default Builder tool(boolean isTool) {
return displayHandheld(isTool);
}

@Override
Builder creativeCategory(int creativeCategory);

@Override
Builder creativeGroup(@Nullable String creativeGroup);

@Override
Builder customItemOptions(@NonNull CustomItemOptions customItemOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.util.HashSet;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Set;

@EqualsAndHashCode
Expand All @@ -46,6 +47,8 @@ public class GeyserCustomItemData implements CustomItemData {
private final String icon;
private final boolean allowOffhand;
private final boolean displayHandheld;
private final OptionalInt creativeCategory;
private final String creativeGroup;
private final int textureSize;
private final CustomRenderOffsets renderOffsets;
private final Set<String> tags;
Expand All @@ -56,6 +59,8 @@ public GeyserCustomItemData(String name,
String icon,
boolean allowOffhand,
boolean displayHandheld,
OptionalInt creativeCategory,
String creativeGroup,
int textureSize,
CustomRenderOffsets renderOffsets,
Set<String> tags) {
Expand All @@ -65,6 +70,8 @@ public GeyserCustomItemData(String name,
this.icon = icon;
this.allowOffhand = allowOffhand;
this.displayHandheld = displayHandheld;
this.creativeCategory = creativeCategory;
this.creativeGroup = creativeGroup;
this.textureSize = textureSize;
this.renderOffsets = renderOffsets;
this.tags = tags;
Expand Down Expand Up @@ -100,6 +107,16 @@ public boolean displayHandheld() {
return this.displayHandheld;
}

@Override
public @NonNull OptionalInt creativeCategory() {
return this.creativeCategory;
}

@Override
public @Nullable String creativeGroup() {
return this.creativeGroup;
}

@Override
public int textureSize() {
return textureSize;
Expand All @@ -118,11 +135,12 @@ public CustomRenderOffsets renderOffsets() {
public static class Builder implements CustomItemData.Builder {
protected String name = null;
protected CustomItemOptions customItemOptions = null;

protected String displayName = null;
protected String icon = null;
protected boolean allowOffhand = true; // Bedrock doesn't give items offhand allowance unless they serve gameplay purpose, but we want to be friendly with Java
protected boolean displayHandheld = false;
protected OptionalInt creativeCategory = OptionalInt.empty();
protected String creativeGroup = null;
protected int textureSize = 16;
protected CustomRenderOffsets renderOffsets = null;
protected Set<String> tags = new HashSet<>();
Expand Down Expand Up @@ -163,6 +181,18 @@ public Builder displayHandheld(boolean displayHandheld) {
return this;
}

@Override
public Builder creativeCategory(int creativeCategory) {
this.creativeCategory = OptionalInt.of(creativeCategory);
return this;
}

@Override
public Builder creativeGroup(@Nullable String creativeGroup) {
this.creativeGroup = creativeGroup;
return this;
}

@Override
public Builder textureSize(int textureSize) {
this.textureSize = textureSize;
Expand Down Expand Up @@ -193,7 +223,8 @@ public CustomItemData build() {
if (this.icon == null) {
this.icon = this.name;
}
return new GeyserCustomItemData(this.name, this.customItemOptions, this.displayName, this.icon, this.allowOffhand, this.displayHandheld, this.textureSize, this.renderOffsets, this.tags);
return new GeyserCustomItemData(this.name, this.customItemOptions, this.displayName, this.icon, this.allowOffhand,
this.displayHandheld, this.creativeCategory, this.creativeGroup, this.textureSize, this.renderOffsets, this.tags);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;

import java.util.OptionalInt;
import java.util.Set;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@EqualsAndHashCode(callSuper = true)
@ToString
public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData implements NonVanillaCustomItemData {
Expand All @@ -50,8 +48,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
private final int protectionValue;
private final String translationString;
private final Set<String> repairMaterials;
private final OptionalInt creativeCategory;
private final String creativeGroup;
private final boolean isHat;
private final boolean isFoil;
private final boolean isTool;
Expand All @@ -61,7 +57,8 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i

public GeyserNonVanillaCustomItemData(Builder builder) {
super(builder.name, builder.customItemOptions, builder.displayName, builder.icon, builder.allowOffhand,
builder.displayHandheld, builder.textureSize, builder.renderOffsets, builder.tags);
builder.displayHandheld, builder.creativeCategory, builder.creativeGroup,
builder.textureSize, builder.renderOffsets, builder.tags);

this.identifier = builder.identifier;
this.javaId = builder.javaId;
Expand All @@ -73,8 +70,6 @@ public GeyserNonVanillaCustomItemData(Builder builder) {
this.protectionValue = builder.protectionValue;
this.translationString = builder.translationString;
this.repairMaterials = builder.repairMaterials;
this.creativeCategory = builder.creativeCategory;
this.creativeGroup = builder.creativeGroup;
this.isHat = builder.hat;
this.isFoil = builder.foil;
this.isTool = builder.tool;
Expand Down Expand Up @@ -133,16 +128,6 @@ public Set<String> repairMaterials() {
return repairMaterials;
}

@Override
public @NonNull OptionalInt creativeCategory() {
return creativeCategory;
}

@Override
public String creativeGroup() {
return creativeGroup;
}

@Override
public boolean isHat() {
return isHat;
Expand Down Expand Up @@ -186,9 +171,6 @@ public static class Builder extends GeyserCustomItemData.Builder implements NonV

private Set<String> repairMaterials;

private OptionalInt creativeCategory = OptionalInt.empty();
private String creativeGroup = null;

private boolean hat = false;
private boolean foil = false;
private boolean tool = false;
Expand Down Expand Up @@ -243,103 +225,101 @@ public Builder tags(@Nullable Set<String> tags) {
}

@Override
public NonVanillaCustomItemData.Builder identifier(@NonNull String identifier) {
public Builder identifier(@NonNull String identifier) {
this.identifier = identifier;
return this;
}

@Override
public NonVanillaCustomItemData.Builder javaId(int javaId) {
public Builder javaId(int javaId) {
this.javaId = javaId;
return this;
}

@Override
public NonVanillaCustomItemData.Builder stackSize(int stackSize) {
public Builder stackSize(int stackSize) {
this.stackSize = stackSize;
return this;
}

@Override
public NonVanillaCustomItemData.Builder maxDamage(int maxDamage) {
public Builder maxDamage(int maxDamage) {
this.maxDamage = maxDamage;
return this;
}

@Override
public NonVanillaCustomItemData.Builder toolType(@Nullable String toolType) {
public Builder toolType(@Nullable String toolType) {
this.toolType = toolType;
return this;
}

@Override
public NonVanillaCustomItemData.Builder toolTier(@Nullable String toolTier) {
public Builder toolTier(@Nullable String toolTier) {
this.toolTier = toolTier;
return this;
}

@Override
public NonVanillaCustomItemData.Builder armorType(@Nullable String armorType) {
public Builder armorType(@Nullable String armorType) {
this.armorType = armorType;
return this;
}

@Override
public NonVanillaCustomItemData.Builder protectionValue(int protectionValue) {
public Builder protectionValue(int protectionValue) {
this.protectionValue = protectionValue;
return this;
}

@Override
public NonVanillaCustomItemData.Builder translationString(@Nullable String translationString) {
public Builder translationString(@Nullable String translationString) {
this.translationString = translationString;
return this;
}

@Override
public NonVanillaCustomItemData.Builder repairMaterials(@Nullable Set<String> repairMaterials) {
public Builder repairMaterials(@Nullable Set<String> repairMaterials) {
this.repairMaterials = repairMaterials;
return this;
}

@Override
public NonVanillaCustomItemData.Builder creativeCategory(int creativeCategory) {
this.creativeCategory = OptionalInt.of(creativeCategory);
return this;
public Builder creativeCategory(int creativeCategory) {
return (Builder) super.creativeCategory(creativeCategory);
}

@Override
public NonVanillaCustomItemData.Builder creativeGroup(@Nullable String creativeGroup) {
this.creativeGroup = creativeGroup;
return this;
public Builder creativeGroup(@Nullable String creativeGroup) {
return (Builder) super.creativeGroup(creativeGroup);
}

@Override
public NonVanillaCustomItemData.Builder hat(boolean isHat) {
public Builder hat(boolean isHat) {
this.hat = isHat;
return this;
}

@Override
public NonVanillaCustomItemData.Builder foil(boolean isFoil) {
public Builder foil(boolean isFoil) {
this.foil = isFoil;
return this;
}

@Override
public NonVanillaCustomItemData.Builder edible(boolean isEdible) {
public Builder edible(boolean isEdible) {
this.edible = isEdible;
return this;
}

@Override
public NonVanillaCustomItemData.Builder canAlwaysEat(boolean canAlwaysEat) {
public Builder canAlwaysEat(boolean canAlwaysEat) {
this.canAlwaysEat = canAlwaysEat;
return this;
}

@Override
public NonVanillaCustomItemData.Builder chargeable(boolean isChargeable) {
public Builder chargeable(boolean isChargeable) {
this.chargeable = isChargeable;
return this;
}
Expand Down
Loading

0 comments on commit 0ad7c43

Please sign in to comment.