Skip to content

Commit 69ea148

Browse files
committed
fixed piston input power, plugin unknown dependency message
1 parent 538c819 commit 69ea148

File tree

8 files changed

+57
-31
lines changed

8 files changed

+57
-31
lines changed

src/main/java/cn/nukkit/Server.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,11 @@ public boolean dispatchCommand(CommandSender sender, String commandLine) throws
744744
if (!this.isPrimaryThread()) {
745745
getLogger().warning("Command Dispatched Async: " + commandLine);
746746
getLogger().warning("Please notify author of plugin causing this execution to fix this bug!", new Throwable());
747-
// TODO: We should sync the command to the main thread too!
747+
748+
this.scheduler.scheduleTask(null, () -> dispatchCommand(sender, commandLine));
749+
return true;
748750
}
751+
749752
if (sender == null) {
750753
throw new ServerException("CommandSender is not valid");
751754
}

src/main/java/cn/nukkit/block/BlockPistonBase.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import cn.nukkit.level.GlobalBlockPalette;
1111
import cn.nukkit.level.Level;
1212
import cn.nukkit.math.BlockFace;
13+
import cn.nukkit.math.BlockVector3;
1314
import cn.nukkit.math.Vector3;
1415
import cn.nukkit.nbt.tag.CompoundTag;
1516
import cn.nukkit.network.protocol.LevelSoundEventPacket;
@@ -129,7 +130,7 @@ private boolean checkState(Boolean isPowered) {
129130
}
130131

