Skip to content

Commit

Permalink
调整几处高度判断
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Mar 5, 2024
1 parent a6e22be commit 42db60d
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 81 deletions.
14 changes: 11 additions & 3 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3128,8 +3128,9 @@ public void onCompletion(Server server) {
if (!this.spawned || !this.isAlive()) {
break;
}
AnimatePacket animatePk = (AnimatePacket) packet;

PlayerAnimationEvent animationEvent = new PlayerAnimationEvent(this, ((AnimatePacket) packet).action);
PlayerAnimationEvent animationEvent = new PlayerAnimationEvent(this, animatePk.action);
this.server.getPluginManager().callEvent(animationEvent);
if (animationEvent.isCancelled()) {
break;
Expand All @@ -3140,8 +3141,14 @@ public void onCompletion(Server server) {
switch (animation) {
case ROW_RIGHT:
case ROW_LEFT:
if (this.riding instanceof EntityBoat) {
((EntityBoat) this.riding).onPaddle(animation, ((AnimatePacket) packet).rowingTime);
if (this.riding instanceof EntityBoat boat) {
float paddleTime = animatePk.rowingTime;
if (!validateFloat(paddleTime)) {
onPacketViolation(PacketViolationReason.IMPOSSIBLE_BEHAVIOR, "anim_nan");
return;
}

boat.onPaddle(animation, paddleTime);
}
break;
case SWING_ARM:
Expand All @@ -3162,6 +3169,7 @@ public void onCompletion(Server server) {
AnimatePacket animatePacket = new AnimatePacket();
animatePacket.eid = this.getId();
animatePacket.action = animationEvent.getAnimationType();
animatePacket.rowingTime = animatePk.rowingTime;
Server.broadcastPacket(this.getViewers().values(), animatePacket);
break;
case ProtocolInfo.SET_HEALTH_PACKET:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/block/BlockCrops.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {
return false;
}

this.getLevel().setBlock(this, ev.getNewState(), false, true);
this.getLevel().setBlock(this, ev.getNewState(), true, true);
this.level.addParticle(new BoneMealParticle(this));

if (player != null && (player.gamemode & 0x01) == 0) {
Expand Down Expand Up @@ -85,7 +85,7 @@ public int onUpdate(int type) {
Server.getInstance().getPluginManager().callEvent(ev);

if (!ev.isCancelled()) {
this.getLevel().setBlock(this, ev.getNewState(), false, true);
this.getLevel().setBlock(this, ev.getNewState(), true, true);
} else {
return Level.BLOCK_UPDATE_RANDOM;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/block/BlockDispenser.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public int onUpdate(int type) {

if (type == Level.BLOCK_UPDATE_SCHEDULED) {
this.setTriggered(false);
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);

dispense();
return type;
Expand All @@ -177,7 +177,7 @@ public int onUpdate(int type) {

if (powered && !triggered) {
this.setTriggered(true);
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);
level.scheduleUpdate(this, this, 4);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockDoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public int onUpdate(int type) {
Block up = this.up();

if (up instanceof BlockDoor) {
this.getLevel().setBlock(up, Block.get(BlockID.AIR), false);
this.getLevel().setBlock(up, Block.get(BlockID.AIR), true, false);
this.getLevel().useBreakOn(this, Item.get(Item.WOODEN_PICKAXE));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockDoublePlant.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public int onUpdate(int type) {
if ((meta & TOP_HALF_BITMASK) == TOP_HALF_BITMASK) {
Block below = down();
if (below.getId() != DOUBLE_PLANT || (below.getDamage() & TYPE_MASK) != (meta & TYPE_MASK)) {
this.getLevel().setBlock(this, Block.get(BlockID.AIR), false, true);
this.getLevel().setBlock(this, Block.get(BlockID.AIR), true, true);
return Level.BLOCK_UPDATE_NORMAL;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockFenceGate.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public boolean toggle(Player player) {
}

this.setDamage(direction | ((~this.getDamage()) & OPEN_BIT));
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/cn/nukkit/block/BlockFlower.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemDye;
import cn.nukkit.level.HeightRange;
import cn.nukkit.level.Level;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.BlockFace;
Expand Down Expand Up @@ -111,14 +112,15 @@ public boolean onActivate(Item item, BlockFace face, Player player) {

this.level.addParticle(new BoneMealParticle(this));

HeightRange heightRange = level.getHeightRange();
ThreadLocalRandom random = ThreadLocalRandom.current();
for (int i = 0; i < 8; i++) {
Vector3 vec = this.add(
random.nextInt(-3, 4),
random.nextInt(-1, 2),
random.nextInt(-3, 4));

if (level.getBlock(vec).getId() == AIR && level.getBlock(vec.down()).getId() == GRASS_BLOCK && vec.getY() >= 0 && vec.getY() < 256) {
if (level.getBlock(vec).getId() == AIR && level.getBlock(vec.down()).getId() == GRASS_BLOCK && vec.getY() >= heightRange.getMinY() && vec.getY() < heightRange.getMaxY()) {
if (random.nextInt(10) == 0) {
this.level.setBlock(vec, this.getUncommonFlower(), true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public int onUpdate(int type) {

if (powered == this.isEnabled()) {
this.setEnabled(!powered);
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);

if (!powered) {
BlockEntity be = this.level.getBlockEntity(this);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/block/BlockLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Item[] getDrops(Item item) {
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_RANDOM && !isPersistent() && !isCheckDecay()) {
setCheckDecay(true);
getLevel().setBlock(this, this, false, false);
getLevel().setBlock(this, this, true, false);
} else if (type == Level.BLOCK_UPDATE_RANDOM && isCheckDecay() && !isPersistent()) {
setDamage(getLeafType());
int check = 0;
Expand All @@ -138,7 +138,7 @@ public int onUpdate(int type) {

Server.getInstance().getPluginManager().callEvent(ev);
if (ev.isCancelled() || findLog(this, new LongArraySet(), 0, check)) {
getLevel().setBlock(this, this, false, false);
getLevel().setBlock(this, this, true, false);
} else {
getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockLever.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public boolean onActivate(Item item, BlockFace face, Player player) {

boolean redstone = this.level.isRedstoneEnabled();

this.getLevel().setBlock(this, this, false, true);
this.getLevel().setBlock(this, this, true, true);
this.getLevel().addLevelEvent(this.blockCenter(), LevelEventPacket.EVENT_SOUND_BUTTON_CLICK, this.isPowerOn() ? 600 : 500);

if (redstone) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockOreRedstone.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Item[] getDrops(Item item) {
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_TOUCH) { //type == Level.BLOCK_UPDATE_NORMAL ||
this.getLevel().setBlock(this, Block.get(getLitBlockId()), false, false);
this.getLevel().setBlock(this, Block.get(getLitBlockId()), true, false);

return Level.BLOCK_UPDATE_WEAK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockOreRedstoneGlowing.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public int onUpdate(int type) {
BlockFadeEvent event = new BlockFadeEvent(this, get(getUnlitBlockId()));
level.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
level.setBlock(this, event.getNewState(), false, false);
level.setBlock(this, event.getNewState(), true, false);
}

return Level.BLOCK_UPDATE_WEAK;
Expand Down
8 changes: 4 additions & 4 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.inventory.InventoryHolder;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.HeightRange;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.BlockVector3;
Expand Down Expand Up @@ -313,10 +314,9 @@ private boolean doMove(boolean extending) {
}

public static boolean canPush(Block block, BlockFace face, boolean destroyBlocks, boolean extending) {
if (
block.getY() >= 0 && (face != BlockFace.DOWN || block.getY() != 0) &&
block.getY() <= 255 && (face != BlockFace.UP || block.getY() != 255)
) {
HeightRange heightRange = block.level.getHeightRange();
if (block.getY() >= heightRange.getMinY() && (face != BlockFace.DOWN || block.getY() != heightRange.getMinY()) &&
block.getY() < heightRange.getMaxY() && (face != BlockFace.UP || block.getY() != heightRange.getMaxY() - 1)) {
if (extending && !block.canBePushed() || !extending && !block.canBePulled()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockPressurePlateBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected void updateState(int oldStrength) {

if (oldStrength != strength) {
this.setRedstonePower(strength);
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);

this.level.updateAroundRedstone(this, null);
this.level.updateAroundRedstone(this.downVec(), null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockRail.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Orientation getOrientation() {
public void setOrientation(Orientation o) {
if (o.metadata() != this.getRealMeta()) {
this.setDamage(o.metadata());
this.level.setBlock(this, this, false, true);
this.level.setBlock(this, this, true, true);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/nukkit/block/BlockRedstoneLamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public int getToolType() {
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (this.level.isBlockPowered(this)) {
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), false, true);
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), true, true);
} else {
this.level.setBlock(this, this, false, true);
this.level.setBlock(this, this, true, true);
}
return true;
}
Expand All @@ -64,7 +64,7 @@ public int onUpdate(int type) {
return 0;
}
if (this.level.isBlockPowered(this)) {
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), false, false);
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), true, false);
return 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockRedstoneLampLit.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int onUpdate(int type) {
}

if (type == Level.BLOCK_UPDATE_SCHEDULED && !this.level.isBlockPowered(this)) {
this.level.setBlock(this, Block.get(BlockID.REDSTONE_LAMP), false, false);
this.level.setBlock(this, Block.get(BlockID.REDSTONE_LAMP), true, false);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockRedstoneTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected boolean checkState() {
if (isPoweredFromSide()) {
BlockFace face = getBlockFace().getOpposite();

this.level.setBlock(this, Block.get(BlockID.UNLIT_REDSTONE_TORCH, getDamage()), false, true);
this.level.setBlock(this, Block.get(BlockID.UNLIT_REDSTONE_TORCH, getDamage()), true, true);

for (BlockFace side : BlockFace.getValues()) {
if (side == face) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockRedstoneTorchUnlit.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected boolean checkState() {
BlockFace face = getBlockFace().getOpposite();

if (!this.level.isSidePowered(this.getSideVec(face), face)) {
this.level.setBlock(this, Block.get(BlockID.REDSTONE_TORCH, getDamage()), false, true);
this.level.setBlock(this, Block.get(BlockID.REDSTONE_TORCH, getDamage()), true, true);

for (BlockFace side : BlockFace.getValues()) {
if (side == face) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockRedstoneWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void calculateCurrentChanges(boolean force) {
this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, meta, maxStrength));

this.setDamage(maxStrength);
this.level.setBlock(this, this, false, false);
this.level.setBlock(this, this, true, false);

this.level.updateAroundRedstone(this, null);
for (BlockFace face : BlockFace.getValues()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/block/BlockVine.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public int onUpdate(int type) {
int faceMeta = getMetaFromFace(face);
int meta = this.getDamage();

if (this.y < 255 && face == BlockFace.UP && block.getId() == AIR) {
if (this.y < level.getHeightRange().getMaxY() - 1 && face == BlockFace.UP && block.getId() == AIR) {
if (this.canSpread()) {
for (BlockFace horizontalFace : BlockFace.Plane.HORIZONTAL) {
if (random.nextBoolean() || !this.getSide(horizontalFace).getSide(face).isSolid()) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public int onUpdate(int type) {
putVine(this, meta, null);
}
}
} else if (this.y > 0) {
} else if (this.y > level.getHeightRange().getMinY()) {
Block below = this.down();
int id = below.getId();
if (id == AIR || id == VINE) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/blockentity/BlockEntityBeacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private boolean hasSkyAccess() {
int tileZ = getFloorZ();

//Check every block from our y coord to the top of the world
for (int y = tileY + 1; y <= 255; y++) {
for (int y = level.getHighestBlockAt(tileX, tileZ); y > tileY; y--) {
int testBlockId = level.getBlock(tileX, y, tileZ).getId();
if (!Block.transparent[testBlockId]) {
//There is no sky access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void updateBlock() {
}

block.setDamage(meta);
this.level.setBlock(block, block, false, false);
this.level.setBlock(block, block, true, false);
}

public int getFuel() {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/cn/nukkit/entity/item/EntityBoat.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,17 @@ public boolean onInteract(Player player, Item item, Vector3 clickedPos) {
return super.onInteract(player, item, clickedPos);
}

public void onPaddle(AnimatePacket.Action animation, float value) {
public void onPaddle(AnimatePacket.Action animation, float frameSeconds) {
int propertyId = animation == AnimatePacket.Action.ROW_RIGHT ? DATA_PADDLE_TIME_RIGHT : DATA_PADDLE_TIME_LEFT;

if (getDataPropertyFloat(propertyId) != value) {
this.setDataProperty(new FloatEntityData(propertyId, value));
if (frameSeconds > 1000) {
frameSeconds -= 1000;
} else if (frameSeconds < 1000) {
frameSeconds += 1000;
}

if (getDataPropertyFloat(propertyId) != frameSeconds) {
this.setDataProperty(new FloatEntityData(propertyId, frameSeconds));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/item/EntityVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean onUpdate(int currentTick) {
}

// A killer task
if (y < -16) {
if (y < level.getHeightRange().getMinY() - 18) {
close();
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cn/nukkit/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,18 @@ public boolean isChemistryFeature() {
return false;
}

public boolean is(int id) {
return getId() == id;
}

public boolean is(int id, int damage) {
return getId() == id && getDamage() == damage;
}

public boolean is(Item item) {
return getId() == item.getId();
}

public boolean isBoneMeal() {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/enchantment/Enchantment.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static String getRandomName() {
static class UnknownEnchantment extends Enchantment {

protected UnknownEnchantment(int id) {
super(id, "unknown", "unknown", Rarity.VERY_RARE, EnchantmentType.ALL);
super(id, "unknown", "unknown", Rarity.VERY_RARE, EnchantmentType.UNKNOWN);
}
}

Expand Down
Loading

0 comments on commit 42db60d

Please sign in to comment.