Skip to content

Commit

Permalink
Update black well block w/ load safety
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces committed Apr 1, 2024
1 parent cc939e2 commit aff4713
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package moriyashiine.aylyth.common.block;

import com.google.common.base.Suppliers;
import moriyashiine.aylyth.common.registry.ModPotions;
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext;
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant;
import net.fabricmc.fabric.api.transfer.v1.item.PlayerInventoryStorage;
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -19,8 +19,11 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.function.Supplier;

@SuppressWarnings("UnstableApiUsage")
public class BlackWellBlock extends Block {
private static final ItemVariant BLIGHT_POTION = ItemVariant.of(PotionUtil.setPotion(new ItemStack(Items.POTION), ModPotions.BLIGHT_POTION));
private static final Supplier<ItemVariant> BLIGHT_POTION = Suppliers.memoize(() -> ItemVariant.of(PotionUtil.setPotion(new ItemStack(Items.POTION), ModPotions.BLIGHT_POTION)));

public BlackWellBlock(Settings settings) {
super(settings);
Expand All @@ -31,7 +34,7 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
ContainerItemContext storage = ContainerItemContext.forPlayerInteraction(player, hand);
try (Transaction transaction = Transaction.openOuter()) {
if (storage.getItemVariant().isOf(Items.GLASS_BOTTLE)) {
if (storage.exchange(BLIGHT_POTION, 1, transaction) == 1) {
if (storage.exchange(BLIGHT_POTION.get(), 1, transaction) == 1) {
transaction.commit();
}
world.playSound(null, pos, SoundEvents.ITEM_BOTTLE_FILL, SoundCategory.PLAYERS, 1.0f, 1.0f);
Expand Down

0 comments on commit aff4713

Please sign in to comment.