131132
if (isPowered && !isExtended()) {
132-
if ((new BlocksCalculator(true)).canMove()) {
133+
if (new BlocksCalculator(true).canMove()) {
133134
if (!this.doMove(true)) {
134135
return false;
135136
}
@@ -164,7 +165,17 @@ private boolean isPowered() {
164165
BlockFace face = getBlockFace();
165166

166167
for (BlockFace side : BlockFace.values()) {
167-
if (side != face && this.level.isSidePowered(this.getLocation().getSide(side), side)) {
168+
if (side == face) {
169+
continue;
170+
}
171+
172+
Block b = this.getSide(side);
173+
174+
if (b.getId() == Block.REDSTONE_WIRE && b.getDamage() > 0) {
175+
return true;
176+
}
177+
178+
if (this.level.isSidePowered(b, side)) {
168179
return true;
169180
}
170181
}
@@ -191,7 +202,7 @@ private boolean doMove(boolean extending) {
191202
if (!calculator.canMove()) {
192203
return false;
193204
} else {
194-
List<Vector3> attached = Collections.emptyList();
205+
List<BlockVector3> attached = Collections.emptyList();
195206

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

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

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

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

230241
CompoundTag t = new CompoundTag(blockEntity.namedTag.getTags());
231-
t.print(System.out);
232242

233243
nbt.putCompound("movingEntity", t);
234244
blockEntity.close();

src/main/java/cn/nukkit/block/BlockRedstoneWire.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,17 @@ public int getWeakPower(BlockFace side) {
241241
} else if (side == BlockFace.UP) {
242242
return power;
243243
} else {
244-
EnumSet<BlockFace> enumset = EnumSet.noneOf(BlockFace.class);
244+
EnumSet<BlockFace> faces = EnumSet.noneOf(BlockFace.class);
245245

246246
for (BlockFace face : Plane.HORIZONTAL) {
247247
if (this.isPowerSourceAt(face)) {
248-
enumset.add(face);
248+
faces.add(face);
249249
}
250250
}
251251

252-
if (side.getAxis().isHorizontal() && enumset.isEmpty()) {
252+
if (side.getAxis().isHorizontal() && faces.isEmpty()) {
253253
return power;
254-
} else if (enumset.contains(side) && !enumset.contains(side.rotateYCCW()) && !enumset.contains(side.rotateY())) {
254+
} else if (faces.contains(side) && !faces.contains(side.rotateYCCW()) && !faces.contains(side.rotateY())) {
255255
return power;
256256
} else {
257257
return 0;
@@ -283,6 +283,9 @@ protected static boolean canConnectTo(Block block, BlockFace side) {
283283
} else if (BlockRedstoneDiode.isDiode(block)) {
284284
BlockFace face = ((BlockRedstoneDiode) block).getFacing();
285285
return face == side || face.getOpposite() == side;
286+
} else if (block instanceof BlockPistonBase) {
287+
// return ((BlockPistonBase) block).getBlockFace() != side.getOpposite();
288+
return true;
286289
} else {
287290
return block.isPowerSource() && side != null;
288291
}

src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import cn.nukkit.block.Block;
44
import cn.nukkit.block.BlockAir;
55
import cn.nukkit.block.BlockID;
6+
import cn.nukkit.level.Level;
67
import cn.nukkit.level.format.FullChunk;
78
import cn.nukkit.math.BlockFace;
8-
import cn.nukkit.math.Vector3;
9+
import cn.nukkit.math.BlockVector3;
910
import cn.nukkit.nbt.tag.CompoundTag;
1011
import cn.nukkit.nbt.tag.IntTag;
1112
import cn.nukkit.nbt.tag.ListTag;
@@ -28,7 +29,7 @@ public class BlockEntityPistonArm extends BlockEntitySpawnable {
2829
public boolean sticky;
2930
public int state;
3031
public int newState = 1;
31-
public List<Vector3> attachedBlocks;
32+
public List<BlockVector3> attachedBlocks;
3233
public boolean powered;
3334

3435
public BlockEntityPistonArm(FullChunk chunk, CompoundTag nbt) {
@@ -66,7 +67,7 @@ protected void initBlockEntity() {
6667
ListTag blocks = namedTag.getList("AttachedBlocks", IntTag.class);
6768
if (blocks != null && blocks.size() > 0) {
6869
for (int i = 0; i < blocks.size(); i += 3) {
69-
this.attachedBlocks.add(new Vector3(
70+
this.attachedBlocks.add(new BlockVector3(
7071
((IntTag) blocks.get(i)).data,
7172
((IntTag) blocks.get(i + 1)).data,
7273
((IntTag) blocks.get(i + 1)).data
@@ -92,7 +93,7 @@ private void moveCollidedEntities() {
9293
// }
9394

9495
BlockFace pushDir = this.extending ? facing : facing.getOpposite();
95-
for (Vector3 pos : this.attachedBlocks) {
96+
for (BlockVector3 pos : this.attachedBlocks) {
9697
BlockEntity blockEntity = this.level.getBlockEntity(pos.getSide(pushDir));
9798

9899
if (blockEntity instanceof BlockEntityMovingBlock) {
@@ -101,7 +102,7 @@ private void moveCollidedEntities() {
101102
}
102103
}
103104

104-
public void move(boolean extending, List<Vector3> attachedBlocks) {
105+
public void move(boolean extending, List<BlockVector3> attachedBlocks) {
105106
this.extending = extending;
106107
this.lastProgress = this.progress = extending ? 0 : 1;
107108
this.state = this.newState = extending ? 1 : 3;
@@ -133,7 +134,7 @@ public boolean onUpdate() {
133134

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

136-
for (Vector3 pos : this.attachedBlocks) {
137+
for (BlockVector3 pos : this.attachedBlocks) {
137138
BlockEntity movingBlock = this.level.getBlockEntity(pos.getSide(pushDir));
138139

139140
if (movingBlock instanceof BlockEntityMovingBlock) {
@@ -150,6 +151,8 @@ public boolean onUpdate() {
150151
blockEntity.putInt("z", movingBlock.getFloorZ());
151152
BlockEntity.createBlockEntity(blockEntity.getString("id"), this.level.getChunk(movingBlock.getChunkX(), movingBlock.getChunkZ()), blockEntity);
152153
}
154+
155+
moved.onUpdate(Level.BLOCK_UPDATE_NORMAL);
153156
}
154157
}
155158

@@ -202,10 +205,10 @@ public CompoundTag getSpawnCompound() {
202205

203206
private ListTag<IntTag> getAttachedBlocks() {
204207
ListTag<IntTag> attachedBlocks = new ListTag<>("AttachedBlocks");
205-
for (Vector3 block : this.attachedBlocks) {
206-
attachedBlocks.add(new IntTag("", block.getFloorX()));
207-
attachedBlocks.add(new IntTag("", block.getFloorY()));
208-
attachedBlocks.add(new IntTag("", block.getFloorZ()));
208+
for (BlockVector3 block : this.attachedBlocks) {
209+
attachedBlocks.add(new IntTag("", block.x));
210+
attachedBlocks.add(new IntTag("", block.y));
211+
attachedBlocks.add(new IntTag("", block.z));
209212
}
210213

211214
return attachedBlocks;

src/main/java/cn/nukkit/entity/item/EntityMinecartTNT.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package cn.nukkit.entity.item;
22

3-
import cn.nukkit.Server;
43
import cn.nukkit.block.BlockTNT;
54
import cn.nukkit.entity.EntityExplosive;
65
import cn.nukkit.entity.data.IntEntityData;
@@ -53,7 +52,6 @@ public void initEntity() {
5352
public boolean onUpdate(int currentTick) {
5453
this.timing.startTiming();
5554

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

@@ -71,8 +69,6 @@ public boolean onUpdate(int currentTick) {
7169
}
7270
kill();
7371
}
74-
75-
Server.getInstance().getLogger().info("Debug:" + fuse);
7672
}
7773

7874
this.timing.stopTiming();

src/main/java/cn/nukkit/level/Level.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,6 @@ public Item useItemOn(Vector3 vector, Item item, BlockFace face, float fx, float
21052105
return null;
21062106
}
21072107

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

22292228
public BlockEntity getBlockEntity(Vector3 pos) {
2230-
FullChunk chunk = this.getChunk((int) pos.x >> 4, (int) pos.z >> 4, false);
2229+
return getBlockEntity(pos.asBlockVector3());
2230+
}
2231+
2232+
public BlockEntity getBlockEntity(BlockVector3 pos) {
2233+
FullChunk chunk = this.getChunk(pos.x >> 4, pos.z >> 4, false);
22312234

22322235
if (chunk != null) {
2233-
return chunk.getTile((int) pos.x & 0x0f, (int) pos.y & 0xff, (int) pos.z & 0x0f);
2236+
return chunk.getTile(pos.x & 0x0f, pos.y & 0xff, pos.z & 0x0f);
22342237
}
22352238

22362239
return null;
@@ -3345,7 +3348,15 @@ public boolean isSidePowered(Vector3 pos, BlockFace face) {
33453348
}
33463349

33473350
public int getRedstonePower(Vector3 pos, BlockFace face) {
3348-
Block block = this.getBlock(pos);
3351+
Block block;
3352+
3353+
if (pos instanceof Block) {
3354+
block = (Block) pos;
3355+
pos = pos.add(0);
3356+
} else {
3357+
block = this.getBlock(pos);
3358+
}
3359+
33493360
return block.isNormalBlock() ? this.getStrongPower(pos) : block.getWeakPower(face);
33503361
}
33513362

src/main/java/cn/nukkit/level/format/anvil/Chunk.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public byte[] toFastBinary() {
275275
if (section instanceof EmptyChunkSection) {
276276
continue;
277277
}
278-
CompoundTag s = new CompoundTag(null);
278+
CompoundTag s = new CompoundTag();
279279
s.putByte("Y", section.getY());
280280
s.putByteArray("Blocks", section.getIdArray());
281281
s.putByteArray("Data", section.getDataArray());
@@ -358,7 +358,7 @@ public byte[] toBinary() {
358358
if (section instanceof EmptyChunkSection) {
359359
continue;
360360
}
361-
CompoundTag s = new CompoundTag(null);
361+
CompoundTag s = new CompoundTag();
362362
s.putByte("Y", (section.getY()));
363363
s.putByteArray("Blocks", section.getIdArray());
364364
s.putByteArray("Data", section.getDataArray());

src/main/java/cn/nukkit/plugin/PluginManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public Map<String, Plugin> loadPlugins(File dictionary, List<String> newLoaders,
244244
dependencies.get(name).remove(dependency);
245245
} else if (!plugins.containsKey(dependency)) {
246246
this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit" +
247-
".plugin.loadError", new String[]{name, "%nukkit.plugin.unknownDependency"}));
247+
".plugin.loadError", name, "%nukkit.plugin.unknownDependency", dependency));
248248
break;
249249
}
250250
}

0 commit comments

Comments
 (0)