Skip to content

Commit

Permalink
Implements BlockPhysicsEvent and make every implementation call super (
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon committed Dec 17, 2018
1 parent 0fd2db6 commit 506ad22
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
if (!canPlaceAt(null, me, BlockFace.DOWN)) {
me.breakNaturally();
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/glowstone/block/blocktype/BlockDispenser.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change
}

@Override
public void updatePhysics(GlowBlock block) {
GlowBlock up = block.getRelative(BlockFace.UP);
boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered()
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
GlowBlock up = me.getRelative(BlockFace.UP);
boolean powered = me.isBlockPowered() || me.isBlockIndirectlyPowered()
|| up.isBlockPowered() || up.isBlockIndirectlyPowered();

GlowBlockState state = block.getState();
GlowBlockState state = me.getState();
MaterialData data = state.getData();
if (!(data instanceof Dispenser)) {
return;
Expand All @@ -100,7 +101,7 @@ public void updatePhysics(GlowBlock block) {
new BukkitRunnable() {
@Override
public void run() {
trigger(block);
trigger(me);
}
}.runTaskLater(null, 4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void onNearBlockChanged(GlowBlock me, BlockFace face, GlowBlock other, Ma

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
Block below = me.getRelative(BlockFace.DOWN);
if (!supportingBlock(below.getType())) {
//Simulates real Minecraft delay on block fall
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/glowstone/block/blocktype/BlockLamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
boolean powered = me.isBlockPowered() || me.isBlockIndirectlyPowered();

if (powered != (me.getType() == Material.REDSTONE_LAMP_ON)) {
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/net/glowstone/block/blocktype/BlockLiquid.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,49 +227,50 @@ private void mix(GlowBlock target, BlockFace direction, Material flowingMaterial
}

@Override
public void updatePhysics(GlowBlock block) {
if (isStationary(block.getType())) {
block.setType(getOpposite(block.getType()), block.getData(), false);
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
if (isStationary(me.getType())) {
me.setType(getOpposite(me.getType()), me.getData(), false);
}
if (Byte.compare(block.getState().getRawData(), STRENGTH_SOURCE) != 0) {
if (Byte.compare(me.getState().getRawData(), STRENGTH_SOURCE) != 0) {
BlockFace[] faces = {UP, NORTH, EAST, SOUTH, WEST};
boolean connected = false;
int count = 0;
for (BlockFace face : faces) {
if (block.getRelative(face).getType() == block.getType()) {
if (me.getRelative(face).getType() == me.getType()) {
if (count < 2 && face != UP
&& Byte.compare(block.getRelative(face).getState().getRawData(),
&& Byte.compare(me.getRelative(face).getState().getRawData(),
STRENGTH_SOURCE) == 0) {
count++;
}
if (!connected && face == UP
|| Byte.compare(block.getRelative(face).getState().getRawData(),
block.getState().getRawData()) < 0) {
|| Byte.compare(me.getRelative(face).getState().getRawData(),
me.getState().getRawData()) < 0) {
connected = true;
if (block.getWorld().getServer().getClassicWater()) {
block.getState().setRawData(STRENGTH_SOURCE);
if (me.getWorld().getServer().getClassicWater()) {
me.getState().setRawData(STRENGTH_SOURCE);
}
}
if (block.getWorld().getServer().getClassicWater()
&& Byte.compare(block.getRelative(face).getState().getRawData(),
if (me.getWorld().getServer().getClassicWater()
&& Byte.compare(me.getRelative(face).getState().getRawData(),
STRENGTH_SOURCE) == 0) {
block.getRelative(face).setType(Material.AIR);
me.getRelative(face).setType(Material.AIR);
}
}
}
if (!connected) {
block.setType(Material.AIR);
me.setType(Material.AIR);
return;
}
if (count == 2) {
block.getState().setRawData(STRENGTH_SOURCE);
me.getState().setRawData(STRENGTH_SOURCE);
return;
}
}
if (!(Byte.compare(block.getState().getRawData(),
isWater(block.getType()) || block.getBiome() == Biome.HELL ? STRENGTH_MIN_WATER
: STRENGTH_MIN_LAVA) == 0) || block.getRelative(DOWN).getType() == Material.AIR) {
calculateFlow(block);
if (!(Byte.compare(me.getState().getRawData(),
isWater(me.getType()) || me.getBiome() == Biome.HELL ? STRENGTH_MIN_WATER
: STRENGTH_MIN_LAVA) == 0) || me.getRelative(DOWN).getType() == Material.AIR) {
calculateFlow(me);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
BlockFace attachedTo = getAttachedFace(me);
if (attachedTo == null) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/glowstone/block/blocktype/BlockNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
if (me.isBlockIndirectlyPowered()) {
((NoteBlock) me.getState()).play();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/glowstone/block/blocktype/BlockTnt.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void onNearBlockChanged(GlowBlock block, BlockFace face, GlowBlock change

@Override
public void updatePhysics(GlowBlock me) {
super.updatePhysics(me);
if (me.isBlockIndirectlyPowered()) {
igniteBlock(me, false, null);
}
Expand Down

0 comments on commit 506ad22

Please sign in to comment.