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 2 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 @@ -92,13 +92,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 ItemStack.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(ItemStack.of(Material.AIR));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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, ItemStack.of(type), consumer);
}

public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
Expand Down Expand Up @@ -109,7 +109,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, ItemStack.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 +284,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 ItemStack.of(Material.PLAYER_HEAD);
}

PlayerSkin skin = PlayerSkin.fromBase64(getTexture(id, texture));
Expand All @@ -307,7 +307,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 @@ -113,7 +113,7 @@ public RecipeType(NamespacedKey key, ItemStack item) {
}

public RecipeType(MinecraftRecipe<?> recipe) {
this.item = new ItemStack(recipe.getMachine());
this.item = ItemStack.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 @@ -47,7 +47,7 @@ public Optional<ItemStack> getDisplayItem(Player p, ItemStack guide) {

if (current.isPresent()) {
SlimefunGuideMode selectedMode = current.get();
ItemStack item = new ItemStack(Material.AIR);
ItemStack item = ItemStack.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 @@ -42,7 +42,7 @@ public void add(int amount) {

private void initializeItem() {
if (this.item instanceof ItemStackWrapper) {
ItemStack copy = new ItemStack(item.getType(), item.getAmount());
ItemStack copy = ItemStack.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 @@ -315,7 +315,7 @@ protected void loadEmbeddedLanguages() {

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

Language language = getLanguage(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,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] = ItemStack.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] = ItemStack.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 @@ -69,13 +69,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 -> ItemStack.of(Material.WHEAT, random.nextInt(2) + 1);
case POTATOES -> ItemStack.of(Material.POTATO, random.nextInt(3) + 1);
case CARROTS -> ItemStack.of(Material.CARROT, random.nextInt(3) + 1);
case BEETROOTS -> ItemStack.of(Material.BEETROOT, random.nextInt(3) + 1);
case COCOA -> ItemStack.of(Material.COCOA_BEANS, random.nextInt(3) + 1);
case NETHER_WART -> ItemStack.of(Material.NETHER_WART, random.nextInt(3) + 1);
case SWEET_BERRY_BUSH -> ItemStack.of(Material.SWEET_BERRIES, random.nextInt(3) + 1);
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,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(ItemStack.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(ItemStack.of(Material.BONE), 10);
fishingLoot.add(ItemStack.of(Material.STRING), 10);
fishingLoot.add(ItemStack.of(Material.INK_SAC), 8);
fishingLoot.add(ItemStack.of(Material.KELP), 6);
fishingLoot.add(ItemStack.of(Material.STICK), 5);
fishingLoot.add(ItemStack.of(Material.ROTTEN_FLESH), 3);
fishingLoot.add(ItemStack.of(Material.LEATHER), 2);
fishingLoot.add(ItemStack.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(ItemStack.of(Material.SADDLE), 1);
fishingLoot.add(ItemStack.of(Material.NAME_TAG), 1);
fishingLoot.add(ItemStack.of(Material.NAUTILUS_SHELL), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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 = ItemStack.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 @@ -595,27 +595,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, ItemStack.of(Material.COAL_BLOCK)));
registerFuelType(new MachineFuel(45, ItemStack.of(Material.BLAZE_ROD)));
registerFuelType(new MachineFuel(70, ItemStack.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, ItemStack.of(Material.COAL)));
registerFuelType(new MachineFuel(8, ItemStack.of(Material.CHARCOAL)));
registerFuelType(new MachineFuel(1, ItemStack.of(Material.BAMBOO)));

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

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

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

int fuelLevel = fuel.getTicks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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 = ItemStack.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 +179,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(), ItemStack.of(saplingType));
block.setType(Material.AIR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ private ItemStack getLeftoverItem(@Nonnull ItemStack item) {
return switch (type) {
case WATER_BUCKET,
LAVA_BUCKET,
MILK_BUCKET -> new ItemStack(Material.BUCKET);
MILK_BUCKET -> ItemStack.of(Material.BUCKET);
case DRAGON_BREATH,
POTION,
HONEY_BOTTLE -> new ItemStack(Material.GLASS_BOTTLE);
HONEY_BOTTLE -> ItemStack.of(Material.GLASS_BOTTLE);
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,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] = ItemStack.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] = ItemStack.of(materialChoice.getChoices().get(0));

if (materialChoice.getChoices().size() > 1) {
task.add(slots[i], materialChoice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ private List<ItemStack> getMachineRecipes() {
List<ItemStack> items = new LinkedList<>();

for (Material leave : Tag.LEAVES.getValues()) {
items.add(new ItemStack(leave, 8));
items.add(new ItemStack(Material.DIRT));
items.add(ItemStack.of(leave, 8));
items.add(ItemStack.of(Material.DIRT));
}

for (Material sapling : Tag.SAPLINGS.getValues()) {
items.add(new ItemStack(sapling, 8));
items.add(new ItemStack(Material.DIRT));
items.add(ItemStack.of(sapling, 8));
items.add(ItemStack.of(Material.DIRT));
}

items.add(new ItemStack(Material.STONE, 4));
items.add(new ItemStack(Material.NETHERRACK));
items.add(ItemStack.of(Material.STONE, 4));
items.add(ItemStack.of(Material.NETHERRACK));

items.add(new ItemStack(Material.SAND, 2));
items.add(new ItemStack(Material.SOUL_SAND));
items.add(ItemStack.of(Material.SAND, 2));
items.add(ItemStack.of(Material.SOUL_SAND));

items.add(new ItemStack(Material.WHEAT, 4));
items.add(new ItemStack(Material.NETHER_WART));
items.add(ItemStack.of(Material.WHEAT, 4));
items.add(ItemStack.of(Material.NETHER_WART));

return items;
}
Expand Down
Loading
Loading