Skip to content

Commit

Permalink
Broken pistons implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Creeperface01 committed Aug 16, 2019
1 parent ebd0365 commit 538c819
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 154 deletions.
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,7 @@ private void registerBlockEntities() {
BlockEntity.registerBlockEntity(BlockEntity.BANNER, BlockEntityBanner.class);
BlockEntity.registerBlockEntity(BlockEntity.MUSIC, BlockEntityMusic.class);
BlockEntity.registerBlockEntity(BlockEntity.DISPENSER, BlockEntityDispenser.class);
BlockEntity.registerBlockEntity(BlockEntity.MOVING_BLOCK, BlockEntityMovingBlock.class);
}

public boolean isNetherAllowed() {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ public static void init() {
list[GLOWING_OBSIDIAN] = BlockObsidianGlowing.class; //246
//list[NETHER_REACTOR] = BlockNetherReactor.class; //247 Should not be removed

//TODO: list[PISTON_EXTENSION] = BlockPistonExtension.class; //250

list[MOVING_BLOCK] = BlockMoving.class; //250
list[OBSERVER] = BlockObserver.class; //251

for (int id = 0; id < 256; id++) {
Expand Down Expand Up @@ -691,6 +690,10 @@ public Block getSide(BlockFace face) {
}

public Block getSide(BlockFace face, int step) {
if (step == 0) {
return this;
}

if (this.isValid()) {
if (step == 1) {
return this.getLevel().getBlock((int) x + face.getXOffset(), (int) y + face.getYOffset(), (int) z + face.getZOffset());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockID.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public interface BlockID {
int GLOWING_OBSIDIAN = 246;
int NETHER_REACTOR = 247; //Should not be removed

int PISTON_EXTENSION = 250;
int MOVING_BLOCK = 250;

int OBSERVER = 251;
}
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/block/BlockLever.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public boolean onActivate(Item item, Player player) {
Block target = this.getSide(face.getOpposite());
target.onUpdate(Level.BLOCK_UPDATE_REDSTONE);

this.level.updateAroundRedstone(this.getLocation(), isPowerOn() ? face.getOpposite() : null);
this.level.updateAroundRedstone(target.getLocation(), isPowerOn() ? face : null);
return true;
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/cn/nukkit/block/BlockMoving.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cn.nukkit.block;

import cn.nukkit.item.Item;

public class BlockMoving extends Block {

public BlockMoving() {
this(0);
}

public BlockMoving(int meta) {
super();
}

@Override
public String getName() {
return "MovingBlock";
}

@Override
public int getId() {
return BlockID.MOVING_BLOCK;
}

@Override
public boolean canBePushed() {
return false;
}

@Override
public boolean isBreakable(Item item) {
return false;
}
}
Loading

0 comments on commit 538c819

Please sign in to comment.