Skip to content

Commit

Permalink
to item or is item?!
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom committed Aug 26, 2024
1 parent 1f27fb8 commit 1d013df
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static List<List<ItemStack>> compactInputs(final List<List<ItemStack>> i
final IngredientStacks newIngredient = new IngredientStacks(ingredient);
// also ignore the build tool as an ingredient, since colony crafters don't require it.
// (see RecipeStorage.calculateCleanedInput() for why)
if (!newIngredient.getStacks().isEmpty() && newIngredient.getStacks().get(0).getItem() == buildTool.get()) continue;
if (!newIngredient.getStacks().isEmpty() && newIngredient.getStacks().get(0).is(buildTool)) continue;

final IngredientStacks existing = ingredients.get(newIngredient);
if (existing == null)
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/minecolonies/api/crafting/ItemStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.JsonObject;
import com.minecolonies.api.util.ItemStackUtils;
import com.minecolonies.api.util.Utils;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -293,6 +294,16 @@ public Item getItem()
return stack.getItem();
}

/**
* Compares whether this storage holds given item
*
* @return true if item matches
*/
public boolean is(final Holder<Item> item)
{
return stack.is(item);
}

/**
* Getter for the damage value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void processInputsAndTools(@Nullable final List<ItemStack> secOutputs)
{
for (final ItemStack secOutput : secOutputs)
{
if (!secOutput.isEmpty() && secOutput.getItem() != ModItems.buildTool.get())
if (!secOutput.isEmpty() && secOutput.is(ModItems.buildTool))
{
this.secondaryOutputs.add(secOutput);
}
Expand All @@ -196,7 +196,7 @@ private void processInputsAndTools(@Nullable final List<ItemStack> secOutputs)
for (final ItemStorage input : input)
{
ItemStorage inputItem = input;
if (inputItem.isEmpty() || inputItem.getItem() == ModItems.buildTool.get())
if (inputItem.isEmpty() || inputItem.is(ModItems.buildTool))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public final class ItemStackUtils
/**
* Predicate to check for compost items.
*/
public static final Predicate<ItemStack> IS_COMPOST = stack -> !stack.isEmpty() && stack.getItem() == ModItems.compost.get();
public static final Predicate<ItemStack> IS_COMPOST = stack -> !stack.isEmpty() && stack.is(ModItems.compost);

