Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 78 additions & 18 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,11 @@ protected void checkBlockCollision() {

if (this.inPortalTicks == (this.gamemode == CREATIVE ? 1 : 80)) {
EntityPortalEnterEvent ev = new EntityPortalEnterEvent(this, EntityPortalEnterEvent.PortalType.NETHER);

if (this.portalPos == null) {
ev.setCancelled();
}

this.getServer().getPluginManager().callEvent(ev);

if (ev.isCancelled()) {
Expand Down Expand Up @@ -2379,7 +2384,7 @@ public boolean onUpdate(int currentTick) {
Item elytra = inv.getChestplate();
if (elytra == null || elytra.getId() != ItemID.ELYTRA) {
this.setGliding(false);
} else if ((this.gamemode & 0x01) == 0 && this.age % (20 * (elytra.getEnchantmentLevel(Enchantment.ID_DURABILITY) + 1)) == 0) {
} else if ((this.gamemode & 0x01) == 0 && this.age % (20 * (elytra.getEnchantmentLevel(Enchantment.ID_DURABILITY) + 1)) == 0 && !elytra.isUnbreakable()) {
elytra.setDamage(elytra.getDamage() + 1);
if (elytra.getDamage() >= elytra.getMaxDurability()) {
this.setGliding(false);
Expand Down Expand Up @@ -3338,6 +3343,48 @@ public void onCompletion(Server server) {
}
}

if (authPacket.getInputData().contains(AuthInputAction.START_SPIN_ATTACK)) {
Enchantment riptide = this.getInventory().getItemInHandFast().getEnchantment(Enchantment.ID_TRIDENT_RIPTIDE);
if (riptide != null) {
PlayerToggleSpinAttackEvent playerToggleSpinAttackEvent = new PlayerToggleSpinAttackEvent(this, true);

if (riptide.getLevel() < 1) {
playerToggleSpinAttackEvent.setCancelled(true);
} else {
boolean inWater = false;
for (Block block : this.getCollisionBlocks()) {
if (block instanceof BlockWater || block.level.isBlockWaterloggedAt(this.chunk, (int) block.x, (int) block.y, (int) block.z)) {
inWater = true;
break;
}
}
if (!(inWater || (this.getLevel().isRaining() && this.canSeeSky()))) {
playerToggleSpinAttackEvent.setCancelled(true);
}
}

server.getPluginManager().callEvent(playerToggleSpinAttackEvent);

if (playerToggleSpinAttackEvent.isCancelled()) {
this.setNeedSendData(true);
} else {
this.onSpinAttack(riptide.getLevel());
this.setSpinAttack(true);
this.setUsingItem(false);
this.resetFallDistance();
int riptideSound;
if (riptide.getLevel() >= 3) {
riptideSound = LevelSoundEventPacket.SOUND_ITEM_TRIDENT_RIPTIDE_3;
} else if (riptide.getLevel() == 2) {
riptideSound = LevelSoundEventPacket.SOUND_ITEM_TRIDENT_RIPTIDE_2;
} else {
riptideSound = LevelSoundEventPacket.SOUND_ITEM_TRIDENT_RIPTIDE_1;
}
this.getLevel().addLevelSoundEvent(this, riptideSound);
}
}
}

if (authPacket.getInputData().contains(AuthInputAction.STOP_SPIN_ATTACK)) {
PlayerToggleSpinAttackEvent playerToggleSpinAttackEvent = new PlayerToggleSpinAttackEvent(this, false);
this.server.getPluginManager().callEvent(playerToggleSpinAttackEvent);
Expand Down Expand Up @@ -3554,6 +3601,8 @@ public void onCompletion(Server server) {
this.inventoryOpen = true;
this.awardAchievement("openInventory");
}
} else if (Nukkit.DEBUG > 1) {
server.getLogger().debug(this.username + " tried to open inventory but one is already open");
}
return;
case InteractPacket.ACTION_MOUSEOVER:
Expand Down Expand Up @@ -3764,36 +3813,47 @@ public void onCompletion(Server server) {
return;
case ProtocolInfo.CONTAINER_CLOSE_PACKET:
ContainerClosePacket containerClosePacket = (ContainerClosePacket) packet;
if (!this.spawned || (containerClosePacket.windowId == ContainerIds.INVENTORY && !inventoryOpen)) {
return;
}

if (this.windowIndex.containsKey(containerClosePacket.windowId)) {
this.server.getPluginManager().callEvent(new InventoryCloseEvent(this.windowIndex.get(containerClosePacket.windowId), this));
if (containerClosePacket.windowId == ContainerIds.INVENTORY) this.inventoryOpen = false;
this.closingWindowId = containerClosePacket.windowId;
this.removeWindow(this.windowIndex.get(containerClosePacket.windowId), true);
this.closingWindowId = Integer.MIN_VALUE;
if (!this.spawned) {
return;
}

if (containerClosePacket.windowId == -1) {
// At least 1.21 does sometimes send windowId -1 when opening and closing containers quickly
if (this.inventoryOpen) {
this.inventoryOpen = false;

if (this.craftingType == CRAFTING_SMALL) {
for (Entry<Inventory, Integer> open : new ArrayList<>(this.windows.entrySet())) {
if (open.getKey() instanceof ContainerInventory || open.getKey() instanceof PlayerEnderChestInventory) {
this.server.getPluginManager().callEvent(new InventoryCloseEvent(open.getKey(), this));
this.closingWindowId = Integer.MAX_VALUE;
this.removeWindow(open.getKey(), true);
this.closingWindowId = Integer.MIN_VALUE;
}
}
return;
}
}

this.resetCraftingGridType();
this.addWindow(this.craftingGrid, ContainerIds.NONE);
ContainerClosePacket pk = new ContainerClosePacket();
pk.windowId = -1;
pk.wasServerInitiated = false;
this.dataPacket(pk);
} else { // TODO: check this
} else if (this.windowIndex.containsKey(containerClosePacket.windowId)) {
this.inventoryOpen = false;
Inventory inn = this.windowIndex.get(containerClosePacket.windowId);
this.server.getPluginManager().callEvent(new InventoryCloseEvent(inn, this));
this.closingWindowId = containerClosePacket.windowId;
this.removeWindow(inn, true);
this.closingWindowId = Integer.MIN_VALUE;
} else { // Close the bugged inventory client refused with id -1 above
ContainerClosePacket pk = new ContainerClosePacket();
pk.windowId = containerClosePacket.windowId;
pk.wasServerInitiated = false;
this.dataPacket(pk);

for (Inventory open : new ArrayList<>(this.windows.keySet())) {
if (open instanceof ContainerInventory) {
this.removeWindow(open);
}
}
}
return;
case ProtocolInfo.BLOCK_ENTITY_DATA_PACKET:
Expand Down Expand Up @@ -6494,7 +6554,7 @@ public void resetCraftingGridType() {
*/
private void moveBlockUIContents(int window) {
Inventory inventory = this.getWindowById(window);
if (inventory != null && !(inventory instanceof ContainerInventory)) {
if (inventory instanceof FakeBlockUIComponent) {
Item[] drops = this.inventory.addItem(inventory.getContents().values().toArray(new Item[0]));
inventory.clearAll();
for (Item drop : drops) {
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBambooBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package cn.nukkit.block;

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

public class BlockBambooBlock extends BlockWood {

public BlockBambooBlock() {
this(0);
}

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

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

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

@Override
protected int getStrippedId() {
return STRIPPED_BAMBOO_BLOCK;
}

@Override
protected int getStrippedDamage() {
return getDamage();
}

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

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
this.setPillarAxis(face.getAxis());
return this.getLevel().setBlock(block, this, true, true);
}

public void setPillarAxis(BlockFace.Axis axis) {
switch (axis) {
case Y:
this.setDamage(0);
break;
case X:
this.setDamage(1);
break;
case Z:
this.setDamage(2);
break;
}
}

public BlockFace.Axis getPillarAxis() {
switch (this.getDamage() % 3) {
case 2:
return BlockFace.Axis.Z;
case 1:
return BlockFace.Axis.X;
case 0:
default:
return BlockFace.Axis.Y;
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBambooButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nukkit.block;

public class BlockBambooButton extends BlockButtonWooden {

public BlockBambooButton() {
this(0);
}

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

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

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

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

public class BlockBambooDoor extends BlockDoorWood {

public BlockBambooDoor() {
this(0);
}

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

@Override
public String getName() {
return "Bamboo Door Block";
}

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

@Override
public Item toItem() {
return Item.get(Item.BAMBOO_DOOR);
}

@Override
public BlockColor getColor() {
return BlockColor.YELLOW_BLOCK_COLOR;
}
}
34 changes: 34 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBambooDoubleSlab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cn.nukkit.block;

import cn.nukkit.utils.BlockColor;

public class BlockBambooDoubleSlab extends BlockDoubleSlabWood {

public BlockBambooDoubleSlab() {
this(0);
}

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

@Override
public String getName() {
return "Bamboo Double Slab";
}

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

@Override
public int getSingleSlabId() {
return BAMBOO_SLAB;
}

@Override
public BlockColor getColor() {
return BlockColor.YELLOW_BLOCK_COLOR;
}
}
36 changes: 36 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBambooFence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cn.nukkit.block;

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

public class BlockBambooFence extends BlockFence {

public BlockBambooFence() {
this(0);
}

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

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

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

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

@Override
public BlockColor getColor() {
return BlockColor.YELLOW_BLOCK_COLOR;
}
}
29 changes: 29 additions & 0 deletions src/main/java/cn/nukkit/block/BlockBambooFenceGate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.nukkit.block;

import cn.nukkit.utils.BlockColor;

public class BlockBambooFenceGate extends BlockFenceGate {

public BlockBambooFenceGate() {
this(0);
}

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

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

@Override
public String getName() {
return "Bamboo Fence Gate";
}

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