Forráskód Böngészése

pistons remove sugar cane, bamboo and cactus blocks

Kajetan Johannes Hammerle 4 éve
szülő
commit
c12a241f3b
1 módosított fájl, 26 hozzáadás és 0 törlés
  1. 26 0
      src/main/java/me/km/events/CustomEventCaller.java

+ 26 - 0
src/main/java/me/km/events/CustomEventCaller.java

@@ -4,9 +4,16 @@ import java.util.HashMap;
 import java.util.LinkedList;
 import me.hammerle.snuviscript.code.Script;
 import me.km.scheduler.SnuviScheduler;
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockState;
+import net.minecraft.block.Blocks;
+import net.minecraft.block.PistonBlockStructureHelper;
 import net.minecraft.server.MinecraftServer;
+import net.minecraft.util.math.BlockPos;
 import net.minecraftforge.eventbus.api.SubscribeEvent;
 import net.minecraftforge.event.TickEvent;
+import net.minecraftforge.event.world.PistonEvent;
+import net.minecraftforge.event.world.PistonEvent.PistonMoveType;
 
 public class CustomEventCaller {
     private final HashMap<Integer, PlayerMoveData> moveData = new HashMap<>();
@@ -62,4 +69,23 @@ public class CustomEventCaller {
             }
         }
     }
+
+    @SubscribeEvent
+    public void onPiston(PistonEvent e) {
+        if(e.getPistonMoveType() != PistonMoveType.EXTEND) {
+            return;
+        }
+        PistonBlockStructureHelper helper = e.getStructureHelper();
+        if(helper == null) {
+            return;
+        }
+        helper.canMove();
+        for(BlockPos pos : helper.getBlocksToDestroy()) {
+            BlockState state = e.getWorld().getBlockState(pos);
+            Block b = state.getBlock();
+            if(b == Blocks.CACTUS || b == Blocks.BAMBOO || b == Blocks.SUGAR_CANE) {
+                e.getWorld().setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
+            }
+        }
+    }
 }