Skip to content

Commit

Permalink
Replace ItemStack.copy() + ItemStack.setCount() with ItemStack.copyWi…
Browse files Browse the repository at this point in the history
…thCount()
  • Loading branch information
williewillus committed Oct 1, 2023
1 parent 4b55137 commit 175d606
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public static boolean buttonPressed(int keyCode, int scanCode) {
}

if (count > 0) {
ItemStack requested = stack.copy();
requested.setCount(count);
ItemStack requested = stack.copyWithCount(count);
ClientXplatAbstractions.INSTANCE.sendToServer(new IndexKeybindRequestPacket(requested));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public boolean addItem(@Nullable Player player, ItemStack stack, @Nullable Inter
for (int i = 0; i < inventorySize(); i++) {
if (getItemHandler().getItem(i).isEmpty()) {
did = true;
ItemStack stackToAdd = stack.copy();
stackToAdd.setCount(1);
ItemStack stackToAdd = stack.copyWithCount(1);
getItemHandler().setItem(i, stackToAdd);

if (player == null || !player.getAbilities().instabuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public boolean addItem(@Nullable Player player, ItemStack stack, @Nullable Inter
for (int i = 0; i < inventorySize(); i++) {
if (getItemHandler().getItem(i).isEmpty()) {
did = true;
ItemStack stackToAdd = stack.copy();
stackToAdd.setCount(1);
ItemStack stackToAdd = stack.copyWithCount(1);
getItemHandler().setItem(i, stackToAdd);

if (player == null || !player.getAbilities().instabuild) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ private static ItemStack[] flattenStacks(List<ItemStack> items) {
int j = 0;
for (ItemStack item : items) {
if (item.getCount() > 1) {
ItemStack temp = item.copy();
temp.setCount(1);
ItemStack temp = item.copyWithCount(1);
for (int count = 0; count < item.getCount(); count++) {
stacks[j] = temp.copy();
j++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Corpo

public void setRequestTarget(ItemStack stack) {
if (!stack.isEmpty() && !locked) {
ItemStack copy = stack.copy();
copy.setCount(1);
requestTarget = copy;
requestTarget = stack.copyWithCount(1);
updateCount();
if (!level.isClientSide) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public List<ItemStack> getFilter() {
if (orientation == dir) {
ItemStack stack = frame.getItem();
if (!stack.isEmpty()) {
ItemStack copy = stack.copy();
copy.setCount(rotationToStackSize[frame.getRotation()]);
ItemStack copy = stack.copyWithCount(rotationToStackSize[frame.getRotation()]);
filter.add(copy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ private int processFood(ItemStack food) {
return index;
}
}
ItemStack newestFood = food.copy();
newestFood.setCount(1);
ItemStack newestFood = food.copyWithCount(1);
lastFoods.add(0, newestFood);
if (lastFoods.size() >= getMaxStreak()) {
lastFoods.remove(lastFoods.size() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,8 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player

if (shouldInsert) {
if (playerHasLens) {
ItemStack toInsert = heldItem.copy();
toInsert.setCount(1);
ItemStack toInsert = heldItem.split(1);

heldItem.shrink(1);
if (!lens.isEmpty()) {
player.getInventory().placeItemBackInInventory(lens);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public NonNullList<ItemStack> getRemainingItems(@NotNull CraftingContainer inv)
}

int extract = Math.min(64, count);
ItemStack copy = s.copy();
copy.setCount(1);
ItemStack copy = s.copyWithCount(1);
BlackHoleTalismanItem.remove(copy, extract);
ItemNBTHelper.setBoolean(copy, BlackHoleTalismanItem.TAG_ACTIVE, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
return ItemStack.EMPTY;
}

ItemStack lensCopy = lens.copy();
ItemStack secondCopy = secondLens.copy();
lensCopy.setCount(1);
secondCopy.setCount(1);
ItemStack lensCopy = lens.copyWithCount(1);
ItemStack secondCopy = secondLens.copyWithCount(1);
lensItem.setCompositeLens(lensCopy, secondCopy);

return lensCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
return ItemStack.EMPTY;
}

ItemStack copy = attachableItem.copy();
copy.setCount(1);
ItemStack copy = attachableItem.copyWithCount(1);
attachable.setCosmeticItem(copy, ItemStack.EMPTY);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
}

if (lens.getItem() instanceof BasicLensItem) {
ItemStack lensCopy = lens.copy();
lensCopy.setCount(1);
ItemStack lensCopy = lens.copyWithCount(1);
LensItem.setLensColor(lensCopy, color);

return lensCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
if (stack.getItem() instanceof ManaBlasterItem) {
gun = stack;
} else if (stack.getItem() instanceof BasicLensItem) {
lens = stack.copy();
lens.setCount(1);
lens = stack.copyWithCount(1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
}
}

ItemStack gunCopy = gun.copy();
gunCopy.setCount(1);
ItemStack gunCopy = gun.copyWithCount(1);
ManaBlasterItem.setLens(gunCopy, ItemStack.EMPTY);

return gunCopy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
}
}

ItemStack copy = item.copy();
ItemStack copy = item.copyWithCount(1);
ItemNBTHelper.setBoolean(copy, ResoluteIvyItem.TAG_KEEP, true);
copy.setCount(1);
return copy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public ItemStack assemble(@NotNull CraftingContainer inv, @NotNull RegistryAcces
for (int i = 0; i < inv.getContainerSize(); i++) {
ItemStack stack = inv.getItem(i);
if (!stack.isEmpty() && stack.isEnchanted() && !stack.is(BotaniaItems.spellCloth)) {
stackToDisenchant = stack.copy();
stackToDisenchant.setCount(1);
stackToDisenchant = stack.copyWithCount(1);
break;
}
}
Expand Down Expand Up @@ -88,8 +87,7 @@ public RecipeSerializer<?> getSerializer() {
public NonNullList<ItemStack> getRemainingItems(@NotNull CraftingContainer inv) {
return RecipeUtils.getRemainingItemsSub(inv, s -> {
if (s.is(BotaniaItems.spellCloth)) {
ItemStack copy = s.copy();
copy.setCount(1);
ItemStack copy = s.copyWithCount(1);
copy.setDamageValue(copy.getDamageValue() + 1);
return copy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public ItemStack assemble(CraftingContainer inv, @NotNull RegistryAccess registr
}
}
if (!found.isEmpty()) {
found = found.copy();
found.setCount(1);
found = found.copyWithCount(1);
}
return found;
}
Expand All @@ -70,8 +69,7 @@ public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
for (int i = 0; i < inv.getContainerSize(); i++) {
ItemStack candidate = inv.getItem(i);
if (candidate.getItem() instanceof BasicLensItem basicLensItem) {
ItemStack newLens = candidate.copy();
newLens.setCount(1);
ItemStack newLens = candidate.copyWithCount(1);
basicLensItem.setCompositeLens(newLens, ItemStack.EMPTY);
remaining.set(i, newLens);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ protected static Collection<ItemStack> breakDownBigStack(ItemStack stack) {
List<ItemStack> stacks = new ArrayList<>();

int additionalStacks = stack.getCount() / stack.getMaxStackSize();
ItemStack fullStack = stack.copy();
fullStack.setCount(stack.getMaxStackSize());
ItemStack fullStack = stack.copyWithCount(stack.getMaxStackSize());
for (int i = 0; i < additionalStacks; i++) {
stacks.add(fullStack.copy());
}

int lastStackSize = stack.getCount() % stack.getMaxStackSize();
ItemStack lastStack = stack.copy();
lastStack.setCount(lastStackSize);
ItemStack lastStack = stack.copyWithCount(lastStackSize);
stacks.add(lastStack);

return stacks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ protected List<ItemStack> examineInventory(CorporeaRequest request, boolean doit
if (rem > 0) {
request.trackSatisfied(rem);

ItemStack copy = stack.copy();
copy.setCount(rem);
ItemStack copy = stack.copyWithCount(rem);
if (doit) {
if (getSpark().isCreative()) {
builder.add(copy);
Expand All @@ -69,7 +68,6 @@ protected List<ItemStack> examineInventory(CorporeaRequest request, boolean doit
getSpark().onItemExtracted(copy);
request.trackExtracted(rem);
} else {
copy.setCount(rem);
builder.add(copy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ protected List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit
request.trackSatisfied(rem);

if (doit) {
ItemStack copy = stackAt.copy();
copy.setCount(rem);
ItemStack copy = stackAt.copyWithCount(rem);
if (getSpark().isCreative()) {
builder.add(copy);
} else {
Expand All @@ -63,8 +62,7 @@ protected List<ItemStack> iterateOverSlots(CorporeaRequest request, boolean doit
getSpark().onItemExtracted(copy);
request.trackExtracted(rem);
} else {
ItemStack copy = stackAt.copy();
copy.setCount(rem);
ItemStack copy = stackAt.copyWithCount(rem);
builder.add(copy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ public static ItemStack removeFromInventory(Player player, Container inv, ItemSt
if (doit) {
ret = inv.removeItem(i, 1);
} else {
ret = invStack.copy();
ret.setCount(1);
ret = invStack.copyWithCount(1);
}
return ret;
}
Expand Down

0 comments on commit 175d606

Please sign in to comment.