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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package re.jag.parquet.dispenser;
import net.minecraft.block.*;
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
import net.minecraft.block.dispenser.ItemDispenserBehavior;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.block.entity.DispenserBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.BlockTags;
import net.minecraft.tag.FluidTags;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
public class GlassBottleDispenserBehavior extends FallibleItemDispenserBehavior {
private final ItemDispenserBehavior fallbackBehavior = new ItemDispenserBehavior();
private ItemStack tryPutFilledBottle(BlockPointer pointer, ItemStack emptyBottleStack, ItemStack filledBottleStack) {
emptyBottleStack.decrement(1);
if (emptyBottleStack.isEmpty()) {
pointer.getWorld().emitGameEvent((Entity)null, GameEvent.FLUID_PICKUP, pointer.getPos());
return filledBottleStack.copy();
} else {
if (((DispenserBlockEntity)pointer.getBlockEntity()).addToFirstFreeSlot(filledBottleStack.copy()) < 0) {
this.fallbackBehavior.dispense(pointer, filledBottleStack.copy());
}
return emptyBottleStack;
}
}
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
//this.success = false;
World world = pointer.getWorld();
BlockPos block_pos = pointer.getPos().offset((Direction)pointer.getBlockState().get(DispenserBlock.FACING));
BlockState state = world.getBlockState(block_pos);
Block block = state.getBlock();
// Original Behavior
if (state.isIn(BlockTags.BEEHIVES, (bstate) -> {
return bstate.contains(BeehiveBlock.HONEY_LEVEL);
}) && (Integer)state.get(BeehiveBlock.HONEY_LEVEL) >= 5) {
((BeehiveBlock)state.getBlock()).takeHoney(world, state, block_pos, (PlayerEntity)null, BeehiveBlockEntity.BeeState.BEE_RELEASED);
this.setSuccess(true);
return this.tryPutFilledBottle(pointer, stack, new ItemStack(Items.HONEY_BOTTLE));
} else if (world.getFluidState(block_pos).isIn(FluidTags.WATER)) {
this.setSuccess(true);
return this.tryPutFilledBottle(pointer, stack, PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER));
}
// New behavior
if (block instanceof LeveledCauldronBlock) {
/* TODO Check for Water */
LeveledCauldronBlock.decrementFluidLevel(state, world, block_pos);
this.setSuccess(true);
return tryPutFilledBottle(pointer, stack, PotionUtil.setPotion( new ItemStack(Items.POTION), Potions.WATER ) );
}
return super.dispenseSilently(pointer, stack);
}
}
|