Skip to content

Commit

Permalink
fixed piston input power, plugin unknown dependency message
Browse files Browse the repository at this point in the history
  • Loading branch information
Creeperface01 committed Aug 18, 2019
1 parent 538c819 commit 69ea148
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,11 @@ public boolean dispatchCommand(CommandSender sender, String commandLine) throws
if (!this.isPrimaryThread()) {
getLogger().warning("Command Dispatched Async: " + commandLine);

This comment has been minimized.

Copy link
@SupremeMortal

SupremeMortal Aug 18, 2019

Member

This is a test branch. You shouldn't be using it in production.

getLogger().warning("Please notify author of plugin causing this execution to fix this bug!", new Throwable());
// TODO: We should sync the command to the main thread too!

this.scheduler.scheduleTask(null, () -> dispatchCommand(sender, commandLine));
return true;
}

if (sender == null) {
throw new ServerException("CommandSender is not valid");
}
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/cn/nukkit/block/BlockPistonBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import cn.nukkit.level.GlobalBlockPalette;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockVector3;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.network.protocol.LevelSoundEventPacket;
Expand Down Expand Up @@ -129,7 +130,7 @@ private boolean checkState(Boolean isPowered) {
}

if (isPowered && !isExtended()) {
if ((new BlocksCalculator(true)).canMove()) {
if (new BlocksCalculator(true).canMove()) {
if (!this.doMove(true)) {
return false;
}
Expand Down Expand Up @@ -164,7 +165,17 @@ private boolean isPowered() {
BlockFace face = getBlockFace();

for (BlockFace side : BlockFace.values()) {
if (side != face && this.level.isSidePowered(this.getLocation().getSide(side), side)) {
if (side == face) {
continue;
}

Block b = this.getSide(side);

if (b.getId() == Block.REDSTONE_WIRE && b.getDamage() > 0) {
return true;
}

if (this.level.isSidePowered(b, side)) {
return true;
}
}
Expand All @@ -191,7 +202,7 @@ private boolean doMove(boolean extending) {
if (!calculator.canMove()) {
return false;
} else {
List<Vector3> attached = Collections.emptyList();
List<BlockVector3> attached = Collections.emptyList();

if (this.sticky || extending) {
List<Block> destroyBlocks = calculator.getBlocksToDestroy();
Expand All @@ -201,7 +212,7 @@ private boolean doMove(boolean extending) {
}

List<Block> newBlocks = calculator.getBlocksToMove();
attached = newBlocks.stream().map(b -> b.add(0)).collect(Collectors.toList());
attached = newBlocks.stream().map(Vector3::asBlockVector3).collect(Collectors.toList());

BlockFace side = extending ? direction : direction.getOpposite();

Expand All @@ -228,7 +239,6 @@ private boolean doMove(boolean extending) {
blockEntity.saveNBT();

CompoundTag t = new CompoundTag(blockEntity.namedTag.getTags());
t.print(System.out);

nbt.putCompound("movingEntity", t);
blockEntity.close();
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/cn/nukkit/block/BlockRedstoneWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ public int getWeakPower(BlockFace side) {
} else if (side == BlockFace.UP) {
return power;
} else {
EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class);
EnumSet<BlockFace> faces = EnumSet.noneOf(BlockFace.class);

for (BlockFace face : Plane.HORIZONTAL) {
if (this.isPowerSourceAt(face)) {
enumset.add(face);
faces.add(face);
}
}

if (side.getAxis().isHorizontal() && enumset.isEmpty()) {
if (side.getAxis().isHorizontal() && faces.isEmpty()) {
return power;
} else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) {
} else if (faces.contains(side) && !faces.contains(side.rotateYCCW()) && !faces.contains(side.rotateY())) {
return power;
} else {
return 0;
Expand Down Expand Up @@ -283,6 +283,9 @@ protected static boolean canConnectTo(Block block, BlockFace side) {
} else if (BlockRedstoneDiode.isDiode(block)) {
BlockFace face = ((BlockRedstoneDiode) block).getFacing();
return face == side || face.getOpposite() == side;
} else if (block instanceof BlockPistonBase) {
// return ((BlockPistonBase) block).getBlockFace() != side.getOpposite();
return true;
} else {
return block.isPowerSource() && side != null;
}
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockAir;
import cn.nukkit.block.BlockID;
import cn.nukkit.level.Level;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.math.BlockVector3;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.nbt.tag.IntTag;
import cn.nukkit.nbt.tag.ListTag;
Expand All @@ -28,7 +29,7 @@ public class BlockEntityPistonArm extends BlockEntitySpawnable {
public boolean sticky;
public int state;
public int newState = 1;
public List<Vector3> attachedBlocks;
public List<BlockVector3> attachedBlocks;
public boolean powered;

public BlockEntityPistonArm(FullChunk chunk, CompoundTag nbt) {
Expand Down Expand Up @@ -66,7 +67,7 @@ protected void initBlockEntity() {
ListTag blocks = namedTag.getList("AttachedBlocks", IntTag.class);
if (blocks != null && blocks.size() > 0) {
for (int i = 0; i < blocks.size(); i += 3) {
this.attachedBlocks.add(new Vector3(
this.attachedBlocks.add(new BlockVector3(
((IntTag) blocks.get(i)).data,
((IntTag) blocks.get(i + 1)).data,
((IntTag) blocks.get(i + 1)).data
Expand All @@ -92,7 +93,7 @@ private void moveCollidedEntities() {
// }

BlockFace pushDir = this.extending ? facing : facing.getOpposite();
for (Vector3 pos : this.attachedBlocks) {
for (BlockVector3 pos : this.attachedBlocks) {
BlockEntity blockEntity = this.level.getBlockEntity(pos.getSide(pushDir));

if (blockEntity instanceof BlockEntityMovingBlock) {
Expand All @@ -101,7 +102,7 @@ private void moveCollidedEntities() {
}
}

public void move(boolean extending, List<Vector3> attachedBlocks) {
public void move(boolean extending, List<BlockVector3> attachedBlocks) {
this.extending = extending;
this.lastProgress = this.progress = extending ? 0 : 1;
this.state = this.newState = extending ? 1 : 3;
Expand Down Expand Up @@ -133,7 +134,7 @@ public boolean onUpdate() {

BlockFace pushDir = this.extending ? facing : facing.getOpposite();

for (Vector3 pos : this.attachedBlocks) {
for (BlockVector3 pos : this.attachedBlocks) {
BlockEntity movingBlock = this.level.getBlockEntity(pos.getSide(pushDir));

if (movingBlock instanceof BlockEntityMovingBlock) {
Expand All @@ -150,6 +151,8 @@ public boolean onUpdate() {
blockEntity.putInt("z", movingBlock.getFloorZ());
BlockEntity.createBlockEntity(blockEntity.getString("id"), this.level.getChunk(movingBlock.getChunkX(), movingBlock.getChunkZ()), blockEntity);
}

moved.onUpdate(Level.BLOCK_UPDATE_NORMAL);
}
}

Expand Down Expand Up @@ -202,10 +205,10 @@ public CompoundTag getSpawnCompound() {

private ListTag<IntTag> getAttachedBlocks() {
ListTag<IntTag> attachedBlocks = new ListTag<>("AttachedBlocks");
for (Vector3 block : this.attachedBlocks) {
attachedBlocks.add(new IntTag("", block.getFloorX()));
attachedBlocks.add(new IntTag("", block.getFloorY()));
attachedBlocks.add(new IntTag("", block.getFloorZ()));
for (BlockVector3 block : this.attachedBlocks) {
attachedBlocks.add(new IntTag("", block.x));
attachedBlocks.add(new IntTag("", block.y));
attachedBlocks.add(new IntTag("", block.z));
}

return attachedBlocks;
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cn.nukkit.entity.item;

import cn.nukkit.Server;
import cn.nukkit.block.BlockTNT;
import cn.nukkit.entity.EntityExplosive;
import cn.nukkit.entity.data.IntEntityData;
Expand Down Expand Up @@ -53,7 +52,6 @@ public void initEntity() {
public boolean onUpdate(int currentTick) {
this.timing.startTiming();

// Todo: Check why the TNT doesn't want to tick
if (activated || fuse < 80) {
int tickDiff = currentTick - lastUpdate;

Expand All @@ -71,8 +69,6 @@ public boolean onUpdate(int currentTick) {
}
kill();
}

Server.getInstance().getLogger().info("Debug:" + fuse);
}

this.timing.stopTiming();
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/cn/nukkit/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,6 @@ public Item useItemOn(Vector3 vector, Item item, BlockFace face, float fx, float
return null;
}

MainLogger.getLogger().info("place: " + block + " loc: " + block.getLocationHash());
if (player != null) {
if (!player.isCreative()) {
item.setCount(item.getCount() - 1);
Expand Down Expand Up @@ -2227,10 +2226,14 @@ public Map<Integer, ChunkLoader> getLoaders() {
}

public BlockEntity getBlockEntity(Vector3 pos) {
FullChunk chunk = this.getChunk((int) pos.x >> 4, (int) pos.z >> 4, false);
return getBlockEntity(pos.asBlockVector3());
}

public BlockEntity getBlockEntity(BlockVector3 pos) {
FullChunk chunk = this.getChunk(pos.x >> 4, pos.z >> 4, false);

if (chunk != null) {
return chunk.getTile((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f);
return chunk.getTile(pos.x & 0x0f, pos.y & 0xff, pos.z & 0x0f);
}

return null;
Expand Down Expand Up @@ -3345,7 +3348,15 @@ public boolean isSidePowered(Vector3 pos, BlockFace face) {
}

public int getRedstonePower(Vector3 pos, BlockFace face) {
Block block = this.getBlock(pos);
Block block;

if (pos instanceof Block) {
block = (Block) pos;
pos = pos.add(0);
} else {
block = this.getBlock(pos);
}

return block.isNormalBlock() ? this.getStrongPower(pos) : block.getWeakPower(face);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/level/format/anvil/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public byte[] toFastBinary() {
if (section instanceof EmptyChunkSection) {
continue;
}
CompoundTag s = new CompoundTag(null);
CompoundTag s = new CompoundTag();
s.putByte("Y", section.getY());
s.putByteArray("Blocks", section.getIdArray());
s.putByteArray("Data", section.getDataArray());
Expand Down Expand Up @@ -358,7 +358,7 @@ public byte[] toBinary() {
if (section instanceof EmptyChunkSection) {
continue;
}
CompoundTag s = new CompoundTag(null);
CompoundTag s = new CompoundTag();
s.putByte("Y", (section.getY()));
s.putByteArray("Blocks", section.getIdArray());
s.putByteArray("Data", section.getDataArray());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/plugin/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public Map<String, Plugin> loadPlugins(File dictionary, List<String> newLoaders,
dependencies.get(name).remove(dependency);
} else if (!plugins.containsKey(dependency)) {
this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit" +
".plugin.loadError", new String[]{name, "%nukkit.plugin.unknownDependency"}));
".plugin.loadError", name, "%nukkit.plugin.unknownDependency", dependency));
break;
}
}
Expand Down

0 comments on commit 69ea148

Please sign in to comment.