-
Notifications
You must be signed in to change notification settings - Fork 18
/
RecipesEvents.java
51 lines (47 loc) · 1.94 KB
/
RecipesEvents.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
39
40
41
42
43
44
45
46
47
48
49
50
51
package knightminer.inspirations.recipes;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.library.recipe.cauldron.CauldronRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
@EventBusSubscriber(modid = Inspirations.modID, bus = Bus.FORGE)
public class RecipesEvents {
/*
* Event to handle cauldron clicking.
* Done though an event instead of the block so we can ensure it runs before other cauldron handlers, since we cancel for non-water.
*/
@SubscribeEvent(priority = EventPriority.HIGH)
static void clickCauldron(RightClickBlock event) {
if(!Config.moreCauldronBehavior.getAsBoolean()) {
return;
}
Player player = event.getPlayer();
if (player.isCrouching()) {
return;
}
// ignore non-cauldrons
Level world = event.getWorld();
BlockPos pos = event.getPos();
BlockState state = world.getBlockState(pos);
if (!(state.getBlock() instanceof AbstractCauldronBlock)) {
return;
}
// this is a good spot to hook in JSON eventually
InteractionHand hand = event.getHand();
InteractionResult result = CauldronRegistry.attemptOverride(state, world, pos, player, hand, event.getItemStack());
if (result.consumesAction()) {
event.setCanceled(true);
event.setCancellationResult(result);
}
}
}