Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BlockEndPortalFrame #1493

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
80 changes: 17 additions & 63 deletions src/main/java/cn/nukkit/block/BlockEndPortalFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public boolean canBeActivated() {

@Override
public boolean onActivate(Item item, Player player) {
if((this.getDamage() & 0x04) == 0 && player != null && item.getId() == Item.ENDER_EYE) {
if ((this.getDamage() & 0x04) == 0 && player != null && item.getId() == Item.ENDER_EYE) {
this.setDamage(this.getDamage() + 4);
this.getLevel().setBlock(this, this, true, true);
this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BLOCK_END_PORTAL_FRAME_FILL);
Expand All @@ -90,78 +90,32 @@ public boolean onActivate(Item item, Player player) {
}

public void createPortal() {
Vector3 centerSpot = this.searchCenter();
if(centerSpot != null) {
for(int x = -2; x <= 2; x++) {
for(int z = -2; z <= 2; z++) {
if((x == -2 || x == 2) && (z == -2 || z == 2))
continue;
if(x == -2 || x == 2 || z == -2 || z == 2) {
if(!this.checkFrame(this.getLevel().getBlock(centerSpot.add(x, 0, z)), x, z)) {
return;
for (int i = 0; i < 4; i++) {
for (int j = -1; j <= 1; j++) {
Block side = this.getSide(BlockFace.fromHorizontalIndex(i), 2).getSide(BlockFace.fromHorizontalIndex((i + 1) % 4), j);
if (this.isCompletedPortal(side)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check the direction of the frame block.

for (int k = -1; k <= 1; k++) {
for (int l = -1; l <= 1; l++) {
this.getLevel().setBlock(side.add(k, 0, l), Block.get(Block.END_PORTAL), true);
}
}
}
}

for(int x = -1; x <= 1; x++) {
for(int z = -1; z <= 1; z++) {
Vector3 vector3 = centerSpot.add(x, 0, z);
if(this.getLevel().getBlock(vector3).getId() != Block.AIR) {
this.getLevel().useBreakOn(vector3);
}
this.getLevel().setBlock(vector3, Block.get(Block.END_PORTAL));
this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BLOCK_END_PORTAL_SPAWN);
return;
}
}
}
}

private Vector3 searchCenter() {
for(int x = -2; x <= 2; x++) {
if(x == 0)
continue;
Block block = this.getLevel().getBlock(this.add(x, 0, 0));
Block iBlock = this.getLevel().getBlock(this.add(x * 2, 0, 0));
if(this.checkFrame(block)) {
if((x == -1 || x == 1) && this.checkFrame(iBlock))
return ((BlockEndPortalFrame) block).searchCenter();
for(int z = -4; z <= 4; z++) {
if(z == 0)
continue;
block = this.getLevel().getBlock(this.add(x, 0, z));
if(this.checkFrame(block)) {
return this.add(x / 2, 0, z / 2);
}
}
}
}
for(int z = -2; z <= 2; z++) {
if(z == 0)
continue;
Block block = this.getLevel().getBlock(this.add(0, 0, z));
Block iBlock = this.getLevel().getBlock(this.add(0, 0, z * 2));
if(this.checkFrame(block)) {
if((z == -1 || z == 1) && this.checkFrame(iBlock))
return ((BlockEndPortalFrame) block).searchCenter();
for(int x = -4; x <= 4; x++) {
if(x == 0)
continue;
block = this.getLevel().getBlock(this.add(x, 0, z));
if(this.checkFrame(block)) {
return this.add(x / 2, 0, z / 2);
}
public boolean isCompletedPortal(Block center) {
for (int i = 0; i < 4; i++) {
for (int j = -1; j <= 1; j++) {
Block block = center.getSide(BlockFace.fromHorizontalIndex(i), 2).getSide(BlockFace.fromHorizontalIndex((i + 1) % 4), j);
if (block.getId() != Block.END_PORTAL_FRAME || (block.getDamage() & 0x4) == 0) {
return false;
}
}
}
return null;
}

private boolean checkFrame(Block block) {
return block.getId() == this.getId() && (block.getDamage() & 4) == 4;
}

private boolean checkFrame(Block block, int x, int z) {
return block.getId() == this.getId() && (block.getDamage() - 4) == (x == -2 ? 3 : x == 2 ? 1 : z == -2 ? 0 : z == 2 ? 2 : -1);
return true;
}

@Override
Expand Down