aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/world/item/FlintAndSteelItem.java.patch
blob: 9cc0efceefc70b6db0add5fd2dbf822438c5bac8 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
--- a/net/minecraft/world/item/FlintAndSteelItem.java
+++ b/net/minecraft/world/item/FlintAndSteelItem.java
@@ -14,57 +14,72 @@
 import net.minecraft.world.level.block.CampfireBlock;
 import net.minecraft.world.level.block.CandleBlock;
 import net.minecraft.world.level.block.CandleCakeBlock;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
 import net.minecraft.world.level.block.state.properties.BlockStateProperties;
 import net.minecraft.world.level.gameevent.GameEvent;
 
 public class FlintAndSteelItem extends Item {
 
-    public FlintAndSteelItem(Item.Properties item_properties) {
-        super(item_properties);
+    public FlintAndSteelItem(Item.Properties properties) {
+        super(properties);
     }
 
     @Override
-    @Override
-    public InteractionResult useOn(UseOnContext useoncontext) {
-        Player player = useoncontext.getPlayer();
-        Level level = useoncontext.getLevel();
-        BlockPos blockpos = useoncontext.getClickedPos();
-        BlockState blockstate = level.getBlockState(blockpos);
+    public InteractionResult useOn(UseOnContext context) {
+        Player entityhuman = context.getPlayer();
+        Level world = context.getLevel();
+        BlockPos blockposition = context.getClickedPos();
+        IBlockData iblockdata = world.getBlockState(blockposition);
 
-        if (!CampfireBlock.canLight(blockstate) && !CandleBlock.canLight(blockstate) && !CandleCakeBlock.canLight(blockstate)) {
-            BlockPos blockpos1 = blockpos.relative(useoncontext.getClickedFace());
+        if (!CampfireBlock.canLight(iblockdata) && !CandleBlock.canLight(iblockdata) && !CandleCakeBlock.canLight(iblockdata)) {
+            BlockPos blockposition1 = blockposition.relative(context.getClickedFace());
 
-            if (BaseFireBlock.canBePlacedAt(level, blockpos1, useoncontext.getHorizontalDirection())) {
-                level.playSound(player, blockpos1, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.getRandom().nextFloat() * 0.4F + 0.8F);
-                BlockState blockstate1 = BaseFireBlock.getState(level, blockpos1);
+            if (BaseFireBlock.canBePlacedAt(world, blockposition1, context.getHorizontalDirection())) {
+                // CraftBukkit start - Store the clicked block
+                if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition1, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) {
+                    context.getItemInHand().hurtAndBreak(1, entityhuman, (entityhuman1) -> {
+                        entityhuman1.broadcastBreakEvent(context.getHand());
+                    });
+                    return InteractionResult.PASS;
+                }
+                // CraftBukkit end
+                world.playSound(entityhuman, blockposition1, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F);
+                IBlockData iblockdata1 = BaseFireBlock.getState(world, blockposition1);
 
-                level.setBlock(blockpos1, blockstate1, 11);
-                level.gameEvent((Entity) player, GameEvent.BLOCK_PLACE, blockpos);
-                ItemStack itemstack = useoncontext.getItemInHand();
+                world.setBlock(blockposition1, iblockdata1, 11);
+                world.gameEvent((Entity) entityhuman, GameEvent.BLOCK_PLACE, blockposition);
+                ItemStack itemstack = context.getItemInHand();
 
-                if (player instanceof ServerPlayer) {
-                    CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) player, blockpos1, itemstack);
-                    itemstack.hurtAndBreak(1, player, (player1) -> {
-                        player1.broadcastBreakEvent(useoncontext.getHand());
+                if (entityhuman instanceof ServerPlayer) {
+                    CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer) entityhuman, blockposition1, itemstack);
+                    itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
+                        entityhuman1.broadcastBreakEvent(context.getHand());
                     });
                 }
 
-                return InteractionResult.sidedSuccess(level.isClientSide());
+                return InteractionResult.sidedSuccess(world.isClientSide());
             } else {
                 return InteractionResult.FAIL;
             }
         } else {
-            level.playSound(player, blockpos, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, level.getRandom().nextFloat() * 0.4F + 0.8F);
-            level.setBlock(blockpos, (BlockState) blockstate.setValue(BlockStateProperties.LIT, true), 11);
-            level.gameEvent((Entity) player, GameEvent.BLOCK_CHANGE, blockpos);
-            if (player != null) {
-                useoncontext.getItemInHand().hurtAndBreak(1, player, (player1) -> {
-                    player1.broadcastBreakEvent(useoncontext.getHand());
+            // CraftBukkit start - Store the clicked block
+            if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) {
+                context.getItemInHand().hurtAndBreak(1, entityhuman, (entityhuman1) -> {
+                    entityhuman1.broadcastBreakEvent(context.getHand());
                 });
+                return InteractionResult.PASS;
             }
+            // CraftBukkit end
+            world.playSound(entityhuman, blockposition, SoundEvents.FLINTANDSTEEL_USE, SoundSource.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F);
+            world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockStateProperties.LIT, true), 11);
+            world.gameEvent((Entity) entityhuman, GameEvent.BLOCK_CHANGE, blockposition);
+            if (entityhuman != null) {
+                context.getItemInHand().hurtAndBreak(1, entityhuman, (entityhuman1) -> {
+                    entityhuman1.broadcastBreakEvent(context.getHand());
+                });
+            }
 
-            return InteractionResult.sidedSuccess(level.isClientSide());
+            return InteractionResult.sidedSuccess(world.isClientSide());
         }
     }
 }