Skip to content

Commit

Permalink
feat: add dispenser behavior for Gastric Acid Buckets
Browse files Browse the repository at this point in the history
Closes: #147
  • Loading branch information
Elenterius committed Sep 13, 2024
1 parent 14fb027 commit 8a29d19
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import com.github.elenterius.biomancy.network.ModNetworkHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockSource;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.core.dispenser.OptionalDispenseItemBehavior;
import net.minecraft.world.item.DispensibleContainerItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
Expand Down Expand Up @@ -93,6 +97,24 @@ protected ItemStack execute(BlockSource source, ItemStack stack) {
return stack;
}
});

DispenserBlock.registerBehavior(ModItems.ACID_BUCKET.get(), new DefaultDispenseItemBehavior() {
private final DefaultDispenseItemBehavior defaultDispenseItemBehavior = new DefaultDispenseItemBehavior();

public ItemStack execute(BlockSource source, ItemStack stack) {
BlockPos pos = source.getPos().relative(source.getBlockState().getValue(DispenserBlock.FACING));
Level level = source.getLevel();

DispensibleContainerItem containerItem = (DispensibleContainerItem) stack.getItem();
if (containerItem.emptyContents(null, level, pos, null, stack)) {
containerItem.checkExtraContent(null, level, stack, pos);
return new ItemStack(Items.BUCKET);
}
else {
return defaultDispenseItemBehavior.dispense(source, stack);
}
}
});
}

}

0 comments on commit 8a29d19

Please sign in to comment.