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
Open
Show file tree
Hide file tree
Changes from 5 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
31 changes: 13 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<packaging>jar</packaging>

<!-- Project Info -->
<description>Slimefun is a Spigot/Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
<description>Slimefun is a Paper plugin that simulates a modpack-like atmosphere by adding over 500 new items and recipes to your Minecraft Server.</description>
<url>https://github.com/Slimefun/Slimefun4</url>

<properties>
Expand All @@ -29,8 +29,8 @@
<maven.compiler.testTarget>21</maven.compiler.testTarget>

<!-- Spigot properties -->
<spigot.version>1.20.6</spigot.version>
<spigot.javadocs>https://hub.spigotmc.org/javadocs/spigot/</spigot.javadocs>
<paper.version>1.21.1</paper.version>
<paper.javadocs>https://hub.spigotmc.org/javadocs/spigot/</paper.javadocs>

<!-- Default settings for sonarcloud.io -->
<sonar.projectKey>Slimefun_Slimefun4</sonar.projectKey>
Expand Down Expand Up @@ -367,6 +367,13 @@
<scope>compile</scope>
</dependency>

<!-- Paper -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.21.1-R0.1-SNAPSHOT</version>
</dependency>

<!-- Testing dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -387,9 +394,10 @@
</dependency>
<!-- This needs to be before Spigot because MockBukkit will fail otherwise. -->
<dependency>
<groupId>com.github.MockBukkit</groupId>
<groupId>com.github.seeseemelk</groupId>
<artifactId>MockBukkit</artifactId>
<version>c7cc678834</version>
<!-- <version>3.123.0</version> -->
<version>dev-3fec4e7b</version>
<scope>test</scope>

<exclusions>
Expand All @@ -401,13 +409,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- Override Spigot with Paper tests as a CommandMap ctor which MockBukkit uses only exists on Paper but not in Spigot -->
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<!-- Third party plugin integrations / soft dependencies -->
<dependency>
Expand Down Expand Up @@ -515,12 +516,6 @@
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public enum MinecraftVersion {
*/
MINECRAFT_1_20_5(20, 5, "1.20.5+"),

/**
* 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.multiversion.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.multiversion.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 All @@ -307,7 +308,7 @@ public void lock() {

@Override
public ItemStack clone() {
return new SlimefunItemStack(id, this);
return new SlimefunItemStack(id, super.clone());
}

@Override
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.multiversion.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.multiversion.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.multiversion.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.multiversion.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.multiversion.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.multiversion.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.multiversion.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.multiversion.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.multiversion.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
Loading