3
0
KCauldronX/patches/net/minecraftforge/event/world/BlockEvent.java.patch

95 lines
4.5 KiB
Diff
Raw Permalink Normal View History

2015-03-22 17:38:04 +00:00
--- ../src-base/minecraft/net/minecraftforge/event/world/BlockEvent.java
+++ ../src-work/minecraft/net/minecraftforge/event/world/BlockEvent.java
2017-07-04 06:29:35 +00:00
@@ -3,17 +3,23 @@
import java.util.ArrayList;
import java.util.List;
2015-03-22 17:38:04 +00:00
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CraftBlockState;
2015-03-22 17:38:04 +00:00
+// Cauldron start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockMultiPlaceEvent;
+
2017-07-04 06:29:35 +00:00
import com.google.common.collect.ImmutableList;
+import cc.capture.type.CaptureBlock;
import cpw.mods.fml.common.eventhandler.Cancelable;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.block.Block;
-import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.init.Blocks;
2015-03-22 17:38:04 +00:00
+import net.minecraft.entity.player.EntityPlayerMP;
+// Cauldron end
2017-07-04 06:29:35 +00:00
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
-import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.util.BlockSnapshot;
2015-03-22 17:38:04 +00:00
2017-07-04 06:29:35 +00:00
public class BlockEvent extends Event {
@@ -80,17 +86,18 @@
2015-03-22 17:38:04 +00:00
super(x, y, z, world, block, blockMetadata);
this.player = player;
- if (block == null || !ForgeHooks.canHarvestBlock(block, player, blockMetadata) || // Handle empty block or player unable to break block scenario
- block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player)) // If the block is being silk harvested, the exp dropped is 0
+ // Cauldron start - handle event on bukkit side
+ org.bukkit.event.block.BlockBreakEvent bukkitEvent = CraftEventFactory.callBlockBreakEvent(world, x, y, z, block, blockMetadata,
+ (EntityPlayerMP) player);
+ if (bukkitEvent.isCancelled())
{
- this.exp = 0;
+ this.setCanceled(true);
}
else
{
- int meta = block.getDamageValue(world, x, y, z);
- int bonusLevel = EnchantmentHelper.getFortuneModifier(player);
- this.exp = block.getExpDrop(world, meta, bonusLevel);
+ this.exp = bukkitEvent.getExpToDrop();
}
+ // Cauldron end
}
public EntityPlayer getPlayer()
2017-07-04 06:29:35 +00:00
@@ -140,6 +147,21 @@
2015-03-25 05:24:42 +00:00
this.blockSnapshot = blockSnapshot;
this.placedBlock = blockSnapshot.getCurrentBlock();
this.placedAgainst = placedAgainst;
+ // Cauldron start - handle event on bukkit side
+ if(!(this instanceof MultiPlaceEvent)){
+ org.bukkit.craftbukkit.block.CraftBlockState blockstate=new org.bukkit.craftbukkit.block.CraftBlockState(blockSnapshot);
+ org.bukkit.event.block.BlockPlaceEvent bukkitEvent=CraftEventFactory.callBlockPlaceEvent(super.world,player,blockstate,super.x,super.y,
+ super.z);
+ if(bukkitEvent.isCancelled()||!bukkitEvent.canBuild()){
+ this.setCanceled(true);
+ }
2017-07-04 06:29:35 +00:00
+
+ CaptureBlock tCapture=world.mCapture.getLastBlockCapture();
+ if(tCapture!=null&&tCapture.mEnable){
+ tCapture.addCheckedBlock(world,x,y,z);
+ }
2015-03-25 05:24:42 +00:00
+ }
+ // Cauldron end
if (DEBUG)
{
System.out.printf("Created PlaceEvent - [PlacedBlock: %s ][PlacedAgainst: %s ][ItemStack: %s ][Player: %s ]\n", placedBlock, placedAgainst, player.getCurrentEquippedItem(), player);
2017-07-04 06:29:35 +00:00
@@ -160,7 +182,17 @@
public MultiPlaceEvent(List<BlockSnapshot> blockSnapshots, Block placedAgainst, EntityPlayer player) {
super(blockSnapshots.get(0), placedAgainst, player);
+
this.blockSnapshots = ImmutableList.copyOf(blockSnapshots);
+
+ //bukkit start
+ ArrayList<BlockState> tStates=new ArrayList<BlockState>(blockSnapshots.size());
+ for(BlockSnapshot sSnapshot : this.blockSnapshots){
+ tStates.add(new CraftBlockState(sSnapshot));
+ }
+ BlockMultiPlaceEvent tEvent=CraftEventFactory.callBlockMultiPlaceEvent(super.world,player,tStates,super.x,super.y,super.z);
+ this.setCanceled(tEvent.isCancelled()||!tEvent.canBuild());
+
if (DEBUG)
{
System.out.printf("Created MultiPlaceEvent - [PlacedAgainst: %s ][ItemInHand: %s ][Player: %s ]\n", placedAgainst, this.itemInHand, player);