Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 committed Apr 23, 2024
2 parents 2b0d7d2 + 86683f2 commit c05be0b
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 83 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jline = "3.22.0"
fastutilmaps = "8.5.13-SNAPSHOT"

[libraries]
network = { group = "org.cloudburstmc.netty", name = "netty-transport-raknet", version = "1.0.0.CR1-20240330.101522-15" }
epoll = { group = "io.netty", name = "netty-transport-native-epoll", version = "4.1.101.Final" }
network = { group = "org.cloudburstmc.netty", name = "netty-transport-raknet", version = "1.0.0.CR3-SNAPSHOT" }
epoll = { group = "io.netty", name = "netty-transport-native-epoll", version = "4.1.100.Final" }
natives = { group = "com.nukkitx", name = "natives", version = "1.0.3" }
fastutil = { group = "com.nukkitx", name = "fastutil-lite", version = "8.1.1" }
fastutil-int-short-maps = { group = "org.cloudburstmc.fastutil.maps", name = "int-short-maps", version.ref = "fastutilmaps" }
Expand Down
62 changes: 33 additions & 29 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,9 @@ public void onCompletion(Server server) {

if (authPacket.getInputData().contains(AuthInputAction.START_SPRINTING)) {
PlayerToggleSprintEvent playerToggleSprintEvent = new PlayerToggleSprintEvent(this, true);
if ((this.foodData.getLevel() <= 6 && !this.getAdventureSettings().get(Type.FLYING)) || this.hasEffect(Effect.BLINDNESS)) {
if ((this.foodData.getLevel() <= 6 && !this.getAdventureSettings().get(Type.FLYING)) ||
this.riding != null || this.sleeping != null || this.hasEffect(Effect.BLINDNESS) ||
(this.isSneaking() && !authPacket.getInputData().contains(AuthInputAction.STOP_SNEAKING))) {
playerToggleSprintEvent.setCancelled(true);
}
this.server.getPluginManager().callEvent(playerToggleSprintEvent);
Expand All @@ -3136,6 +3138,9 @@ public void onCompletion(Server server) {

if (authPacket.getInputData().contains(AuthInputAction.START_SNEAKING)) {
PlayerToggleSneakEvent playerToggleSneakEvent = new PlayerToggleSneakEvent(this, true);
if (this.riding != null || this.sleeping != null) {
playerToggleSneakEvent.setCancelled(true);
}
this.server.getPluginManager().callEvent(playerToggleSneakEvent);
if (playerToggleSneakEvent.isCancelled()) {
this.needSendData = true;
Expand All @@ -3156,6 +3161,9 @@ public void onCompletion(Server server) {

if (authPacket.getInputData().contains(AuthInputAction.START_CRAWLING)) {
PlayerToggleCrawlEvent playerToggleCrawlEvent = new PlayerToggleCrawlEvent(this, true);
if (this.riding != null || this.sleeping != null) {
playerToggleCrawlEvent.setCancelled(true);
}
this.server.getPluginManager().callEvent(playerToggleCrawlEvent);
if (playerToggleCrawlEvent.isCancelled()) {
this.needSendData = true;
Expand Down Expand Up @@ -3189,7 +3197,7 @@ public void onCompletion(Server server) {
return;
}
PlayerToggleGlideEvent playerToggleGlideEvent = new PlayerToggleGlideEvent(this, true);
if (withoutElytra) {
if (this.riding != null || this.sleeping != null || withoutElytra) {
playerToggleGlideEvent.setCancelled(true);
}
this.server.getPluginManager().callEvent(playerToggleGlideEvent);
Expand All @@ -3212,7 +3220,7 @@ public void onCompletion(Server server) {

if (authPacket.getInputData().contains(AuthInputAction.START_SWIMMING)) {
PlayerToggleSwimEvent ptse = new PlayerToggleSwimEvent(this, true);
if (!this.isInsideOfWater()) {
if (this.riding != null || this.sleeping != null || !this.isInsideOfWater()) {
ptse.setCancelled(true);
}
this.server.getPluginManager().callEvent(ptse);
Expand Down Expand Up @@ -3298,27 +3306,15 @@ public void onCompletion(Server server) {

MobEquipmentPacket mobEquipmentPacket = (MobEquipmentPacket) packet;

Inventory inv = this.getWindowById(mobEquipmentPacket.windowId);

if (inv == null) {
this.server.getLogger().debug("Player " + this.getName() + " has no open container with window ID " + mobEquipmentPacket.windowId);
if (mobEquipmentPacket.windowId != ContainerIds.INVENTORY) {
return;
}

/*Item item = inv.getItem(mobEquipmentPacket.hotbarSlot);
if (!item.equals(mobEquipmentPacket.item)) {
if (Nukkit.DEBUG > 1) {
this.server.getLogger().debug("Tried to equip " + mobEquipmentPacket.item + " but have " + item + " in target slot");
}
inv.sendSlot(mobEquipmentPacket.hotbarSlot, this);
if (this.inventory == null) {
return;
}*/

if (inv instanceof PlayerInventory) {
((PlayerInventory) inv).equipItem(mobEquipmentPacket.hotbarSlot);
}

this.inventory.equipItem(mobEquipmentPacket.hotbarSlot);
this.setUsingItem(false);
return;
case ProtocolInfo.PLAYER_ACTION_PACKET:
Expand Down Expand Up @@ -3377,7 +3373,6 @@ public void onCompletion(Server server) {
return;
case PlayerActionPacket.ACTION_START_SPIN_ATTACK:
if (this.inventory == null) {
this.getServer().getLogger().debug(username + ": got ACTION_START_SPIN_ATTACK but inventory was null");
break stopItemHold;
}

Expand Down Expand Up @@ -3543,7 +3538,6 @@ public void onCompletion(Server server) {
}

if (this.inventory == null) {
this.getServer().getLogger().debug(username + ": got block pick request but inventory was null");
return;
}

Expand Down Expand Up @@ -3627,10 +3621,8 @@ public void onCompletion(Server server) {

AnimatePacket animatePacket = (AnimatePacket) packet;

if (animatePacket.action == null // Illegal action ID
|| animatePacket.action == AnimatePacket.Action.WAKE_UP // These actions are server to client only
|| animatePacket.action == AnimatePacket.Action.CRITICAL_HIT
|| animatePacket.action == AnimatePacket.Action.MAGIC_CRITICAL_HIT) {
if (animatePacket.action != AnimatePacket.Action.SWING_ARM &&
!(this.riding != null && (animatePacket.action == AnimatePacket.Action.ROW_LEFT || animatePacket.action == AnimatePacket.Action.ROW_RIGHT))) {
return;
}

Expand Down Expand Up @@ -3818,7 +3810,6 @@ public void onCompletion(Server server) {
return;
case ProtocolInfo.MAP_INFO_REQUEST_PACKET:
if (this.inventory == null) {
this.getServer().getLogger().debug(username + ": got map info request but inventory was null");
return;
}

Expand Down Expand Up @@ -3914,6 +3905,7 @@ public void onCompletion(Server server) {

InventoryTransactionPacket transactionPacket = (InventoryTransactionPacket) packet;

Inventory inv;
if ((transactionPacket.transactionType == InventoryTransactionPacket.TYPE_MISMATCH ||
(transactionPacket.transactionType == InventoryTransactionPacket.TYPE_NORMAL && this.isCreative() && Arrays.stream(transactionPacket.actions).anyMatch(action -> action.sourceType == NetworkInventoryAction.SOURCE_TODO)))
&& (inv = getWindowById(SMITHING_WINDOW_ID)) instanceof SmithingInventory) {
Expand Down Expand Up @@ -4417,6 +4409,16 @@ public void onCompletion(Server server) {

this.setUsingItem(false);

if (this.sleeping != null) {
this.getServer().getLogger().debug(username + ": USE_ITEM_ON_ENTITY_ACTION_ATTACK while sleeping");
return;
}

if (this.inventoryOpen) {
this.getServer().getLogger().debug(username + ": USE_ITEM_ON_ENTITY_ACTION_ATTACK while viewing inventory");
return;
}

this.setShieldBlockingDelay(5);

if (server.attackStopSprint) {
Expand Down Expand Up @@ -4512,8 +4514,7 @@ public void onCompletion(Server server) {
}
return;
case ProtocolInfo.PLAYER_HOTBAR_PACKET:
if (this.inventory == null) {
this.getServer().getLogger().debug(username + ": got PlayerHotbarPacket but inventory was null");
if (!this.spawned || !this.isAlive()) {
return;
}

Expand All @@ -4523,6 +4524,10 @@ public void onCompletion(Server server) {
return;
}

if (this.inventory == null) {
return;
}

this.inventory.equipItem(hotbarPacket.selectedHotbarSlot);
this.setUsingItem(false);
return;
Expand Down Expand Up @@ -4566,7 +4571,6 @@ public void onCompletion(Server server) {
}

if (this.inventory == null) {
this.getServer().getLogger().debug(username + ": got BookEditPacket but inventory was null");
return;
}

Expand Down Expand Up @@ -6840,7 +6844,7 @@ public boolean pickupEntity(Entity entity, boolean near) {

Item item = ((EntityThrownTrident) entity).getItem();

if (item.hasEnchantment(Enchantment.ID_TRIDENT_LOYALTY) && !this.equals(((EntityProjectile) entity).shootingEntity)) {
if (((EntityProjectile) entity).shootingEntity != null && item.hasEnchantment(Enchantment.ID_TRIDENT_LOYALTY) && !this.equals(((EntityProjectile) entity).shootingEntity)) {
return false;
}

Expand Down
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 @@ -1824,7 +1824,7 @@ private void saveOfflinePlayerDataInternal(PlayerDataSerializer serializer, Comp
try (OutputStream dataStream = serializer.write(name, uuid)) {
NBTIO.writeGZIPCompressed(tag, dataStream, ByteOrder.BIG_ENDIAN);
} catch (Exception e) {
log.error(this.getLanguage().translateString("nukkit.data.saveError", name, e));
log.error(this.getLanguage().translateString("nukkit.data.saveError", name, e), e);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cn/nukkit/block/BlockHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public boolean onActivate(Item item, Player player) {
BlockEntity blockEntity = this.level.getBlockEntity(this);

if (blockEntity instanceof BlockEntityHopper) {
return player.addWindow(((BlockEntityHopper) blockEntity).getInventory()) != -1;
player.addWindow(((BlockEntityHopper) blockEntity).getInventory());
return true;
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/block/BlockRespawnAnchor.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean onActivate(Item item, Player player) {
explosion.explodeA();
explosion.explodeB();
}
return false;
return true;
}

if (player != null && chargeLevel > 0 && this.level.getDimension() == Level.DIMENSION_NETHER) {
Expand All @@ -130,7 +130,7 @@ public boolean onActivate(Item item, Player player) {
}
}

return true;
return item.getId() == GLOWSTONE;
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/cn/nukkit/block/BlockTrapdoor.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,9 @@ public BlockFace getBlockFace() {
public boolean canPassThrough() {
return this.isOpen();
}

@Override
public WaterloggingType getWaterloggingType() {
return WaterloggingType.WHEN_PLACED_IN_WATER;
}
}
11 changes: 9 additions & 2 deletions src/main/java/cn/nukkit/blockentity/BlockEntityBeacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.inventory.Inventory;
import cn.nukkit.item.Item;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
Expand Down Expand Up @@ -271,6 +272,14 @@ public boolean updateCompoundTag(CompoundTag nbt, Player player) {
return false;
}

Inventory inv = player.getWindowById(Player.BEACON_WINDOW_ID);
if (inv != null) {
inv.setItem(0, Item.get(Item.AIR));
} else {
Server.getInstance().getLogger().debug(player.getName() + " tried to set effect but beacon inventory is null");
return false;
}

int primary = nbt.getInt("primary");
if (ALLOWED_EFFECTS.contains(primary)) {
this.setPrimaryPower(primary);
Expand All @@ -286,8 +295,6 @@ public boolean updateCompoundTag(CompoundTag nbt, Player player) {
}

this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_POWER);

player.getWindowById(Player.BEACON_WINDOW_ID).setItem(0, Item.get(Item.AIR));
return true;
}
}
27 changes: 14 additions & 13 deletions src/main/java/cn/nukkit/entity/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ public boolean entityBaseTick(int tickDiff) {
return false;
}

if (this.age % 10 == 0) {
this.blocksAround = null;
this.collisionBlocks = null;
if (this.onGround) {
if (level.getBlock(chunk, getFloorX(), getFloorY() - 1, getFloorZ(), false).canPassThrough()) {
this.onGround = false;
if (!this.isImmobile()) {
if (this.age % 10 == 0) {
if (this.onGround) {
if (level.getBlock(chunk, getFloorX(), getFloorY() - 1, getFloorZ(), false).canPassThrough()) {
this.onGround = false;
}
}
}
}

if (!this.onGround || Math.abs(this.motionX) > 0.1 || Math.abs(this.motionY) > 0.1 || Math.abs(this.motionZ) > 0.1) {
this.motionY -= 0.08f;
this.move(this.motionX, this.motionY, this.motionZ);
if (!this.onGround || Math.abs(this.motionX) > 0.1 || Math.abs(this.motionY) > 0.1 || Math.abs(this.motionZ) > 0.1) {
this.motionY -= 0.08f;
this.move(this.motionX, this.motionY, this.motionZ);
}

this.motionX *= 0.9;
this.motionY *= 0.9;
this.motionZ *= 0.9;
}

this.motionX *= 0.9;
this.motionY *= 0.9;
this.motionZ *= 0.9;
super.entityBaseTick(tickDiff); // updateMovement is called at the end of onUpdate after entityBaseTick is called
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public boolean isControlling(Entity entity) {
}

public boolean hasControllingPassenger() {
return !this.passengers.isEmpty() && isControlling(this.passengers.get(0));
return !this.passengers.isEmpty() && this.passengers.get(0) != null;
}

public Entity getRiding() {
Expand Down
30 changes: 11 additions & 19 deletions src/main/java/cn/nukkit/entity/EntityHumanType.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ public boolean attack(EntityDamageEvent source) {
} else if (damager != null && source.getCause() != DamageCause.THORNS) { // Do post attack only
for (int slot = 0; slot < 4; slot++) {
Item armor = this.inventory.getArmorItem(slot);
if (armor.hasEnchantments()) {
for (Enchantment enchantment : armor.getEnchantments()) {
enchantment.doPostAttack(damager, this);
}
for (Enchantment enchantment : armor.getEnchantments()) {
enchantment.doPostAttack(damager, this);
}
}
}
Expand All @@ -216,19 +214,17 @@ protected Item damageArmor(Item armor, Entity damager, float damage, boolean shi
return armor;
}

if (armor.hasEnchantments()) {
if (damager != null && cause != DamageCause.THORNS) {
for (Enchantment enchantment : armor.getEnchantments()) {
enchantment.doPostAttack(damager, this);
}
if (damager != null && cause != DamageCause.THORNS) {
for (Enchantment enchantment : armor.getEnchantments()) {
enchantment.doPostAttack(damager, this);
}
}

Enchantment durability = armor.getEnchantment(Enchantment.ID_DURABILITY);
if (durability != null
&& durability.getLevel() > 0
&& (100 / (durability.getLevel() + 1)) <= Utils.random.nextInt(100)) {
return armor;
}
Enchantment durability = armor.getEnchantment(Enchantment.ID_DURABILITY);
if (durability != null
&& durability.getLevel() > 0
&& (100 / (durability.getLevel() + 1)) <= Utils.random.nextInt(100)) {
return armor;
}

if (shield) {
Expand All @@ -246,10 +242,6 @@ protected Item damageArmor(Item armor, Entity damager, float damage, boolean shi


protected double calculateEnchantmentProtectionFactor(Item item, EntityDamageEvent source) {
if (!item.hasEnchantments()) {
return 0;
}

double epf = 0;

for (Enchantment ench : item.getEnchantments()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/entity/item/EntityFishingHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public boolean attractFish() {
private static final int[] rodEnchantments = {Enchantment.ID_LURE, Enchantment.ID_FORTUNE_FISHING, Enchantment.ID_DURABILITY, Enchantment.ID_MENDING, Enchantment.ID_VANISHING_CURSE};

public void reelLine() {
if (this.shootingEntity instanceof Player) {
if (this.shootingEntity instanceof Player && !this.closed) {
if (this.caught) {
Player player = (Player) this.shootingEntity;
Item item = Fishing.getFishingResult(this.rod);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/ItemBucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public boolean onActivate(Level level, Player player, Block block, Block target,
} else {
ev.setCancelled(!canBeFlowedInto);
}
if (!block.canBeFlowedInto()) {
if (!block.canBeFlowedInto() && !(block instanceof BlockTrapdoor)) {
ev.setCancelled(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/item/ItemFirework.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public boolean onActivate(Level level, Player player, Block block, Block target,

@Override
public boolean onClickAir(Player player, Vector3 directionVector) {
if (player.getInventory().getChestplateFast() instanceof ItemElytra && player.isGliding()) {
if (player.isGliding() && player.getInventory().getChestplateFast() instanceof ItemElytra) {
this.spawnFirework(player.getLevel(), player);

if (!player.isCreative()) {
Expand Down
Loading

0 comments on commit c05be0b

Please sign in to comment.