Now: full entity support, here: add experience orb support

This commit is contained in:
bixilon 2020-06-13 00:51:02 +02:00
parent 81e550d71e
commit 07be1645cf
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 117 additions and 3 deletions

View File

@ -0,0 +1,56 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.game.datatypes.entities;
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
public class ExperienceOrb extends Entity {
EntityMetaData metaData;
short count;
public ExperienceOrb(int id, Location location, short count) {
super(id, location, 0, 0, null);
this.count = count;
}
@Override
public EntityMetaData getMetaData() {
return metaData;
}
@Override
public void setMetaData(EntityMetaData metaData) {
this.metaData = metaData;
}
@Override
public float getWidth() {
return 0.5F;
}
@Override
public float getHeight() {
return 0.5F;
}
@Override
public Class<? extends EntityMetaData> getMetaDataClass() {
return EntityMetaData.class;
}
public short getCount() {
return count;
}
}

View File

@ -0,0 +1,53 @@
/*
* Codename Minosoft
* Copyright (C) 2020 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.game.datatypes.entities.ExperienceOrb;
import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
public class PacketSpawnExperienceOrb implements ClientboundPacket {
ExperienceOrb orb;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
int entityId = buffer.readVarInt();
Location location = new Location(buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger(), buffer.readFixedPointNumberInteger());
short count = buffer.readShort();
orb = new ExperienceOrb(entityId, location, count);
break;
}
}
@Override
public void log() {
Log.protocol(String.format("Experience orb spawned (entityId=%d, count=%d, at %s)", orb.getId(), orb.getCount(), orb.getLocation().toString()));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public ExperienceOrb getOrb() {
return orb;
}
}

View File

@ -38,7 +38,7 @@ public class PacketSpawnLocation implements ClientboundPacket {
@Override
public void log() {
Log.protocol(String.format("Received spawn location %s %s %s", loc.getX(), loc.getY(), loc.getZ()));
Log.protocol(String.format("Received spawn location %s", loc.toString()));
}
public Location getSpawnLocation() {

View File

@ -43,7 +43,7 @@ public class PacketSpawnMob implements ClientboundPacket {
assert type != null;
try {
mob = (Mob) type.getClazz().getConstructor(int.class, Location.class, int.class, int.class, Velocity.class, InByteBuffer.class, ProtocolVersion.class).newInstance(entityId, location, yaw, pitch, velocity, buffer, v);
mob = type.getClazz().getConstructor(int.class, Location.class, int.class, int.class, Velocity.class, InByteBuffer.class, ProtocolVersion.class).newInstance(entityId, location, yaw, pitch, velocity, buffer, v);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
@ -53,7 +53,7 @@ public class PacketSpawnMob implements ClientboundPacket {
@Override
public void log() {
Log.protocol(String.format("Mob spawned (entityId=%d, type=%s, at %s %s %s)", mob.getId(), mob.getEntityType().name(), mob.getLocation().getX(), mob.getLocation().getY(), mob.getLocation().getZ()));
Log.protocol(String.format("Mob spawned (entityId=%d, type=%s, at %s)", mob.getId(), mob.getEntityType().name(), mob.getLocation().toString()));
}
public Mob getMob() {

View File

@ -231,4 +231,8 @@ public class PacketHandler {
public void handle(PacketSpawnObject pkg) {
connection.getPlayer().getWorld().addEntity(pkg.getObject());
}
public void handle(PacketSpawnExperienceOrb pkg) {
connection.getPlayer().getWorld().addEntity(pkg.getOrb());
}
}

View File

@ -79,5 +79,6 @@ public interface Protocol {
packetClassMapping.put(Packets.Clientbound.PLAY_RESPAWN, PacketRespawn.class);
packetClassMapping.put(Packets.Clientbound.PLAY_OPEN_SIGN_EDITOR, PacketOpenSignEditor.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_OBJECT, PacketSpawnObject.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_EXPERIENCE_ORB, PacketSpawnExperienceOrb.class);
}
}