Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Aug 13, 2024
2 parents 45b2907 + 4344117 commit 7d73d81
Show file tree
Hide file tree
Showing 153 changed files with 640 additions and 419 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Achievement.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Achievement {

/**
* All known achievements.
*
* <p>
* Based on <a href="https://minecraft.fandom.com/wiki/Achievement/Java_Edition#List_of_achievements">...</a>
*/
public static final HashMap<String, Achievement> achievements = new HashMap<String, Achievement>() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/nukkit/IPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* An interface to describe a player and get its information.
*
* <p>
* This player can be online or offline.
*
* @author MagicDroidX(code) @ Nukkit Project
Expand All @@ -26,7 +26,7 @@ public interface IPlayer extends ServerOperator, Metadatable {

/**
* Returns the name of this player.
*
* <p>
* 如果是在线的玩家,这个函数只会返回登录名字。如果要返回显示的名字,参见{@link cn.nukkit.Player#getDisplayName}<br>
* Notice that this will only return its login name. If you need its display name, turn to
* {@link cn.nukkit.Player#getDisplayName}
Expand Down Expand Up @@ -104,7 +104,7 @@ public interface IPlayer extends ServerOperator, Metadatable {

/**
* Returns if this player has played in this server before.
*
* <p>
* If you want to know if this player is the first time playing in this server, you can use:<br>
* <pre>if (!player.hasPlayerBefore()) {...}</pre>
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/InterruptibleThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* An interface to describe a thread that can be interrupted.
*
* <p>
* When a Nukkit server is stopping, Nukkit finds all threads implements {@code InterruptibleThread},
* and interrupt them one by one.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Nukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Nukkit {

public final static Properties GIT_INFO = getGitInfo();
public final static String VERSION = getVersion();
public final static String API_VERSION = "1.0.20";
public final static String API_VERSION = "1.0.21";
public final static String PATH = System.getProperty("user.dir") + '/';
public final static String DATA_PATH = System.getProperty("user.dir") + '/';
public final static String PLUGIN_PATH = DATA_PATH + "plugins";
Expand Down
52 changes: 30 additions & 22 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public int getLastFireworkBoostTick() {
public void onFireworkBoost(int boostLevel) {
this.lastFireworkBoost = this.server.getTick();
this.fireworkBoostLevel = boostLevel;
this.fireworkBoostTicks = 40;
this.fireworkBoostTicks = boostLevel == 3 ? 44 : boostLevel == 2 ? 29 : 23;
}

/**
Expand Down Expand Up @@ -2008,27 +2008,27 @@ protected void handleMovement(Vector3 newPos) {
if (this.speed == null) speed = new Vector3(from.x - to.x, from.y - to.y, from.z - to.z);
else this.speed.setComponents(from.x - to.x, from.y - to.y, from.z - to.z);

if (this.isFoodEnabled() && this.getServer().getDifficulty() > 0) {
if (distanceSquared >= 0.05) {
double jump = 0;
double swimming = this.isInsideOfWater() ? 0.01 * distanceSquared : 0;
double dd = distanceSquared;
if (swimming != 0) dd = 0;
if (this.isSprinting()) {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.2;
}
this.foodData.updateFoodExpLevel(0.1 * dd + jump + swimming);
} else {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.05;
if (this.riding == null && this.inventory != null) {
if (this.isFoodEnabled() && this.getServer().getDifficulty() > 0) {
if (distanceSquared >= 0.05) {
double jump = 0;
double swimming = this.isInsideOfWater() ? 0.01 * distanceSquared : 0;
double dd = distanceSquared;
if (swimming != 0) dd = 0;
if (this.isSprinting()) {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.2;
}
this.foodData.updateFoodExpLevel(0.1 * dd + jump + swimming);
} else {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.05;
}
this.foodData.updateFoodExpLevel(jump + swimming);
}
this.foodData.updateFoodExpLevel(jump + swimming);
}
}
}

if (this.riding == null && this.inventory != null) {
Item boots = this.inventory.getBootsFast();

Enchantment frostWalker = boots.getEnchantment(Enchantment.ID_FROST_WALKER);
Expand Down Expand Up @@ -2517,7 +2517,7 @@ public void onCompletion(Server server) {
}
};

this.server.getScheduler().scheduleAsyncTask(this.preLoginEventTask);
this.server.getScheduler().scheduleAsyncTask(null, this.preLoginEventTask);

try {
this.processLogin();
Expand Down Expand Up @@ -2954,7 +2954,7 @@ public void handleDataPacket(DataPacket packet) {
}

if (server.encryptionEnabled) {
this.getServer().getScheduler().scheduleAsyncTask(new PrepareEncryptionTask(this) {
this.getServer().getScheduler().scheduleAsyncTask(null, new PrepareEncryptionTask(this) {

@Override
public void onCompletion(Server server) {
Expand Down Expand Up @@ -3295,7 +3295,7 @@ public void onCompletion(Server server) {
}
}

Vector3 clientPosition = authPacket.getPosition().subtract(0, this.getBaseOffset(), 0).asVector3();
Vector3 clientPosition = authPacket.getPosition().subtract(0, this.riding == null ? this.getBaseOffset() : this.riding.getMountedOffset(this).getY(), 0).asVector3();

double distSqrt = clientPosition.distanceSquared(this);
if (distSqrt > 100) { // Notice: This is the distance to player's position on server side. There are likely still unhandled previous movements when next move packet is received.
Expand Down Expand Up @@ -7049,7 +7049,7 @@ public void startFishing(Item fishingRod) {
.add(new FloatTag("", (float) yaw))
.add(new FloatTag("", (float) pitch)));
double f = 1.1;
EntityFishingHook fishingHook = new EntityFishingHook(chunk, nbt, this);
EntityFishingHook fishingHook = (EntityFishingHook) Entity.createEntity(EntityFishingHook.NETWORK_ID, chunk, nbt, this);
fishingHook.setMotion(new Vector3(-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * f * f, -Math.sin(Math.toRadians(pitch)) * f * f,
Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * f * f));
ProjectileLaunchEvent ev = new ProjectileLaunchEvent(fishingHook);
Expand Down Expand Up @@ -7203,4 +7203,12 @@ public void setGliding(boolean value) {

super.setGliding(value);
}

/**
* Close form windows sent with showFormWindow
*/
public void closeFormWindows() {
this.formWindows.clear();
this.dataPacket(new ClientboundCloseFormPacket());
}
}
6 changes: 3 additions & 3 deletions src/main/java/cn/nukkit/PlayerFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

/**
* This class handles player's food.
*
* <p>
* Created by funcraft on 2015/11/11.
*/
public class PlayerFood {

private int foodLevel;
private float foodSaturationLevel;
private short foodTickTimer = 0;
private double foodExpLevel = 0;
private int foodTickTimer;
private double foodExpLevel;

private final Player player;

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,9 @@ public void addOnlinePlayer(Player player) {
}

public void removeOnlinePlayer(Player player) {
if (player.getUniqueId() == null) {
return;
}
if (this.playerList.remove(player.getUniqueId()) != null) {
PlayerListPacket pk = new PlayerListPacket();
pk.type = PlayerListPacket.TYPE_REMOVE;
Expand Down Expand Up @@ -1796,7 +1799,7 @@ private void saveOfflinePlayerData(String name, CompoundTag tag, boolean async,
}

if (async) {
this.getScheduler().scheduleTask(new Task() {
this.getScheduler().scheduleTask(null, new Task() {
private volatile boolean hasRun = false;

@Override
Expand Down Expand Up @@ -2044,7 +2047,7 @@ public boolean unloadLevel(Level level) {

/**
* Unload a level
*
* <p>
* Notice: the default level cannot be unloaded without forceUnload=true
*
* @param level Level
Expand Down Expand Up @@ -2605,7 +2608,7 @@ public int getPlayerSkinChangeCooldown() {

/**
* Checks the current thread against the expected primary thread for the server.
*
* <p>
* <b>Note:</b> this method should not be used to indicate the current synchronized state of the runtime. A current thread matching the main thread indicates that it is synchronized, but a mismatch does not preclude the same assumption.
*
* @return true if the current thread matches the expected primary thread, false otherwise
Expand Down
48 changes: 18 additions & 30 deletions src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.block.properties.BlockNotImplemented;
import cn.nukkit.customblock.CustomBlockManager;
import cn.nukkit.entity.Entity;
import cn.nukkit.item.Item;
Expand Down Expand Up @@ -83,41 +82,30 @@ public static void init() {
if (c != null) {
Block block;
try {
if (c.isAssignableFrom(BlockNotImplemented.class)) {
Constructor<?> constructor = c.getDeclaredConstructor(int.class, int.class);
block = (Block) c.newInstance();
try {
@SuppressWarnings("rawtypes")
Constructor constructor = c.getDeclaredConstructor(int.class);
constructor.setAccessible(true);
block = (Block) constructor.newInstance(id, 0);
for (int data = 0; data < (1 << DATA_BITS); ++data) {
int fullId = (id << DATA_BITS) | data;
fullList[fullId] = (Block) constructor.newInstance(id, data);
}
hasMeta[id] = true;
} else {
block = (Block) c.newInstance();
try {
@SuppressWarnings("rawtypes")
Constructor constructor = c.getDeclaredConstructor(int.class);
constructor.setAccessible(true);
for (int data = 0; data < (1 << DATA_BITS); ++data) {
int fullId = (id << DATA_BITS) | data;
Block blockState;
try {
blockState = (Block) constructor.newInstance(data);
if (blockState.getDamage() != data) {
blockState = new BlockUnknown(id, data);
}
} catch (Exception e) {
Server.getInstance().getLogger().error("Error while registering " + c.getName(), e);
Block blockState;
try {
blockState = (Block) constructor.newInstance(data);
if (blockState.getDamage() != data) {
blockState = new BlockUnknown(id, data);
}
fullList[fullId] = blockState;
}
hasMeta[id] = true;
} catch (NoSuchMethodException ignore) {
for (int data = 0; data < DATA_SIZE; ++data) {
int fullId = (id << DATA_BITS) | data;
fullList[fullId] = block;
} catch (Exception e) {
Server.getInstance().getLogger().error("Error while registering " + c.getName(), e);
blockState = new BlockUnknown(id, data);
}
fullList[fullId] = blockState;
}
hasMeta[id] = true;
} catch (NoSuchMethodException ignore) {
for (int data = 0; data < DATA_SIZE; ++data) {
int fullId = (id << DATA_BITS) | data;
fullList[fullId] = block;
}
}
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockButtonWooden.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public int getId() {

@Override
public String getName() {
return "Wooden Button";
return "Oak Button";
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cn/nukkit/block/BlockCaveVines.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,9 @@ public static boolean isCaveVine(Block block) {
}
return false;
}

@Override
public boolean canPassThrough() {
return true;
}
}
12 changes: 4 additions & 8 deletions src/main/java/cn/nukkit/block/BlockComposter.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,7 @@ public boolean onActivate(Item item, Player player) {
}

if (isFull()) {
ComposterEmptyEvent event = new ComposterEmptyEvent(this, player, item, new ItemDye(DyeColor.WHITE), 0);
this.level.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.setDamage(event.getNewLevel());
this.level.setBlock(this, this, true, true);
this.level.dropItem(add(0.5, 0.85, 0.5), event.getDrop());
this.level.addSound(add(0.5 , 0.5, 0.5), Sound.BLOCK_COMPOSTER_EMPTY);
}
empty(item, player);
return true;
}

Expand Down Expand Up @@ -150,6 +143,9 @@ public Item empty(Player player) {
}

public Item empty(Item item, Player player) {
if (isEmpty()) {
return null;
}
ComposterEmptyEvent event = new ComposterEmptyEvent(this, player, item, new ItemDye(DyeColor.WHITE), 0);
this.level.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockConcrete.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public double getHardness() {

@Override
public String getName() {
return "Concrete";
return getDyeColor().getName() + " Concrete";
}

@Override
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cn/nukkit/block/BlockConcretePowder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BlockConcretePowder(int meta) {

@Override
public int getFullId() {
return (this.getId() << Block.DATA_BITS) + getDamage();
return (CONCRETE_POWDER << Block.DATA_BITS) + getDamage();
}

@Override
Expand All @@ -33,7 +33,7 @@ public int getId() {

@Override
public String getName() {
return "Concrete Powder";
return getDyeColor().getName() + " Concrete Powder";
}

@Override
Expand Down Expand Up @@ -93,4 +93,8 @@ public boolean place(Item item, Block b, Block target, BlockFace face, double fx
public BlockColor getColor() {
return DyeColor.getByWoolData(getDamage()).getColor();
}

public DyeColor getDyeColor() {
return DyeColor.getByWoolData(getDamage());
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockCrimsonStairs.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public int getId() {

@Override
public String getName() {
return "Crimson Wood Stairs";
return "Crimson Stairs";
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockDoubleSlabStone.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BlockDoubleSlabStone extends BlockDoubleSlabBase {
private static final String[] NAMES = new String[]{
"Stone",
"Sandstone",
"Wooden",
"Oak",
"Cobblestone",
"Brick",
"Stone Brick",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockEndRod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.nukkit.utils.Faceable;

/**
* http://minecraft.gamepedia.com/End_Rod
* <a href="http://minecraft.gamepedia.com/End_Rod">...</a>
*
* @author PikyCZ
*/
Expand Down
Loading

0 comments on commit 7d73d81

Please sign in to comment.