|
@@ -10,6 +10,8 @@ import me.km.utils.ReflectionUtils;
|
|
import net.minecraft.block.*;
|
|
import net.minecraft.block.*;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.command.arguments.BlockStateParser;
|
|
import net.minecraft.command.arguments.BlockStateParser;
|
|
|
|
+import net.minecraft.enchantment.EnchantmentHelper;
|
|
|
|
+import net.minecraft.enchantment.Enchantments;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.LivingEntity;
|
|
@@ -34,6 +36,7 @@ import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
import net.minecraft.world.IWorld;
|
|
import net.minecraft.world.IWorld;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.World;
|
|
|
|
+import net.minecraft.world.server.ServerWorld;
|
|
|
|
|
|
public class BlockCommands {
|
|
public class BlockCommands {
|
|
private static class Offset {
|
|
private static class Offset {
|
|
@@ -69,23 +72,27 @@ public class BlockCommands {
|
|
};
|
|
};
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
- private static void breakBlock(World w, Entity e, BlockPos pos) {
|
|
|
|
|
|
+ private static void breakBlock(ServerWorld w, Entity e, BlockPos pos) {
|
|
BlockState state = w.getBlockState(pos);
|
|
BlockState state = w.getBlockState(pos);
|
|
if(state.isAir(w, pos)) {
|
|
if(state.isAir(w, pos)) {
|
|
return;
|
|
return;
|
|
- } else {
|
|
|
|
- FluidState fState = w.getFluidState(pos);
|
|
|
|
- if(!(state.getBlock() instanceof AbstractFireBlock)) {
|
|
|
|
- w.playEvent(2001, pos, Block.getStateId(state));
|
|
|
|
- }
|
|
|
|
- TileEntity te = state.hasTileEntity() ? w.getTileEntity(pos) : null;
|
|
|
|
- ItemStack stack = ItemStack.EMPTY;
|
|
|
|
- if(e instanceof LivingEntity) {
|
|
|
|
- stack = ((LivingEntity) e).getActiveItemStack();
|
|
|
|
- }
|
|
|
|
- Block.spawnDrops(state, w, pos, te, e, stack);
|
|
|
|
- w.setBlockState(pos, fState.getBlockState(), 3, 512);
|
|
|
|
}
|
|
}
|
|
|
|
+ FluidState fState = w.getFluidState(pos);
|
|
|
|
+ if(!(state.getBlock() instanceof AbstractFireBlock)) {
|
|
|
|
+ w.playEvent(2001, pos, Block.getStateId(state));
|
|
|
|
+ }
|
|
|
|
+ TileEntity te = state.hasTileEntity() ? w.getTileEntity(pos) : null;
|
|
|
|
+ ItemStack stack = ItemStack.EMPTY;
|
|
|
|
+ if(e instanceof LivingEntity) {
|
|
|
|
+ stack = ((LivingEntity) e).getHeldItemMainhand();
|
|
|
|
+ }
|
|
|
|
+ int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
|
|
|
|
+ int silklevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack);
|
|
|
|
+ state.getBlock().dropXpOnBlockBreak(w, pos,
|
|
|
|
+ state.getExpDrop(w, pos, bonusLevel, silklevel));
|
|
|
|
+
|
|
|
|
+ Block.spawnDrops(state, w, pos, te, e, stack);
|
|
|
|
+ w.setBlockState(pos, fState.getBlockState(), 3, 512);
|
|
}
|
|
}
|
|
|
|
|
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
@@ -200,7 +207,7 @@ public class BlockCommands {
|
|
});
|
|
});
|
|
sm.registerConsumer("block.break", (sc, in) -> {
|
|
sm.registerConsumer("block.break", (sc, in) -> {
|
|
Location l = (Location) in[0].get(sc);
|
|
Location l = (Location) in[0].get(sc);
|
|
- breakBlock(l.getWorld(), (Entity) in[1].get(sc), l.getBlockPos());
|
|
|
|
|
|
+ breakBlock((ServerWorld) l.getWorld(), (Entity) in[1].get(sc), l.getBlockPos());
|
|
});
|
|
});
|
|
sm.registerConsumer("block.set", (sc, in) -> {
|
|
sm.registerConsumer("block.set", (sc, in) -> {
|
|
Location l = (Location) in[0].get(sc);
|
|
Location l = (Location) in[0].get(sc);
|