2020-11-20 19:56:39 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-11-20 19:56:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.collision;
|
2020-11-20 19:56:39 +00:00
|
|
|
|
2021-07-31 02:35:13 +00:00
|
|
|
import lombok.EqualsAndHashCode;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.level.physics.BoundingBox;
|
|
|
|
import org.geysermc.geyser.level.physics.CollisionManager;
|
2020-11-20 19:56:39 +00:00
|
|
|
|
2021-07-31 02:35:13 +00:00
|
|
|
@EqualsAndHashCode(callSuper = true)
|
2020-11-20 19:56:39 +00:00
|
|
|
@CollisionRemapper(regex = "_trapdoor$", usesParams = true, passDefaultBoxes = true)
|
|
|
|
public class TrapdoorCollision extends BlockCollision {
|
|
|
|
/**
|
|
|
|
* 1 = north
|
|
|
|
* 2 = east
|
|
|
|
* 3 = south
|
|
|
|
* 4 = west
|
|
|
|
* 5 = up
|
|
|
|
* 6 = down
|
|
|
|
*/
|
|
|
|
private int facing;
|
|
|
|
|
|
|
|
public TrapdoorCollision(String params, BoundingBox[] defaultBoxes) {
|
2021-07-31 02:35:13 +00:00
|
|
|
super(defaultBoxes);
|
2020-11-20 19:56:39 +00:00
|
|
|
if (params.contains("open=true")) {
|
|
|
|
if (params.contains("facing=north")) {
|
|
|
|
facing = 1;
|
|
|
|
} else if (params.contains("facing=east")) {
|
|
|
|
facing = 2;
|
|
|
|
} else if (params.contains("facing=south")) {
|
|
|
|
facing = 3;
|
|
|
|
} else if (params.contains("facing=west")) {
|
|
|
|
facing = 4;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (params.contains("half=bottom")) {
|
|
|
|
// Up
|
|
|
|
facing = 5;
|
|
|
|
} else {
|
|
|
|
// Down
|
|
|
|
facing = 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public boolean correctPosition(GeyserSession session, int x, int y, int z, BoundingBox playerCollision) {
|
2021-09-26 14:16:22 +00:00
|
|
|
boolean result = super.correctPosition(session, x, y, z, playerCollision);
|
2020-11-20 19:56:39 +00:00
|
|
|
// Check for door bug (doors are 0.1875 blocks thick on Java but 0.1825 blocks thick on Bedrock)
|
2021-09-26 14:16:22 +00:00
|
|
|
if (this.checkIntersection(x, y, z, playerCollision)) {
|
2020-11-20 19:56:39 +00:00
|
|
|
switch (facing) {
|
|
|
|
case 1: // North
|
2021-07-31 02:35:13 +00:00
|
|
|
playerCollision.setMiddleZ(z + 0.5125);
|
|
|
|
break;
|
|
|
|
case 2: // East
|
|
|
|
playerCollision.setMiddleX(x + 0.5125);
|
2020-11-20 19:56:39 +00:00
|
|
|
break;
|
|
|
|
case 3: // South
|
2021-07-31 02:35:13 +00:00
|
|
|
playerCollision.setMiddleZ(z + 0.4875);
|
2020-11-20 19:56:39 +00:00
|
|
|
break;
|
|
|
|
case 4: // West
|
2021-07-31 02:35:13 +00:00
|
|
|
playerCollision.setMiddleX(x + 0.4875);
|
2020-11-20 19:56:39 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2021-07-31 02:35:13 +00:00
|
|
|
// Up-facing trapdoors are handled by the step-up check
|
|
|
|
break;
|
|
|
|
case 6: // Down
|
|
|
|
// (top y of trap door) - (trap door thickness) = top y of player
|
|
|
|
playerCollision.setMiddleY(y + 1 - (3.0 / 16.0) - playerCollision.getSizeY() / 2.0 - CollisionManager.COLLISION_TOLERANCE);
|
2020-11-20 19:56:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|