13
0

Merge pull request 'Add Bow Damge and Fire' (#22) from sneaking_like_a_god into master

Reviewed-on: #22
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2021-04-23 19:52:15 +02:00
Commit da35cb6f10
3 geänderte Dateien mit 110 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -305,6 +305,27 @@ class PacketProcessor {
packetCounter.clear();
}
private void bow() throws IOException {
int entityId = source.rInt();
boolean drawn = source.rBoolean();
int hand = source.rInt();
execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, hand));
}
private void damage() throws IOException {
int entityId = source.rInt();
execSync(() -> REntity.getEntity(entityId).damage());
}
private void fireTick() throws IOException {
int entityId = source.rInt();
boolean perma = source.rBoolean();
execSync(() -> REntity.getEntity(entityId).setOnFire(perma));
}
private void process(){
try{
@ -343,6 +364,15 @@ class PacketProcessor {
case 0x09:
fireballSpawn();
break;
case 0x0A:
bow();
break;
case 0x0B:
damage();
break;
case 0x0C:
fireTick();
break;
case 0x30:
block();
break;
@ -388,11 +418,12 @@ class PacketProcessor {
break;
case (byte) 0xFF:
//Tick
execSync(() -> REntity.tickFire());
if(!source.async())
tickFinished = true;
break;
default:
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing");
Bukkit.getLogger().log(Level.SEVERE, "Unknown packet recieved, closing: " + packetType);
source.close();
}
}

Datei anzeigen

@ -31,12 +31,33 @@ import java.util.Map;
public abstract class REntity {
public static void tickFire() {
getEntities().forEach((integer, entity) -> {
if(entity.fireTick > 0) {
entity.fireTick--;
if(entity.fireTick == 0) {
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 0);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);
}
}
});
}
protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
private static final Map<Integer, REntity> entities = new HashMap<>();
private static Map<Integer, REntity> getEntities() {
return entities;
}
private final int internalId;
protected final Entity entity;
private int fireTick;
protected REntity(int internalId, Entity entity){
this.internalId = internalId;
@ -55,6 +76,22 @@ public abstract class REntity {
for(REntity entity : entities.values()){
entity.sendToPlayer(player);
entity.sendLocation(player);
if(entity.fireTick != 0) {
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 1);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);
}
if(entity.entity.isSneaking()) {
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING);
dataWatcher.markDirty(dataWatcherObject);
entity.sendDataWatcher(dataWatcher);
}
}
}
}
@ -104,13 +141,45 @@ public abstract class REntity {
}
public void sneak(boolean sneaking) {
entity.setSneaking(sneaking);
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<EntityPose> dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s);
dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING);
dataWatcher.markDirty(dataWatcherObject);
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
sendDataWatcher(dataWatcher);
}
public void setOnFire(boolean perma) {
if(!perma) {
fireTick = 21;
} else {
fireTick = -1;
}
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) 1);
dataWatcher.markDirty(dataWatcherObject);
sendDataWatcher(dataWatcher);
}
public void setBowDrawn(boolean drawn, int hand) {
DataWatcher dataWatcher = new DataWatcher(null);
DataWatcherObject<Byte> dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a);
dataWatcher.register(dataWatcherObject, (byte) ((drawn?1:0) + (hand * 2)));
dataWatcher.markDirty(dataWatcherObject);
sendDataWatcher(dataWatcher);
}
public void damage() {
PacketPlayOutEntityStatus packet = new PacketPlayOutEntityStatus(entity, (byte) 2);
for(Player player : Bukkit.getOnlinePlayers()){
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
@ -145,4 +214,12 @@ public abstract class REntity {
protected void spawnEntity(PlayerConnection connection){
connection.sendPacket(new PacketPlayOutSpawnEntity(entity));
}
private void sendDataWatcher(DataWatcher dataWatcher) {
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false);
for(Player player : Bukkit.getOnlinePlayers()){
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}

Datei anzeigen

@ -54,7 +54,6 @@ public class RPlayer extends REntity {
public RPlayer(UUID uuid, String name, int internalId){
super(internalId, createPlayer(uuid, name));
//TODO Damage
team.addEntry(entity.getName());
}