-
Notifications
You must be signed in to change notification settings - Fork 18
/
DyedBottleIntoDyeCauldronInteraction.java
38 lines (33 loc) · 1.58 KB
/
DyedBottleIntoDyeCauldronInteraction.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
38
package knightminer.inspirations.cauldrons.interaction.dye;
import knightminer.inspirations.library.MiscUtil;
import knightminer.inspirations.cauldrons.InspirationsCaudrons;
import knightminer.inspirations.cauldrons.block.entity.DyeCauldronBlockEntity;
import knightminer.inspirations.cauldrons.interaction.IncreaseLayerCauldronInteraction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.LayeredCauldronBlock;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
/** Increases the amount of dye in a dyed cauldron, mixing the color if different */
public class DyedBottleIntoDyeCauldronInteraction extends IncreaseLayerCauldronInteraction {
@Nullable
private final Integer color;
protected DyedBottleIntoDyeCauldronInteraction(ItemLike bottle, @Nullable Integer color) {
super(bottle, LayeredCauldronBlock.LEVEL, 3);
this.color = color;
}
public DyedBottleIntoDyeCauldronInteraction(@Nullable Integer color) {
this(Items.GLASS_BOTTLE, color);
}
@Override
protected void afterSetBlock(BlockState state, Level level, BlockPos pos, ItemStack stack) {
DyeCauldronBlockEntity cauldron = InspirationsCaudrons.dyeCauldronEntity.getBlockEntity(level, pos);
if (cauldron != null) {
int newColor = this.color != null ? this.color : MiscUtil.getColor(stack);
cauldron.setColor(MiscUtil.addColors(newColor, 1, cauldron.getColor(), state.getValue(this.prop)));
}
}
}