Paintings work

This commit is contained in:
Camotoy 2022-05-25 18:44:33 -04:00
parent bbf45b6a4c
commit 193fa23146
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
6 changed files with 35 additions and 28 deletions

View file

@ -272,8 +272,9 @@ public final class EntityDefinitions {
.type(EntityType.LLAMA_SPIT)
.heightAndWidth(0.25f)
.build();
PAINTING = EntityDefinition.inherited(PaintingEntity::new, entityBase)
PAINTING = EntityDefinition.<PaintingEntity>inherited(null, entityBase)
.type(EntityType.PAINTING)
.addTranslator(MetadataType.PAINTING_VARIANT, PaintingEntity::setPaintingType)
.build();
SHULKER_BULLET = EntityDefinition.inherited(ThrowableEntity::new, entityBase)
.type(EntityType.SHULKER_BULLET)
@ -871,7 +872,7 @@ public final class EntityDefinitions {
CAT = EntityDefinition.inherited(CatEntity::new, tameableEntityBase)
.type(EntityType.CAT)
.height(0.35f).width(0.3f)
.addTranslator(MetadataType.INT, CatEntity::setCatVariant)
.addTranslator(MetadataType.CAT_VARIANT, CatEntity::setCatVariant)
.addTranslator(MetadataType.BOOLEAN, CatEntity::setResting)
.addTranslator(null) // "resting state one" //TODO
.addTranslator(MetadataType.INT, CatEntity::setCollarColor)

View file

@ -25,6 +25,8 @@
package org.geysermc.geyser.entity.type;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket;
import org.geysermc.geyser.entity.EntityDefinition;
@ -35,11 +37,11 @@ import java.util.UUID;
public class PaintingEntity extends Entity {
private static final double OFFSET = -0.46875;
private PaintingType paintingName;
private int direction;
private final Direction direction;
public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
public PaintingEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw, Direction direction) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
this.direction = direction;
}
@Override
@ -47,13 +49,21 @@ public class PaintingEntity extends Entity {
// Wait until we get the metadata needed
}
public void paintingtodo() {
public void setPaintingType(ObjectEntityMetadata<com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType> entityMetadata) {
PaintingType type = PaintingType.getByPaintingType(entityMetadata.getValue());
AddPaintingPacket addPaintingPacket = new AddPaintingPacket();
addPaintingPacket.setUniqueEntityId(geyserId);
addPaintingPacket.setRuntimeEntityId(geyserId);
addPaintingPacket.setMotive(paintingName.getBedrockName());
addPaintingPacket.setPosition(fixOffset());
addPaintingPacket.setDirection(direction);
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;
});
session.sendUpstreamPacket(addPaintingPacket);
valid = true;
@ -66,17 +76,17 @@ public class PaintingEntity extends Entity {
// Do nothing, as head look messes up paintings
}
private Vector3f fixOffset() {
private Vector3f fixOffset(PaintingType paintingName) {
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;
return switch (direction) {
case 0 -> position.add(widthOffset, heightOffset, OFFSET);
case 1 -> position.add(-OFFSET, heightOffset, widthOffset);
case 2 -> position.add(-widthOffset, heightOffset, -OFFSET);
case 3 -> position.add(OFFSET, heightOffset, -widthOffset);
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);
default -> position;
};
}

View file

@ -60,13 +60,9 @@ public enum PaintingType {
BURNING_SKULL("BurningSkull", 4, 4);
private static final PaintingType[] VALUES = values();
private String bedrockName;
private int width;
private int height;
public com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType toJavaType() {
return com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType.valueOf(name());
}
private final String bedrockName;
private final int width;
private final int height;
public static PaintingType getByName(String javaName) {
for (PaintingType paintingName : VALUES) {

View file

@ -69,7 +69,6 @@ public class TagCache {
}
public void loadPacket(GeyserSession session, ClientboundUpdateTagsPacket packet) {
System.out.println(packet);
Map<String, int[]> blockTags = packet.getTags().get("minecraft:block");
this.leaves = IntList.of(blockTags.get("minecraft:leaves"));
this.wool = IntList.of(blockTags.get("minecraft:wool"));

View file

@ -106,10 +106,12 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
session.setGameMode(packet.getGameMode());
String newDimension = packet.getDimension();
boolean needsSpawnPacket = !session.isSentSpawnPacket();
if (needsSpawnPacket) {
// The player has yet to spawn so let's do that using some of the information in this Java packet
//session.setDimension(newDimension);
session.setDimension(newDimension);
session.connect();
}
@ -145,7 +147,6 @@ public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:register", PluginMessageChannels.getFloodgateRegisterData()));
}
String newDimension = packet.getDimension();
if (!newDimension.equals(session.getDimension())) {
DimensionUtils.switchDimension(session, newDimension);
} else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {

View file

@ -32,10 +32,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
import com.nukkitx.math.vector.Vector3f;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.entity.type.FallingBlockEntity;
import org.geysermc.geyser.entity.type.FishingHookEntity;
import org.geysermc.geyser.entity.type.ItemFrameEntity;
import org.geysermc.geyser.entity.type.*;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.registry.Registries;
import org.geysermc.geyser.session.GeyserSession;
@ -68,6 +65,9 @@ public class JavaAddEntityTranslator extends PacketTranslator<ClientboundAddEnti
// Item frames need the hanging direction
entity = new ItemFrameEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(),
definition, position, motion, yaw, pitch, headYaw, (Direction) packet.getData());
} else if (packet.getType() == EntityType.PAINTING) {
entity = new PaintingEntity(session, packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), packet.getUuid(),
definition, position, motion, yaw, pitch, headYaw, (Direction) packet.getData());
} else if (packet.getType() == EntityType.FISHING_BOBBER) {
// Fishing bobbers need the owner for the line
int ownerEntityId = ((ProjectileData) packet.getData()).getOwnerId();