Skip to content

Commit

Permalink
fix: 超频模块使用不减少
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Aug 25, 2024
1 parent 73163d1 commit ce644b1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ public class SlimefunItem implements Placeable {
private ItemStack[] recipe;
/**
* -- SETTER --
* Sets the
* for this
* Sets the
* for this
* .
*
*/
@Setter
@Getter
Expand All @@ -111,33 +110,30 @@ public class SlimefunItem implements Placeable {

/**
* -- GETTER --
* This returns whether or not this
* is allowed to be used in
* an
* This returns whether or not this
* is allowed to be used in
* an
* .
*
*/
@Getter
protected boolean enchantable = true;
/**
* -- GETTER --
* This returns whether or not this
* is allowed to be used in
* an
* This returns whether or not this
* is allowed to be used in
* an
* .
*
*/
@Getter
protected boolean disenchantable = true;
protected boolean hidden = false;
/**
* -- GETTER --
* This method returns whether or not this
* is allowed to
* be used in a Crafting Table.
* Items of type
* may be used in workbenches for example.
*
* This method returns whether or not this
* is allowed to
* be used in a Crafting Table.
* Items of type
* may be used in workbenches for example.
*/
@Getter
protected boolean useableInWorkbench = false;
Expand All @@ -150,25 +146,22 @@ public class SlimefunItem implements Placeable {

/**
* -- GETTER --
* This returns whether or not we are scheduling a ticking task for this block.
*
* This returns whether or not we are scheduling a ticking task for this block.
*/
@Getter
private boolean ticking = false;
@Getter
private BlockTicker blockTicker;

private String normalItemName;

/**
* This creates a new {@link SlimefunItem} from the given arguments.
*
* @param itemGroup
* The {@link ItemGroup} this {@link SlimefunItem} belongs to
* @param item
* The {@link SlimefunItemStack} that describes the visual features of our {@link SlimefunItem}
* @param recipeType
* the {@link RecipeType} that determines how this {@link SlimefunItem} is crafted
* @param recipe
* An Array representing the recipe of this {@link SlimefunItem}
* @param itemGroup The {@link ItemGroup} this {@link SlimefunItem} belongs to
* @param item The {@link SlimefunItemStack} that describes the visual features of our {@link SlimefunItem}
* @param recipeType the {@link RecipeType} that determines how this {@link SlimefunItem} is crafted
* @param recipe An Array representing the recipe of this {@link SlimefunItem}
*/
public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
this(itemGroup, item, recipeType, recipe, null);
Expand All @@ -177,16 +170,11 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci
/**
* This creates a new {@link SlimefunItem} from the given arguments.
*
* @param itemGroup
* The {@link ItemGroup} this {@link SlimefunItem} belongs to
* @param item
* The {@link SlimefunItemStack} that describes the visual features of our {@link SlimefunItem}
* @param recipeType
* the {@link RecipeType} that determines how this {@link SlimefunItem} is crafted
* @param recipe
* An Array representing the recipe of this {@link SlimefunItem}
* @param recipeOutput
* The result of crafting this item
* @param itemGroup The {@link ItemGroup} this {@link SlimefunItem} belongs to
* @param item The {@link SlimefunItemStack} that describes the visual features of our {@link SlimefunItem}
* @param recipeType the {@link RecipeType} that determines how this {@link SlimefunItem} is crafted
* @param recipe An Array representing the recipe of this {@link SlimefunItem}
* @param recipeOutput The result of crafting this item
*/
public SlimefunItem(
ItemGroup itemGroup,
Expand All @@ -200,6 +188,7 @@ public SlimefunItem(
this.recipeType = recipeType;
this.recipe = recipe;
this.recipeOutput = recipeOutput;
normalItemName = TextUtils.toPlainText(itemStackTemplate.getItemMeta().getDisplayName()).replaceAll(" ","_");
}

// Previously deprecated constructor, now only for internal purposes
Expand All @@ -209,6 +198,7 @@ protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeTyp
this.id = id;
this.recipeType = recipeType;
this.recipe = recipe;
normalItemName = TextUtils.toPlainText(itemStackTemplate.getItemMeta().getDisplayName()).replaceAll(" ","_");
}

/**
Expand Down Expand Up @@ -503,9 +493,9 @@ private void onEnable() {
// Check for an illegal stack size
if (itemStackTemplate.getAmount() != 1) {
warn("无效物品数量: "
+ itemStackTemplate.getAmount()
+ " "
+ addon.getName());
+ itemStackTemplate.getAmount()
+ " "
+ addon.getName());

}

Expand Down Expand Up @@ -824,7 +814,7 @@ public final String getItemName() {
}

public final String getItemNormalName() {
return TextUtils.toPlainText(itemStackTemplate.getItemMeta().getDisplayName()).replaceAll(" ","_");
return TextUtils.toPlainText(itemStackTemplate.getItemMeta().getDisplayName()).replaceAll(" ", "_");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.qscbm.slimefun4.items.machines.Speedable;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.Optional;
Expand All @@ -31,15 +32,16 @@ public ItemUseHandler getItemHandler() {
SlimefunBlockData blockData = Slimefun.getDatabaseManager()
.getBlockDataController().getBlockData(block.getLocation());
SlimefunItem item = sfBlock.get();

Player player = e.getPlayer();
if (item instanceof Speedable machine) {
if (!machine.speedUp(blockData)) {
e.getPlayer().sendMessage("超频倍率已达上限: " + machine.getSpeedLimit() + "x");
player.sendMessage("超频倍率已达上限: " + machine.getSpeedLimit() + "x");
} else {
e.getPlayer().sendMessage("超频机器成功, 目前倍率: " + machine.getIncreasedSpeed(blockData) + "x");
player.sendMessage("超频机器成功, 目前倍率: " + machine.getIncreasedSpeed(blockData) + "x");
e.getItem().setAmount(e.getItem().getAmount() - 1);
}
} else {
e.getPlayer().sendMessage("该机器无法超频");
player.sendMessage("该机器无法超频");
}
}
};
Expand Down

0 comments on commit ce644b1

Please sign in to comment.