Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace block item as additional setting for block placer component. #5147

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/

package org.geysermc.geyser.api.item.custom;

/**
* This class is used to store the block placer settings of custom items.
*/
public record CustomBlockPlacer(String block, boolean replaceBlockItem) {}
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,20 @@ default boolean isTool() {
}

/**
* @deprecated Use {@link #blockPlacer()} instead.
* Gets the block the item places.
*
* @return the block the item places
*/
String block();
OmeWillem marked this conversation as resolved.
Show resolved Hide resolved

/**
* Gets the block placer settings, if it's null then the component won't be added.
*
* @return the block placer settings
*/
@Nullable CustomBlockPlacer blockPlacer();

static NonVanillaCustomItemData.Builder builder() {
return GeyserApi.api().provider(NonVanillaCustomItemData.Builder.class);
}
Expand Down Expand Up @@ -208,8 +216,14 @@ interface Builder extends CustomItemData.Builder {

Builder chargeable(boolean isChargeable);

/**
* @deprecated Use {@link #blockPlacer(CustomBlockPlacer)} instead.
*/
@Deprecated
Builder block(String block);

Builder blockPlacer(CustomBlockPlacer blockPlacer);

/**
* @deprecated Use {@link #displayHandheld(boolean)} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import lombok.ToString;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.item.custom.CustomBlockPlacer;
import org.geysermc.geyser.api.item.custom.CustomItemOptions;
import org.geysermc.geyser.api.item.custom.CustomRenderOffsets;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
Expand All @@ -55,7 +56,7 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
private final boolean isEdible;
private final boolean canAlwaysEat;
private final boolean isChargeable;
private final String block;
private final CustomBlockPlacer blockPlacer;

public GeyserNonVanillaCustomItemData(Builder builder) {
super(builder.name, builder.customItemOptions, builder.displayName, builder.icon, builder.allowOffhand,
Expand All @@ -79,7 +80,7 @@ public GeyserNonVanillaCustomItemData(Builder builder) {
this.isEdible = builder.edible;
this.canAlwaysEat = builder.canAlwaysEat;
this.isChargeable = builder.chargeable;
this.block = builder.block;
this.blockPlacer = builder.blockPlacer;
}

@Override
Expand Down Expand Up @@ -164,7 +165,12 @@ public boolean isChargeable() {

@Override
public String block() {
return block;
return blockPlacer == null ? null : blockPlacer.block();
}

@Override
public CustomBlockPlacer blockPlacer() {
return blockPlacer;
}

public static class Builder extends GeyserCustomItemData.Builder implements NonVanillaCustomItemData.Builder {
Expand Down Expand Up @@ -193,7 +199,7 @@ public static class Builder extends GeyserCustomItemData.Builder implements NonV
private boolean edible = false;
private boolean canAlwaysEat = false;
private boolean chargeable = false;
private String block = null;
private CustomBlockPlacer blockPlacer = null;

@Override
public Builder name(@NonNull String name) {
Expand Down Expand Up @@ -349,7 +355,13 @@ public Builder chargeable(boolean isChargeable) {

@Override
public Builder block(String block) {
this.block = block;
this.blockPlacer = new CustomBlockPlacer(block, false);
return this;
}

@Override
public Builder blockPlacer(CustomBlockPlacer blockPlacer) {
this.blockPlacer = blockPlacer;
return this;
}

Expand Down
Loading