Skip to content

Commit

Permalink
new ItemStack => ItemStack.of
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Sep 25, 2024
1 parent af2d6f6 commit 2813710
Show file tree
Hide file tree
Showing 119 changed files with 867 additions and 867 deletions.
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 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,46 @@ public List<ItemStack> getDisplayRecipes() {
private List<ItemStack> getMachineRecipes() {
List<ItemStack> items = new LinkedList<>();

items.add(new ItemStack(Material.COBBLESTONE, 16));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.COBBLESTONE, 16));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.NETHERRACK, 16));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.NETHERRACK, 16));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.STONE, 12));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.STONE, 12));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.OBSIDIAN, 1));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.OBSIDIAN, 1));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.TERRACOTTA, 12));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.TERRACOTTA, 12));
items.add(ItemStack.of(Material.LAVA_BUCKET));

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

for (Material sapling : SlimefunTag.TERRACOTTA.getValues()) {
items.add(new ItemStack(sapling, 12));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(sapling, 12));
items.add(ItemStack.of(Material.LAVA_BUCKET));
}

items.add(new ItemStack(Material.BLACKSTONE, 8));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.BLACKSTONE, 8));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.BASALT, 12));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.BASALT, 12));
items.add(ItemStack.of(Material.LAVA_BUCKET));

if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
items.add(new ItemStack(Material.COBBLED_DEEPSLATE, 12));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.COBBLED_DEEPSLATE, 12));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.DEEPSLATE, 10));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.DEEPSLATE, 10));
items.add(ItemStack.of(Material.LAVA_BUCKET));

items.add(new ItemStack(Material.TUFF, 8));
items.add(new ItemStack(Material.LAVA_BUCKET));
items.add(ItemStack.of(Material.TUFF, 8));
items.add(ItemStack.of(Material.LAVA_BUCKET));
}

return items;
Expand Down
Loading

0 comments on commit 2813710

Please sign in to comment.