mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 16:01:50 -04:00
wip (3) entities
This commit is contained in:
parent
3d6edb64f9
commit
21d2c7c69d
@ -23,8 +23,8 @@ import java.util.Map;
|
|||||||
* Collection of ChunkColumns
|
* Collection of ChunkColumns
|
||||||
*/
|
*/
|
||||||
public class World {
|
public class World {
|
||||||
public final HashMap<ChunkLocation, Chunk> chunks;
|
final HashMap<ChunkLocation, Chunk> chunks;
|
||||||
public final HashMap<Integer, Entity> entities;
|
final HashMap<Integer, Entity> entities;
|
||||||
final String name;
|
final String name;
|
||||||
boolean hardcore;
|
boolean hardcore;
|
||||||
boolean raining;
|
boolean raining;
|
||||||
@ -87,4 +87,16 @@ public class World {
|
|||||||
public void setRaining(boolean raining) {
|
public void setRaining(boolean raining) {
|
||||||
this.raining = raining;
|
this.raining = raining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addEntity(Entity entity) {
|
||||||
|
this.entities.put(entity.getId(), entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Entity getEntity(int id) {
|
||||||
|
return entities.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeEntity(Entity entity) {
|
||||||
|
this.entities.remove(entity.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
package de.bixilon.minosoft.game.datatypes.entities;
|
package de.bixilon.minosoft.game.datatypes.entities;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity {
|
||||||
Entities getEntityType();
|
Mobs getEntityType();
|
||||||
|
|
||||||
int getId();
|
int getId();
|
||||||
|
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
public interface Mob extends Entity {
|
||||||
|
float getHealth();
|
||||||
|
|
||||||
|
void setHealth(float health);
|
||||||
|
}
|
@ -15,21 +15,21 @@ package de.bixilon.minosoft.game.datatypes.entities;
|
|||||||
|
|
||||||
import de.bixilon.minosoft.game.datatypes.Identifier;
|
import de.bixilon.minosoft.game.datatypes.Identifier;
|
||||||
|
|
||||||
public enum Entities {
|
public enum Mobs {
|
||||||
ZOMBIE(new Identifier("zombie"), 54, Zombie.class);
|
ZOMBIE(new Identifier("zombie"), 54, Zombie.class);
|
||||||
|
|
||||||
final Identifier identifier;
|
final Identifier identifier;
|
||||||
final int type;
|
final int type;
|
||||||
final Class<? extends Entity> clazz;
|
final Class<? extends Entity> clazz;
|
||||||
|
|
||||||
Entities(Identifier identifier, int type, Class<? extends Entity> clazz) {
|
Mobs(Identifier identifier, int type, Class<? extends Entity> clazz) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entities byIdentifier(Identifier identifier) {
|
public static Mobs byIdentifier(Identifier identifier) {
|
||||||
for (Entities b : values()) {
|
for (Mobs b : values()) {
|
||||||
if (b.getIdentifier().equals(identifier)) {
|
if (b.getIdentifier().equals(identifier)) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -37,8 +37,8 @@ public enum Entities {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entities byType(int type) {
|
public static Mobs byType(int type) {
|
||||||
for (Entities b : values()) {
|
for (Mobs b : values()) {
|
||||||
if (b.getType() == type) {
|
if (b.getType() == type) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
@ -13,21 +13,28 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.game.datatypes.entities;
|
package de.bixilon.minosoft.game.datatypes.entities;
|
||||||
|
|
||||||
public class Zombie implements Entity {
|
|
||||||
|
public class Zombie implements Mob {
|
||||||
final int id;
|
final int id;
|
||||||
Location location;
|
Location location;
|
||||||
Velocity velocity;
|
Velocity velocity;
|
||||||
int yaw;
|
int yaw;
|
||||||
int pitch;
|
int pitch;
|
||||||
EntityMetaData data;
|
EntityMetaData metaData;
|
||||||
|
float health;
|
||||||
|
|
||||||
public Zombie(int id) {
|
public Zombie(int id, Location location, int yaw, int pitch, Velocity velocity, EntityMetaData metaData) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.location = location;
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
this.velocity = velocity;
|
||||||
|
this.metaData = metaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Entities getEntityType() {
|
public Mobs getEntityType() {
|
||||||
return Entities.ZOMBIE;
|
return Mobs.ZOMBIE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -79,21 +86,31 @@ public class Zombie implements Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getWidth() {
|
public float getWidth() {
|
||||||
return 0;
|
return 0.6F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getHeight() {
|
public float getHeight() {
|
||||||
return 0;
|
return 1.95F;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityMetaData getMetaData() {
|
public EntityMetaData getMetaData() {
|
||||||
return data;
|
return metaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMetaData(EntityMetaData data) {
|
public void setMetaData(EntityMetaData data) {
|
||||||
this.data = data;
|
this.metaData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHealth(float health) {
|
||||||
|
this.health = health;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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.*;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
|
public class PacketSpawnMob implements ClientboundPacket {
|
||||||
|
Mob mob;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||||
|
switch (v) {
|
||||||
|
case VERSION_1_7_10:
|
||||||
|
int entityId = buffer.readVarInt();
|
||||||
|
Mobs type = Mobs.byType(buffer.readByte());
|
||||||
|
Location location = new Location(buffer.readFixedPointNumber(), buffer.readFixedPointNumber(), buffer.readFixedPointNumber());
|
||||||
|
int yaw = buffer.readByte(); //ToDo
|
||||||
|
int pitch = buffer.readByte();
|
||||||
|
int headPitch = buffer.readByte();
|
||||||
|
Velocity velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());
|
||||||
|
EntityMetaData metaData = buffer.readEntityMetaData();
|
||||||
|
|
||||||
|
assert type != null;
|
||||||
|
try {
|
||||||
|
mob = (Mob) type.getClazz().getConstructor(int.class, Location.class, int.class, int.class, Velocity.class, EntityMetaData.class).newInstance(entityId, location, yaw, pitch, velocity, metaData);
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mob getMob() {
|
||||||
|
return mob;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(PacketHandler h) {
|
||||||
|
h.handle(this);
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.protocol.protocol;
|
|||||||
|
|
||||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||||
import de.bixilon.minosoft.game.datatypes.ChatComponent;
|
import de.bixilon.minosoft.game.datatypes.ChatComponent;
|
||||||
|
import de.bixilon.minosoft.game.datatypes.entities.EntityMetaData;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -141,6 +142,10 @@ public class InByteBuffer {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double readFixedPointNumber() {
|
||||||
|
return readInteger() / 32.0D;
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject readJson() {
|
public JSONObject readJson() {
|
||||||
return new JSONObject(readString());
|
return new JSONObject(readString());
|
||||||
}
|
}
|
||||||
@ -170,4 +175,9 @@ public class InByteBuffer {
|
|||||||
public int getBytesLeft() {
|
public int getBytesLeft() {
|
||||||
return bytes.length - pos;
|
return bytes.length - pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityMetaData readEntityMetaData() {
|
||||||
|
//ToDo
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,10 @@ public class OutByteBuffer {
|
|||||||
} while (value != 0);
|
} while (value != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void writeFixedPointNumber(double d) {
|
||||||
|
writeInteger((int) (d * 32.0D));
|
||||||
|
}
|
||||||
|
|
||||||
public List<Byte> getBytes() {
|
public List<Byte> getBytes() {
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
@ -142,4 +142,8 @@ public class PacketHandler {
|
|||||||
//ToDo: handle all updates
|
//ToDo: handle all updates
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(PacketSpawnMob pkg) {
|
||||||
|
connection.getPlayer().getWorld().addEntity(pkg.getMob());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public class Packets {
|
|||||||
LOGIN_LOGIN_SUCCESS,
|
LOGIN_LOGIN_SUCCESS,
|
||||||
LOGIN_SET_COMPRESSION,
|
LOGIN_SET_COMPRESSION,
|
||||||
LOGIN_PLUGIN_REQUEST,
|
LOGIN_PLUGIN_REQUEST,
|
||||||
PLAY_SPAWN_ENTITY,
|
PLAY_SPAWN_MOB,
|
||||||
PLAY_SPAWN_EXPERIENCE_ORB,
|
PLAY_SPAWN_EXPERIENCE_ORB,
|
||||||
PLAY_SPAWN_WEATHER_ENTITY,
|
PLAY_SPAWN_WEATHER_ENTITY,
|
||||||
PLAY_SPAWN_LIVING_ENTITY,
|
PLAY_SPAWN_LIVING_ENTITY,
|
||||||
@ -174,7 +174,7 @@ public class Packets {
|
|||||||
PLAY_UPDATE_VIEW_DISTANCE,
|
PLAY_UPDATE_VIEW_DISTANCE,
|
||||||
PLAY_CHUNK_BULK,
|
PLAY_CHUNK_BULK,
|
||||||
PLAY_UPDATE_SIGN,
|
PLAY_UPDATE_SIGN,
|
||||||
PLAY_STATISTICS
|
PLAY_STATISTICS,
|
||||||
|
PLAY_SPAWN_OBJECT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,5 +62,6 @@ public interface Protocol {
|
|||||||
packetClassMapping.put(Packets.Clientbound.PLAY_HELD_ITEM_CHANGE, PacketHeldItemChangeReceiving.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_HELD_ITEM_CHANGE, PacketHeldItemChangeReceiving.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_SET_EXPERIENCE, PacketSetExperience.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_SET_EXPERIENCE, PacketSetExperience.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, PacketChangeGameState.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_CHANGE_GAME_STATE, PacketChangeGameState.class);
|
||||||
|
packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_MOB, PacketSpawnMob.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -81,8 +81,9 @@ public class Protocol_1_7_10 implements Protocol {
|
|||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_USE_BED, 0x0A);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_USE_BED, 0x0A);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, 0x0B);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, 0x0B);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_PLAYER, 0x0C);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_PLAYER, 0x0C);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_COLLECT_ITEM, 0x0E);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_COLLECT_ITEM, 0x0D);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_ENTITY, 0x0F);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_OBJECT, 0x0E);
|
||||||
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_MOB, 0x0F);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_PAINTING, 0x10);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_PAINTING, 0x10);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_EXPERIENCE_ORB, 0x11);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_SPAWN_EXPERIENCE_ORB, 0x11);
|
||||||
clientboundPacketMapping.put(Packets.Clientbound.PLAY_ENTITY_VELOCITY, 0x12);
|
clientboundPacketMapping.put(Packets.Clientbound.PLAY_ENTITY_VELOCITY, 0x12);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user