2019-11-28 01:30:30 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2019-11-28 01:30:30 +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.entity.type;
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2022-05-25 22:44:33 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
|
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
2019-10-09 18:39:38 +00:00
|
|
|
import com.nukkitx.math.vector.Vector3f;
|
2019-09-21 07:42:44 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket;
|
2022-05-25 19:55:15 +00:00
|
|
|
import org.geysermc.geyser.entity.EntityDefinition;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.level.PaintingType;
|
2022-05-25 19:55:15 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-11-18 03:02:38 +00:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2019-09-21 07:42:44 +00:00
|
|
|
public class PaintingEntity extends Entity {
|
|
|
|
private static final double OFFSET = -0.46875;
|
2022-05-25 22:44:33 +00:00
|
|
|
private final Direction direction;
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2022-05-25 22:44:33 +00:00
|
|
|
public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, Direction direction) {
|
2022-05-25 19:55:15 +00:00
|
|
|
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
2022-05-25 22:44:33 +00:00
|
|
|
this.direction = direction;
|
2019-09-21 07:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-11-18 03:02:38 +00:00
|
|
|
public void spawnEntity() {
|
2022-05-25 19:55:15 +00:00
|
|
|
// Wait until we get the metadata needed
|
|
|
|
}
|
|
|
|
|
2022-05-25 22:44:33 +00:00
|
|
|
public void setPaintingType(ObjectEntityMetadata<com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType> entityMetadata) {
|
|
|
|
PaintingType type = PaintingType.getByPaintingType(entityMetadata.getValue());
|
2019-09-21 07:42:44 +00:00
|
|
|
AddPaintingPacket addPaintingPacket = new AddPaintingPacket();
|
|
|
|
addPaintingPacket.setUniqueEntityId(geyserId);
|
|
|
|
addPaintingPacket.setRuntimeEntityId(geyserId);
|
2022-05-25 22:44:33 +00:00
|
|
|
addPaintingPacket.setMotive(type.getBedrockName());
|
|
|
|
addPaintingPacket.setPosition(fixOffset(type));
|
|
|
|
addPaintingPacket.setDirection(switch (direction) {
|
|
|
|
//TODO this doesn't seem right. Why did it work fine before?
|
|
|
|
case SOUTH -> 0;
|
|
|
|
case WEST -> 1;
|
|
|
|
case NORTH -> 2;
|
|
|
|
case EAST -> 3;
|
|
|
|
default -> 0;
|
|
|
|
});
|
2020-05-05 15:51:43 +00:00
|
|
|
session.sendUpstreamPacket(addPaintingPacket);
|
2019-09-21 07:42:44 +00:00
|
|
|
|
|
|
|
valid = true;
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
session.getGeyser().getLogger().debug("Spawned painting on " + position);
|
2019-09-21 07:42:44 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 23:58:06 +00:00
|
|
|
@Override
|
2021-11-18 03:02:38 +00:00
|
|
|
public void updateHeadLookRotation(float headYaw) {
|
2020-06-16 23:58:06 +00:00
|
|
|
// Do nothing, as head look messes up paintings
|
|
|
|
}
|
|
|
|
|
2022-05-25 22:44:33 +00:00
|
|
|
private Vector3f fixOffset(PaintingType paintingName) {
|
2021-08-21 13:54:52 +00:00
|
|
|
Vector3f position = super.position;
|
|
|
|
position = position.add(0.5, 0.5, 0.5);
|
|
|
|
double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
|
|
|
|
double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-09-10 18:10:56 +00:00
|
|
|
return switch (direction) {
|
2022-05-25 22:44:33 +00:00
|
|
|
case SOUTH -> position.add(widthOffset, heightOffset, OFFSET);
|
|
|
|
case WEST -> position.add(-OFFSET, heightOffset, widthOffset);
|
|
|
|
case NORTH -> position.add(-widthOffset, heightOffset, -OFFSET);
|
|
|
|
case EAST -> position.add(OFFSET, heightOffset, -widthOffset);
|
2021-09-10 18:10:56 +00:00
|
|
|
default -> position;
|
|
|
|
};
|
2019-09-21 07:42:44 +00:00
|
|
|
}
|
|
|
|
}
|