Files
2018-07-20 01:14:44 +08:00

91 lines
4.8 KiB
Diff

--- ../src-base/minecraft/net/minecraftforge/event/world/BlockEvent.java
+++ ../src-work/minecraft/net/minecraftforge/event/world/BlockEvent.java
@@ -19,12 +19,14 @@
package net.minecraftforge.event.world;
+import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.block.state.IBlockState;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Enchantments;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
@@ -39,6 +41,7 @@
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import com.google.common.collect.ImmutableList;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
import javax.annotation.Nullable;
@@ -123,17 +126,23 @@
{
super(world, pos, state);
this.player = player;
-
- if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
+ // Svarka start - handle event on bukkit side
+ org.bukkit.event.block.BlockBreakEvent bukkitEvent = CraftEventFactory.callBlockBreakEvent(world, pos, state, (EntityPlayerMP) player);
+ /* if (bukkitEvent.isCancelled() || state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
(state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
+ */
+ if(bukkitEvent.isCancelled())
{
- this.exp = 0;
+ //this.exp = 0;
+ this.setCanceled(true);
}
else
{
- int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
- this.exp = state.getBlock().getExpDrop(state, world, pos, bonusLevel);
+ /*int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
+ this.exp = state.getBlock().getExpDrop(state, world, pos, bonusLevel);*/
+ this.exp = bukkitEvent.getExpToDrop();
}
+ // Svarka end
}
public EntityPlayer getPlayer()
@@ -191,9 +200,10 @@
this.placedBlock = blockSnapshot.getCurrentBlock();
this.placedAgainst = placedAgainst;
this.hand = hand;
- if (DEBUG)
- {
- System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ][Hand: %s]\n", getPlacedBlock(), placedAgainst, getItemInHand(), player, hand);
+ org.bukkit.craftbukkit.block.CraftBlockState blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(super.world, super.pos.getX(), super.pos.getY(), super.pos.getZ());
+ org.bukkit.event.block.BlockPlaceEvent bukkitEvent = CraftEventFactory.callBlockPlaceEvent(super.world, player, hand , blockstate, super.pos.getX(), super.pos.getY(), super.pos.getZ());
+ if (bukkitEvent.isCancelled() || !bukkitEvent.canBuild()) {
+ this.setCanceled(true);
}
}
@@ -228,10 +238,18 @@
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, IBlockState placedAgainst, EntityPlayer player, @Nullable EnumHand hand) {
super(blockSnapshots.get(0), placedAgainst, player, hand);
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
- if (DEBUG)
- {
- System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, this.getItemInHand(), player);
+
+ List<org.bukkit.block.BlockState> blocks = new ArrayList<org.bukkit.block.BlockState>();
+ for (int i=0; i<this.blockSnapshots.size(); i++) {
+ BlockSnapshot block = this.blockSnapshots.get(i);
+ org.bukkit.craftbukkit.block.CraftBlockState blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(super.getWorld(), block.getPos().getX(), block.getPos().getY(), block.getPos().getZ());
+ blocks.add(blockstate);
}
+
+ org.bukkit.event.block.BlockPlaceEvent bukkitEvent = CraftEventFactory.callBlockMultiPlaceEvent(super.getWorld(), player, hand , blocks, super.getPos().getX(), super.getPos().getY(), super.getPos().getZ());
+ if (bukkitEvent.isCancelled() || !bukkitEvent.canBuild()) {
+ this.setCanceled(true);
+ }
}
/**