-
Notifications
You must be signed in to change notification settings - Fork 18
/
PotionIntoPotionCauldron.java
37 lines (32 loc) · 1.46 KB
/
PotionIntoPotionCauldron.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package knightminer.inspirations.cauldrons.interaction.potion;
import knightminer.inspirations.cauldrons.InspirationsCaudrons;
import knightminer.inspirations.cauldrons.block.entity.PotionCauldronBlockEntity;
import knightminer.inspirations.cauldrons.interaction.AbstractModifyCauldronInteraction;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.stats.Stats;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
import static net.minecraft.world.level.block.LayeredCauldronBlock.LEVEL;
/** Logic to dump a potion into an empty cauldron */
public class PotionIntoPotionCauldron extends AbstractModifyCauldronInteraction {
public PotionIntoPotionCauldron(ItemLike container) {
super(container, SoundEvents.BOTTLE_EMPTY, Stats.FILL_CAULDRON);
}
@Nullable
@Override
protected BlockState getNewState(BlockState oldState, Level level, BlockPos pos, ItemStack filledStack) {
int potionLevel = oldState.getValue(LEVEL);
if (potionLevel < 4) {
PotionCauldronBlockEntity cauldron = InspirationsCaudrons.potionCauldronEntity.getBlockEntity(level, pos);
if (cauldron != null && cauldron.getPotion() == PotionUtils.getPotion(filledStack)) {
return oldState.setValue(LEVEL, potionLevel + 1);
}
}
return null;
}
}