/**
* Private constructor to hide the implicit one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public WindowSupplyStory(final BlockPos pos, final String type, final ItemStack
final Random random = new Random(currentComponent.randomKey());
final List<Holder.Reference<Biome>> biomes = mc.level.registryAccess().registryOrThrow(Registries.BIOME).holders().toList();
final Holder<Biome> biome = biomes.get(random.nextInt(biomes.size()));
if (stack.getItem() == ModItems.supplyCamp.get())
if (stack.is(ModItems.supplyCamp))
{
story.add(Component.literal(ColonyStoryListener.pickRandom(ColonyStoryListener.supplyCampStories, biome, random)));
}
Expand All @@ -90,7 +90,7 @@ public WindowSupplyStory(final BlockPos pos, final String type, final ItemStack
story.add(Component.translatable("com.minecolonies.core.gui.supplies.guide", Component.translatable(stack.getItem().getDescriptionId())));
story.add(Component.empty());

if (stack.getItem() == ModItems.supplyCamp.get())
if (stack.is(ModItems.supplyCamp))
{
story.add(Component.translatable("com.minecolonies.core.gui.supplycamp.guide"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public boolean isEnabled(final WorldEventContext ctx)
{
return RenderingCache.hasBlueprint("blueprint") &&
MinecoloniesAPIProxy.getInstance().getConfig().getClient().neighborbuildingrendering.get() &&
ctx.mainHandItem.getItem() == buildTool.get();
ctx.mainHandItem.is(buildTool);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ColonyBorderRenderer

static void render(final WorldEventContext ctx)
{
if (ctx.mainHandItem.getItem() != ModItems.buildTool.get() || !ctx.hasNearestColony())
if (!ctx.mainHandItem.is(ModItems.buildTool) || !ctx.hasNearestColony())
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GuardTowerRallyBannerRenderer
*/
static void render(final WorldEventContext ctx)
{
if (ctx.mainHandItem.getItem() != ModItems.bannerRallyGuards.get())
if (!ctx.mainHandItem.is(ModItems.bannerRallyGuards))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public boolean isRecipeCompatible(@NotNull final IGenericRecipe recipe)
if (!super.isRecipeCompatible(recipe))
return false;

return recipe.getPrimaryOutput().getItem() == ModItems.magicpotion.get();
return recipe.getPrimaryOutput().is(ModItems.magicpotion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BuildingEnchanter extends AbstractBuilding
public BuildingEnchanter(@NotNull final IColony c, final BlockPos l)
{
super(c, l);
keepX.put((stack) -> stack.getItem() == ModItems.ancientTome.get(), new Tuple<>(STACKSIZE, true));
keepX.put((stack) -> stack.is(ModItems.ancientTome), new Tuple<>(STACKSIZE, true));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class BuildingFlorist extends AbstractBuilding
public BuildingFlorist(@NotNull final IColony c, final BlockPos l)
{
super(c, l);
keepX.put((stack) -> stack.getItem() == ModItems.compost.get(), new Tuple<>(STACKSIZE, true));
keepX.put((stack) -> stack.is(ModItems.compost), new Tuple<>(STACKSIZE, true));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static List<LootDrop> entryToDrops(@NotNull final HolderLookup.Provider
modifier = result.getB();
}
modifier = adjustModifier(modifier, conditions);
if (stack.getItem().equals(ModItems.adventureToken.get()))
if (stack.is(ModItems.adventureToken))
{
final List<LootDrop> mobDrops = expandAdventureToken(provider, stack);
for (final LootDrop drop : mobDrops)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void doAttack(final LivingEntity target)
boolean gotMaterial = false;
BiPredicate<LivingEntity, MobEffect> predicate;
if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DRUID_USE_POTIONS) > 0
&& InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.getItem() == ModItems.magicpotion.get()))
&& InventoryUtils.hasItemInItemHandler(user.getInventoryCitizen(), item -> item.is(ModItems.magicpotion)))
{
gotMaterial = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ protected void atBuildingActions()
{
// Mistletoes and water bottles
InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(building,
item -> item.getItem() == ModItems.magicpotion.get(),
item -> item.is(ModItems.magicpotion),
32,
worker.getInventoryCitizen());

if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.getItem() == ModItems.magicpotion.get()) < 8)
if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), item -> item.is(ModItems.magicpotion)) < 8)
{
checkIfRequestForItemExistOrCreateAsync(ModItems.magicpotion.toStack(), 16, 8);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ else if (farmField.getFieldStage() == FarmField.Stage.EMPTY && checkIfShouldExec
*/
private boolean isCompost(final ItemStack itemStack)
{
if (itemStack.getItem() == ModItems.compost.get())
if (itemStack.is(ModItems.compost))
{
return true;
}
return itemStack.getItem() == Items.BONE_MEAL;
return itemStack.is(Items.BONE_MEAL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ public class EntityAIWorkEnchanter extends AbstractEntityAICrafting<JobEnchanter
/**
* Predicate to define an ancient tome which can be enchanted.
*/
private static final Predicate<ItemStack> IS_ANCIENT_TOME = item -> !item.isEmpty() && item.getItem() == ModItems.ancientTome.get();
private static final Predicate<ItemStack> IS_ANCIENT_TOME = item -> !item.isEmpty() && item.is(ModItems.ancientTome);

/**
* Predicate to define an ancient tome which can be enchanted.
*/
private static final Predicate<ItemStack> IS_BOOK = item -> !item.isEmpty() && item.getItem() == Items.BOOK;
private static final Predicate<ItemStack> IS_BOOK = item -> !item.isEmpty() && item.is(Items.BOOK);

/**
* Min distance to drain from citizen.
Expand Down Expand Up @@ -177,7 +177,7 @@ protected IAIState decide()
for (final IToken<?> token : craftingModule.getRecipes())
{
final IRecipeStorage storage = IColonyManager.getInstance().getRecipeManager().getRecipes().get(token);
if (storage != null && !storage.getInput().isEmpty() && storage.getInput().get(0).getItem() == ModItems.ancientTome.get() && craftingModule.isDisabled(token))
if (storage != null && !storage.getInput().isEmpty() && storage.getInput().get(0).is(ModItems.ancientTome) && craftingModule.isDisabled(token))
{
ancientTomeCraftingDisabled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ private boolean updateVisualData()
this.setItemSlot(EquipmentSlot.HEAD, ModItems.santaHat.toStack());
}
}
else if (!hat.isEmpty() && hat.getItem() == ModItems.santaHat.get())
else if (!hat.isEmpty() && hat.is(ModItems.santaHat))
{
this.setItemSlot(EquipmentSlot.HEAD, ItemStackUtils.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ protected void registerRecipes(@NotNull final Consumer<CustomRecipeBuilder> cons
recipe(ENCHANTER, MODULE_CUSTOM, "scroll_tp")
.inputs(List.of(new ItemStorage(new ItemStack(Items.PAPER, 3)),
new ItemStorage(new ItemStack(Items.COMPASS)),
new ItemStorage(new ItemStack(com.ldtteam.structurize.items.ModItems.buildTool.get()))))
new ItemStorage(com.ldtteam.structurize.items.ModItems.buildTool.toStack())))
.result(ModItems.scrollColonyTP.toStack(3))
.showTooltip(true)
.build(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ protected void onExecute(final IPayloadContext ctxIn, final ServerPlayer player)
{
stackSlot = i;
}
else if (player.getInventory().getItem(i).getItem() == ModItems.buildTool.get())
else if (player.getInventory().getItem(i).is(ModItems.buildTool))
{
buildToolSlot = i;
}
}

for (int i = 9; i < player.getInventory().getContainerSize(); i++)
{
if (player.getInventory().getItem(i).getItem() == ModItems.buildTool.get())
if (player.getInventory().getItem(i).is(ModItems.buildTool))
{
buildToolSlot = i;
}
Expand All @@ -84,7 +84,7 @@ else if (player.getInventory().getItem(i).getItem() == ModItems.buildTool.get())
if (stackSlot != -1 && buildToolSlot != -1)
{
player.getInventory().setItem(buildToolSlot, player.getInventory().getItem(stackSlot).copy());
player.getInventory().setItem(stackSlot, new ItemStack(ModItems.buildTool.get(), 1));
player.getInventory().setItem(stackSlot, ModItems.buildTool.toStack());
}
}
}

0 comments on commit 1d013df

Please sign in to comment.