Browse Source

snuvi block break fix

Kajetan Johannes Hammerle 2 years ago
parent
commit
b1c6532641
1 changed files with 23 additions and 2 deletions
  1. 23 2
      src/main/java/me/km/snuviscript/commands/BlockCommands.java

+ 23 - 2
src/main/java/me/km/snuviscript/commands/BlockCommands.java

@@ -12,7 +12,9 @@ import net.minecraft.block.material.Material;
 import net.minecraft.command.arguments.BlockStateParser;
 import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityType;
+import net.minecraft.entity.LivingEntity;
 import net.minecraft.entity.player.ServerPlayerEntity;
+import net.minecraft.fluid.FluidState;
 import net.minecraft.fluid.Fluids;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.item.ItemStack;
@@ -66,6 +68,26 @@ public class BlockCommands {
             new Offset(0, 1, 1), // new Offset(1, 1, 1),
     };
 
+    @SuppressWarnings("deprecation")
+    private static void breakBlock(World w, Entity e, BlockPos pos) {
+        BlockState state = w.getBlockState(pos);
+        if(state.isAir(w, pos)) {
+            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);
+        }
+    }
+
     @SuppressWarnings({"unchecked", "rawtypes"})
     public static void registerFunctions(ScriptManager sm) {
         sm.registerFunction("block.gettag", (sc, in) -> BlockTags.getCollection()
@@ -178,8 +200,7 @@ public class BlockCommands {
         });
         sm.registerConsumer("block.break", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
-            Entity ent = (Entity) in[1].get(sc);
-            l.getWorld().destroyBlock(l.getBlockPos(), true, ent);
+            breakBlock(l.getWorld(), (Entity) in[1].get(sc), l.getBlockPos());
         });
         sm.registerConsumer("block.set", (sc, in) -> {
             Location l = (Location) in[0].get(sc);