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

new ItemStack => ItemStack.of #4246

Open
wants to merge 10 commits into
base: walshy/mc-1.21
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public enum MinecraftVersion {
*/
MINECRAFT_1_21(21, 0, "1.21.x"),

/**
* This constant represents Minecraft (Java Edition) Version 1.21
* ("Tricky Trials")
*/
MINECRAFT_1_21(21, 0, "1.21+"),

/**
* This constant represents an exceptional state in which we were unable
Intybyte marked this conversation as resolved.
Show resolved Hide resolved
* to identify the Minecraft Version we are using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.annotation.Nonnull;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -92,13 +93,13 @@ public PlayerInteractEvent getInteractEvent() {
/**
* This method returns the {@link ItemStack} that was held in the hand of the {@link Player}.
* It will never return null, should there be no {@link ItemStack} then it will return
* {@code new ItemStack(Material.AIR)}.
* {@code StackResolver.of(Material.AIR)}.
*
* @return The {@link ItemStack} that the {@link Player} right clicked with
*/
@Nonnull
public ItemStack getItem() {
return itemStack.orElse(new ItemStack(Material.AIR));
return itemStack.orElse(StackResolver.of(Material.AIR));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Color;
Expand Down Expand Up @@ -78,7 +79,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull C
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Consumer<ItemMeta> consumer) {
this(id, new ItemStack(type), consumer);
this(id, StackResolver.of(type), consumer);
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
Expand Down Expand Up @@ -109,7 +110,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nullable
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, String... lore) {
this(id, new ItemStack(type), name, lore);
this(id, StackResolver.of(type), name, lore);
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) {
Expand Down Expand Up @@ -284,7 +285,7 @@ public void lock() {

private static @Nonnull ItemStack getSkull(@Nonnull String id, @Nonnull String texture) {
if (Slimefun.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
return new ItemStack(Material.PLAYER_HEAD);
return StackResolver.of(Material.PLAYER_HEAD);
}

PlayerSkin skin = PlayerSkin.fromBase64(getTexture(id, texture));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.ChatColor;
import org.bukkit.Keyed;
import org.bukkit.Material;
Expand Down Expand Up @@ -113,7 +114,7 @@ public RecipeType(NamespacedKey key, ItemStack item) {
}

public RecipeType(MinecraftRecipe<?> recipe) {
this.item = new ItemStack(recipe.getMachine());
this.item = StackResolver.of(recipe.getMachine());
this.machine = "";
this.key = NamespacedKey.minecraft(recipe.getRecipeClass().getSimpleName().toLowerCase(Locale.ROOT).replace("recipe", ""));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -47,7 +48,7 @@ public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {

if (current.isPresent()) {
SlimefunGuideMode selectedMode = current.get();
ItemStack item = new ItemStack(Material.AIR);
ItemStack item = StackResolver.of(Material.AIR);

if (selectedMode == SlimefunGuideMode.SURVIVAL_MODE) {
item.setType(Material.CHEST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nonnull;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -42,7 +43,7 @@ public void add(int amount) {

private void initializeItem() {
if (this.item instanceof ItemStackWrapper) {
ItemStack copy = new ItemStack(item.getType(), item.getAmount());
ItemStack copy = StackResolver.of(item.getType(), item.getAmount());
if (this.item.hasItemMeta()) {
copy.setItemMeta(this.item.getItemMeta());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Keyed;
Expand Down Expand Up @@ -315,7 +316,7 @@ protected void loadEmbeddedLanguages() {

if (item == null) {
// Fixes #3088
return new ItemStack(Material.AIR);
return StackResolver.of(Material.AIR);
}

Language language = getLanguage(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand Down Expand Up @@ -484,15 +485,15 @@ private <T extends Recipe> void showRecipeChoices(T recipe, ItemStack[] recipeIt
RecipeChoice[] choices = Slimefun.getMinecraftRecipeService().getRecipeShape(recipe);

if (choices.length == 1 && choices[0] instanceof MaterialChoice materialChoice) {
recipeItems[4] = new ItemStack(materialChoice.getChoices().get(0));
recipeItems[4] = StackResolver.of(materialChoice.getChoices().get(0));

if (materialChoice.getChoices().size() > 1) {
task.add(recipeSlots[4], materialChoice);
}
} else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] instanceof MaterialChoice materialChoice) {
recipeItems[i] = new ItemStack(materialChoice.getChoices().get(0));
recipeItems[i] = StackResolver.of(materialChoice.getChoices().get(0));

if (materialChoice.getChoices().size() > 1) {
task.add(recipeSlots[i], materialChoice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
Expand Down Expand Up @@ -69,13 +70,13 @@ private ItemStack getDropFromCrop(Material crop) {
Random random = ThreadLocalRandom.current();

return switch (crop) {
case WHEAT -> new ItemStack(Material.WHEAT, random.nextInt(2) + 1);
case POTATOES -> new ItemStack(Material.POTATO, random.nextInt(3) + 1);
case CARROTS -> new ItemStack(Material.CARROT, random.nextInt(3) + 1);
case BEETROOTS -> new ItemStack(Material.BEETROOT, random.nextInt(3) + 1);
case COCOA -> new ItemStack(Material.COCOA_BEANS, random.nextInt(3) + 1);
case NETHER_WART -> new ItemStack(Material.NETHER_WART, random.nextInt(3) + 1);
case SWEET_BERRY_BUSH -> new ItemStack(Material.SWEET_BERRIES, random.nextInt(3) + 1);
case WHEAT -> StackResolver.of(Material.WHEAT, random.nextInt(2) + 1);
case POTATOES -> StackResolver.of(Material.POTATO, random.nextInt(3) + 1);
case CARROTS -> StackResolver.of(Material.CARROT, random.nextInt(3) + 1);
case BEETROOTS -> StackResolver.of(Material.BEETROOT, random.nextInt(3) + 1);
case COCOA -> StackResolver.of(Material.COCOA_BEANS, random.nextInt(3) + 1);
case NETHER_WART -> StackResolver.of(Material.NETHER_WART, random.nextInt(3) + 1);
case SWEET_BERRY_BUSH -> StackResolver.of(Material.SWEET_BERRIES, random.nextInt(3) + 1);
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
Expand All @@ -28,23 +29,23 @@ public FishermanAndroid(ItemGroup itemGroup, int tier, SlimefunItemStack item, R

// Fish
for (Material fish : Tag.ITEMS_FISHES.getValues()) {
fishingLoot.add(new ItemStack(fish), 25);
fishingLoot.add(StackResolver.of(fish), 25);
}

// Junk
fishingLoot.add(new ItemStack(Material.BONE), 10);
fishingLoot.add(new ItemStack(Material.STRING), 10);
fishingLoot.add(new ItemStack(Material.INK_SAC), 8);
fishingLoot.add(new ItemStack(Material.KELP), 6);
fishingLoot.add(new ItemStack(Material.STICK), 5);
fishingLoot.add(new ItemStack(Material.ROTTEN_FLESH), 3);
fishingLoot.add(new ItemStack(Material.LEATHER), 2);
fishingLoot.add(new ItemStack(Material.BAMBOO), 3);
fishingLoot.add(StackResolver.of(Material.BONE), 10);
fishingLoot.add(StackResolver.of(Material.STRING), 10);
fishingLoot.add(StackResolver.of(Material.INK_SAC), 8);
fishingLoot.add(StackResolver.of(Material.KELP), 6);
fishingLoot.add(StackResolver.of(Material.STICK), 5);
fishingLoot.add(StackResolver.of(Material.ROTTEN_FLESH), 3);
fishingLoot.add(StackResolver.of(Material.LEATHER), 2);
fishingLoot.add(StackResolver.of(Material.BAMBOO), 3);

// "loot"
fishingLoot.add(new ItemStack(Material.SADDLE), 1);
fishingLoot.add(new ItemStack(Material.NAME_TAG), 1);
fishingLoot.add(new ItemStack(Material.NAUTILUS_SHELL), 1);
fishingLoot.add(StackResolver.of(Material.SADDLE), 1);
fishingLoot.add(StackResolver.of(Material.NAME_TAG), 1);
fishingLoot.add(StackResolver.of(Material.NAUTILUS_SHELL), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
Expand Down Expand Up @@ -52,7 +53,7 @@
public class MinerAndroid extends ProgrammableAndroid {

// Determines the drops a miner android will get
private final ItemStack effectivePickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
private final ItemStack effectivePickaxe = StackResolver.of(Material.DIAMOND_PICKAXE);

private final ItemSetting<Boolean> firesEvent = new ItemSetting<>(this, "trigger-event-for-generators", false);
private final ItemSetting<Boolean> applyOptimizations = new ItemSetting<>(this, "reduced-block-updates", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -595,27 +596,27 @@ public void setScript(@Nonnull Location l, @Nonnull String script) {
private void registerDefaultFuelTypes() {
switch (getFuelSource()) {
case SOLID -> {
registerFuelType(new MachineFuel(80, new ItemStack(Material.COAL_BLOCK)));
registerFuelType(new MachineFuel(45, new ItemStack(Material.BLAZE_ROD)));
registerFuelType(new MachineFuel(70, new ItemStack(Material.DRIED_KELP_BLOCK)));
registerFuelType(new MachineFuel(80, StackResolver.of(Material.COAL_BLOCK)));
registerFuelType(new MachineFuel(45, StackResolver.of(Material.BLAZE_ROD)));
registerFuelType(new MachineFuel(70, StackResolver.of(Material.DRIED_KELP_BLOCK)));

// Coal, Charcoal & Bamboo
registerFuelType(new MachineFuel(8, new ItemStack(Material.COAL)));
registerFuelType(new MachineFuel(8, new ItemStack(Material.CHARCOAL)));
registerFuelType(new MachineFuel(1, new ItemStack(Material.BAMBOO)));
registerFuelType(new MachineFuel(8, StackResolver.of(Material.COAL)));
registerFuelType(new MachineFuel(8, StackResolver.of(Material.CHARCOAL)));
registerFuelType(new MachineFuel(1, StackResolver.of(Material.BAMBOO)));

// Logs
for (Material mat : Tag.LOGS.getValues()) {
registerFuelType(new MachineFuel(2, new ItemStack(mat)));
registerFuelType(new MachineFuel(2, StackResolver.of(mat)));
}

// Wooden Planks
for (Material mat : Tag.PLANKS.getValues()) {
registerFuelType(new MachineFuel(1, new ItemStack(mat)));
registerFuelType(new MachineFuel(1, StackResolver.of(mat)));
}
}
case LIQUID -> {
registerFuelType(new MachineFuel(100, new ItemStack(Material.LAVA_BUCKET)));
registerFuelType(new MachineFuel(100, StackResolver.of(Material.LAVA_BUCKET)));
registerFuelType(new MachineFuel(200, SlimefunItems.OIL_BUCKET));
registerFuelType(new MachineFuel(500, SlimefunItems.FUEL_BUCKET));
}
Expand Down Expand Up @@ -828,7 +829,7 @@ private void consumeFuel(Block b, BlockMenu menu) {
menu.consumeItem(43);

if (getFuelSource() == AndroidFuelSource.LIQUID) {
menu.pushItem(new ItemStack(Material.BUCKET), getOutputSlots());
menu.pushItem(StackResolver.of(Material.BUCKET), getOutputSlots());
}

int fuelLevel = fuel.getTicks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Material;
Expand Down Expand Up @@ -71,7 +72,7 @@ protected boolean chopTree(Block b, BlockMenu menu, BlockFace face) {

@ParametersAreNonnullByDefault
private void breakLog(Block log, Block android, BlockMenu menu, BlockFace face) {
ItemStack drop = new ItemStack(log.getType());
ItemStack drop = StackResolver.of(log.getType());

// We try to push the log into the android's inventory, but nothing happens if it does not fit
menu.pushItem(drop, getOutputSlots());
Expand Down Expand Up @@ -179,7 +180,7 @@ private void replant(@Nonnull Block block) {
block.setType(saplingType);
} else {
// Simply drop the sapling if the soil does not fit
block.getWorld().dropItemNaturally(block.getLocation(), new ItemStack(saplingType));
block.getWorld().dropItemNaturally(block.getLocation(), StackResolver.of(saplingType));
block.setType(Material.AIR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -474,10 +475,10 @@ private ItemStack getLeftoverItem(@Nonnull ItemStack item) {
return switch (type) {
case WATER_BUCKET,
LAVA_BUCKET,
MILK_BUCKET -> new ItemStack(Material.BUCKET);
MILK_BUCKET -> StackResolver.of(Material.BUCKET);
case DRAGON_BREATH,
POTION,
HONEY_BOTTLE -> new ItemStack(Material.GLASS_BOTTLE);
HONEY_BOTTLE -> StackResolver.of(Material.GLASS_BOTTLE);
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import javax.annotation.Nonnull;

import io.github.thebusybiscuit.slimefun4.utils.compatibility.StackResolver;
import org.apache.commons.lang.Validate;
import org.bukkit.Keyed;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -82,15 +83,15 @@ public void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task) {
ItemStack[] items = new ItemStack[9];

if (choices.length == 1 && choices[0] instanceof MaterialChoice materialChoice) {
items[4] = new ItemStack(materialChoice.getChoices().get(0));
items[4] = StackResolver.of(materialChoice.getChoices().get(0));

if (materialChoice.getChoices().size() > 1) {
task.add(slots[4], materialChoice);
}
} else {
for (int i = 0; i < choices.length; i++) {
if (choices[i] instanceof MaterialChoice materialChoice) {
items[i] = new ItemStack(materialChoice.getChoices().get(0));
items[i] = StackResolver.of(materialChoice.getChoices().get(0));

if (materialChoice.getChoices().size() > 1) {
task.add(slots[i], materialChoice);
Expand Down
Loading
Loading