From 69ea148fc0124c5ead282653c1e28cd73ce63359 Mon Sep 17 00:00:00 2001 From: CreeperFace Date: Sun, 18 Aug 2019 16:50:17 +0200 Subject: [PATCH] fixed piston input power, plugin unknown dependency message --- src/main/java/cn/nukkit/Server.java | 5 +++- .../java/cn/nukkit/block/BlockPistonBase.java | 20 ++++++++++++---- .../cn/nukkit/block/BlockRedstoneWire.java | 11 +++++---- .../blockentity/BlockEntityPistonArm.java | 23 +++++++++++-------- .../nukkit/entity/item/EntityMinecartTNT.java | 4 ---- src/main/java/cn/nukkit/level/Level.java | 19 +++++++++++---- .../cn/nukkit/level/format/anvil/Chunk.java | 4 ++-- .../java/cn/nukkit/plugin/PluginManager.java | 2 +- 8 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/main/java/cn/nukkit/Server.java b/src/main/java/cn/nukkit/Server.java index b5db3136613..5eeb3d291d0 100644 --- a/src/main/java/cn/nukkit/Server.java +++ b/src/main/java/cn/nukkit/Server.java @@ -744,8 +744,11 @@ public boolean dispatchCommand(CommandSender sender, String commandLine) throws if (!this.isPrimaryThread()) { getLogger().warning("Command Dispatched Async: " + commandLine); 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"); } diff --git a/src/main/java/cn/nukkit/block/BlockPistonBase.java b/src/main/java/cn/nukkit/block/BlockPistonBase.java index 64be0c5a547..fa54d022976 100644 --- a/src/main/java/cn/nukkit/block/BlockPistonBase.java +++ b/src/main/java/cn/nukkit/block/BlockPistonBase.java @@ -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; @@ -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; } @@ -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; } } @@ -191,7 +202,7 @@ private boolean doMove(boolean extending) { if (!calculator.canMove()) { return false; } else { - List attached = Collections.emptyList(); + List attached = Collections.emptyList(); if (this.sticky || extending) { List destroyBlocks = calculator.getBlocksToDestroy(); @@ -201,7 +212,7 @@ private boolean doMove(boolean extending) { } List 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(); @@ -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(); diff --git a/src/main/java/cn/nukkit/block/BlockRedstoneWire.java b/src/main/java/cn/nukkit/block/BlockRedstoneWire.java index b3f10b312f2..2d058a000aa 100644 --- a/src/main/java/cn/nukkit/block/BlockRedstoneWire.java +++ b/src/main/java/cn/nukkit/block/BlockRedstoneWire.java @@ -241,17 +241,17 @@ public int getWeakPower(BlockFace side) { } else if (side == BlockFace.UP) { return power; } else { - EnumSet enumset = EnumSet.noneOf(BlockFace.class); + EnumSet 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; @@ -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; } diff --git a/src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java b/src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java index 24cafd3c1a2..79d23fd4f8e 100644 --- a/src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java +++ b/src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java @@ -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; @@ -28,7 +29,7 @@ public class BlockEntityPistonArm extends BlockEntitySpawnable { public boolean sticky; public int state; public int newState = 1; - public List attachedBlocks; + public List attachedBlocks; public boolean powered; public BlockEntityPistonArm(FullChunk chunk, CompoundTag nbt) { @@ -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 @@ -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) { @@ -101,7 +102,7 @@ private void moveCollidedEntities() { } } - public void move(boolean extending, List attachedBlocks) { + public void move(boolean extending, List attachedBlocks) { this.extending = extending; this.lastProgress = this.progress = extending ? 0 : 1; this.state = this.newState = extending ? 1 : 3; @@ -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) { @@ -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); } } @@ -202,10 +205,10 @@ public CompoundTag getSpawnCompound() { private ListTag getAttachedBlocks() { ListTag 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; diff --git a/src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java b/src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java index 8cad3fb0c05..8b55c069964 100644 --- a/src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java +++ b/src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java @@ -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; @@ -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; @@ -71,8 +69,6 @@ public boolean onUpdate(int currentTick) { } kill(); } - - Server.getInstance().getLogger().info("Debug:" + fuse); } this.timing.stopTiming(); diff --git a/src/main/java/cn/nukkit/level/Level.java b/src/main/java/cn/nukkit/level/Level.java index b3ba0aa4187..73169167621 100644 --- a/src/main/java/cn/nukkit/level/Level.java +++ b/src/main/java/cn/nukkit/level/Level.java @@ -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); @@ -2227,10 +2226,14 @@ public Map 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; @@ -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); } diff --git a/src/main/java/cn/nukkit/level/format/anvil/Chunk.java b/src/main/java/cn/nukkit/level/format/anvil/Chunk.java index 722271bff00..b0d15b46e28 100644 --- a/src/main/java/cn/nukkit/level/format/anvil/Chunk.java +++ b/src/main/java/cn/nukkit/level/format/anvil/Chunk.java @@ -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()); @@ -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()); diff --git a/src/main/java/cn/nukkit/plugin/PluginManager.java b/src/main/java/cn/nukkit/plugin/PluginManager.java index fab4bc5c7a1..dfb694a51cf 100644 --- a/src/main/java/cn/nukkit/plugin/PluginManager.java +++ b/src/main/java/cn/nukkit/plugin/PluginManager.java @@ -244,7 +244,7 @@ public Map loadPlugins(File dictionary, List 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; } }