Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Nov 7, 2024
2 parents 7376835 + 2172e54 commit f3d4e87
Show file tree
Hide file tree
Showing 68 changed files with 1,101 additions and 340 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,8 @@ public void forceShutdown(String reason) {
nameLookup.close();
}

this.getLogger().debug("Stopping Watchdog...");
if (this.watchdog != null) {
this.getLogger().debug("Stopping Watchdog...");
this.watchdog.kill();
}
} catch (Exception e) {
Expand Down
27 changes: 23 additions & 4 deletions src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public abstract class Block extends Position implements Metadatable, Cloneable, AxisAlignedBB, BlockID {

@SuppressWarnings("UnnecessaryBoxing")
public static final int MAX_BLOCK_ID = Integer.valueOf("1024");
public static final int MAX_BLOCK_ID = Integer.valueOf("2048");
public static final int DATA_BITS = 6;
public static final int DATA_SIZE = 1 << DATA_BITS;
public static final int DATA_MASK = DATA_SIZE - 1;
Expand Down Expand Up @@ -946,25 +946,40 @@ public BlockLayer getLayer() {
return this.layer;
}

protected static boolean canStayOnFullSolid(Block down) {
protected static boolean canConnectToFullSolid(Block down) {
if (down.isTransparent()) {
switch (down.getId()) {
case BEACON:
case ICE:
case GLASS:
case STAINED_GLASS:
case SCAFFOLDING:
case BARRIER:
case GLOWSTONE:
case SEA_LANTERN:
case HOPPER_BLOCK:
case MANGROVE_ROOTS:
case MUDDY_MANGROVE_ROOTS:
return true;
}
return false;
}
return true;
}

protected static boolean canStayOnFullSolid(Block down) {
if (canConnectToFullSolid(down)) {
return true;
}
switch (down.getId()) {
case SCAFFOLDING:
case HOPPER_BLOCK:
return true;
}
if (down instanceof BlockSlab) {
return ((BlockSlab) down).hasTopBit();
}
return down instanceof BlockTrapdoor && ((BlockTrapdoor) down).isTop() && !((BlockTrapdoor) down).isOpen();
}

protected static boolean canStayOnFullNonSolid(Block down) {
if (canStayOnFullSolid(down)) {
return true;
Expand All @@ -978,6 +993,10 @@ protected static boolean canStayOnFullNonSolid(Block down) {
return false;
}

protected boolean isNarrowSurface() {
return this instanceof BlockGlassPane || this instanceof BlockFence || this instanceof BlockWall || this instanceof BlockChain || this instanceof BlockIronBars;
}

public boolean alwaysDropsOnExplosion() {
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/cn/nukkit/block/BlockAmethystBud.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public String getName() {

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.setDamage(face.getIndex());
this.getLevel().setBlock(this, this, true, true);
return true;
if (Block.canConnectToFullSolid(this.getSide(face.getOpposite()))) {
this.setDamage(face.getIndex());
return this.getLevel().setBlock(this, this, true, true);
}
return false;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockAzaleaLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl

@Override
public Item toItem() {
return new ItemBlock(this, 0, 1);
return new ItemBlock(Block.get(this.getId(), 0), 0);
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBell.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ private boolean checkSupport(Block support, BlockFace attachmentFace) {
if (support instanceof BlockCauldron) {
return attachmentFace == BlockFace.UP;
}

if (attachmentFace == BlockFace.UP) {
return Block.canStayOnFullSolid(support);
}
return false;
}

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/cn/nukkit/block/BlockButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ public double getHardness() {

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (target.isTransparent()) {
return false;
}

this.setDamage(face.getIndex());
if (this.getSide(getFacing().getOpposite()).isTransparent()) {
if (!isSupportValid(this.getSide(this.getFacing().getOpposite()))) {
return false;
}

Expand Down Expand Up @@ -72,7 +68,7 @@ public boolean onActivate(Item item, Player player) {
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.getSide(getFacing().getOpposite()).isTransparent()) {
if (!isSupportValid(this.getSide(this.getFacing().getOpposite()))) {
this.level.useBreakOn(this, Item.get(Item.WOODEN_PICKAXE));
return Level.BLOCK_UPDATE_NORMAL;
}
Expand All @@ -94,6 +90,16 @@ public int onUpdate(int type) {
return 0;
}

private boolean isSupportValid(Block block) {
if (!block.isTransparent()) {
return true;
}
if (this.getFacing() == BlockFace.UP) {
return Block.canStayOnFullSolid(block);
}
return Block.canConnectToFullSolid(block);
}

public boolean isActivated() {
return ((this.getDamage() & 0x08) == 0x08);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean onActivate(Item item, Player player) {
if (player != null) {
Block top = this.up();
if (!(top instanceof BlockStairs)) { // Stairs don't block chest on vanilla
if ((!(top instanceof BlockSlab) && !top.isTransparent()) || (top instanceof BlockSlab && top.isTransparent())) { // Avoid issues with the slab hack
if (!top.isTransparent()) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockCoral.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
if (this.down().isTransparent()) {
return false;
}
if (!(block instanceof BlockWater || block.level.isBlockWaterloggedAt(block.getChunk(), (int) block.x, (int) block.y, (int) block.z))) {
if (this.getDamage() < 8 && !(block instanceof BlockWater || block.level.isBlockWaterloggedAt(block.getChunk(), (int) block.x, (int) block.y, (int) block.z))) {
this.setDamage(8 + this.getDamage()); // Dead
}
if (this.getLevel().setBlock(this, this, true, true)) {
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/cn/nukkit/block/BlockDirt.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cn.nukkit.block;

import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemDye;
import cn.nukkit.item.ItemTool;
import cn.nukkit.item.*;
import cn.nukkit.level.Sound;
import cn.nukkit.level.generator.object.ObjectTallGrass;
import cn.nukkit.level.particle.BoneMealParticle;
Expand Down Expand Up @@ -89,6 +86,16 @@ public boolean onActivate(Item item, Player player) {
}
return true;
}
} else if (player != null && item.getId() == Item.POTION && item.getDamage() == ItemPotion.NO_EFFECTS) {
item.count--;
Item emptyBottle = Item.get(Item.GLASS_BOTTLE);
if (player.getInventory().canAddItem(emptyBottle)) {
player.getInventory().addItem(emptyBottle);
} else {
player.getLevel().dropItem(player.add(0, 1.3, 0), emptyBottle, player.getDirectionVector().multiply(0.4));
}
this.getLevel().setBlock(this, get(MUD), true);
return true;
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockEnderChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean place(Item item, Block block, Block target, BlockFace face, doubl
public boolean onActivate(Item item, Player player) {
if (player != null) {
Block top = this.up();
if (!top.isTransparent() && !(top instanceof BlockSlab && (top.getDamage() & 0x07) <= 0)) { // avoid issues with the slab hack
if (!top.isTransparent()) {
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/nukkit/block/BlockFlowerPot.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static boolean canPlaceIntoFlowerPot(Block block) {
case CRIMSON_ROOTS:
case WARPED_ROOTS:
case WITHER_ROSE:
case MANGROVE_PROPAGULE:
return true;
default:
return false;
Expand All @@ -77,8 +78,8 @@ public int getId() {
return FLOWER_POT_BLOCK;
}

private boolean isSupportValid(Block block) {
return block.isSolid() || block instanceof BlockFence || block instanceof BlockWall || block instanceof BlockHopper;
private static boolean isSupportValid(Block block) {
return block.isSolid() || block.isNarrowSurface() || Block.canStayOnFullSolid(block);
}

@Override
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/cn/nukkit/block/BlockFroglight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cn.nukkit.block;

import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.utils.BlockColor;

public abstract class BlockFroglight extends BlockSolidMeta {

protected BlockFroglight(int meta) {
super(meta);
}

@Override
public double getResistance() {
return 0.3;
}

@Override
public double getHardness() {
return 0.3;
}

@Override
public int getLightLevel() {
return 15;
}

@Override
public BlockColor getColor() {
return BlockColor.WHITE_BLOCK_COLOR;
}

@Override
public Item toItem() {
return new ItemBlock(Block.get(this.getId(), 0), 0);
}
}
22 changes: 22 additions & 0 deletions src/main/java/cn/nukkit/block/BlockFroglightOchre.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nukkit.block;

public class BlockFroglightOchre extends BlockFroglight {

public BlockFroglightOchre() {
this(0);
}

public BlockFroglightOchre(int meta) {
super(meta);
}

@Override
public String getName() {
return "Ochre Froglight";
}

@Override
public int getId() {
return OCHRE_FROGLIGHT;
}
}
22 changes: 22 additions & 0 deletions src/main/java/cn/nukkit/block/BlockFroglightPearlescent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nukkit.block;

public class BlockFroglightPearlescent extends BlockFroglight {

public BlockFroglightPearlescent() {
this(0);
}

public BlockFroglightPearlescent(int meta) {
super(meta);
}

@Override
public String getName() {
return "Pearlescent Froglight";
}

@Override
public int getId() {
return PEARLESCENT_FROGLIGHT;
}
}
22 changes: 22 additions & 0 deletions src/main/java/cn/nukkit/block/BlockFroglightVerdant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nukkit.block;

public class BlockFroglightVerdant extends BlockFroglight {

public BlockFroglightVerdant() {
this(0);
}

public BlockFroglightVerdant(int meta) {
super(meta);
}

@Override
public String getName() {
return "Verdant Froglight";
}

@Override
public int getId() {
return VERDANT_FROGLIGHT;
}
}
45 changes: 45 additions & 0 deletions src/main/java/cn/nukkit/block/BlockFrogspawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cn.nukkit.block;

import cn.nukkit.Player;
import cn.nukkit.item.Item;
import cn.nukkit.math.BlockFace;

public class BlockFrogspawn extends BlockFlowable {

public BlockFrogspawn() {
this(0);
}

public BlockFrogspawn(int meta) {
super(0);
}

@Override
public int getId() {
return FROG_SPAWN;
}

@Override
public String getName() {
return "Frogspawn";
}

@Override
public Item[] getDrops(Item item) {
return new Item[0];
}

@Override
public int getDropExp() {
return 1;
}

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
Block up;
if (!(block instanceof BlockWater) || !((up = block.up()) instanceof BlockAir)) {
return false;
}
return this.getLevel().setBlock(up, this, true, true);
}
}
Loading

0 comments on commit f3d4e87

Please sign in to comment.