SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'No Gravity' (#223) from NoGravityREntity into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #223
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2023-01-17 16:56:40 +01:00
Commit baab53a25d
3 geänderte Dateien mit 91 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -40,11 +40,14 @@ public class REntity {
private static final Object nameWatcher = BountifulWrapper.impl.getDataWatcherObject(2, Core.getVersion() > 12 ? Optional.class : String.class); // Optional<IChatBaseComponent>
private static final Object nameVisibleWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Boolean.class);
private static final Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5,Boolean.class);
private static int entityIdCounter = -1;
private static final Random random = new Random();
private final REntityServer server;
private final EntityType entityType;
@Getter
protected final int entityId;
@Getter
protected final UUID uuid;
@ -59,16 +62,24 @@ public class REntity {
private boolean invisible;
private FlatteningWrapper.EntityPose pose = FlatteningWrapper.EntityPose.NORMAL;
private boolean bowDrawn;
private boolean noGravity;
private boolean isGlowing;
private int fireTick;
private final int objectData;
@Getter
private String displayName;
protected final Map<Object, ItemStack> itemSlots;
public REntity(REntityServer server, EntityType entityType, Location location) {
this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location);
this(server,entityType,location,0);
}
protected REntity(REntityServer server, EntityType entityType, UUID uuid, Location location) {
protected REntity(REntityServer server, EntityType entityType, Location location,int objectData) {
this(server, entityType, new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L), location,objectData);
}
protected REntity(REntityServer server, EntityType entityType, UUID uuid, Location location,int objectData) {
this.server = server;
this.entityType = entityType;
this.entityId = entityIdCounter--;
@ -82,6 +93,11 @@ public class REntity {
this.itemSlots = entityType == EntityType.PLAYER ? new HashMap<>() : null;
this.noGravity = false;
this.isGlowing = false;
this.objectData = objectData;
server.addEntity(this);
}
@ -185,6 +201,19 @@ public class REntity {
server.removeEntity(this);
}
public void setNoGravity(boolean noGravity) {
this.noGravity = noGravity;
if(Core.getVersion() > 8)
server.updateEntity(this,getDataWatcherPacket(noGravityDataWatcher,noGravity));
}
public void setGlowing(boolean glowing) {
this.isGlowing = glowing;
if(Core.getVersion() > 8) {
server.updateEntity(this,getDataWatcherPacket(entityStatusWatcher,getEntityStatus()));
}
}
private static int spawnPacketOffset() {
switch (Core.getVersion()) {
case 8:
@ -230,6 +259,9 @@ public class REntity {
if(displayName != null) {
packetSink.accept(getDataWatcherPacket(nameWatcher, FlatteningWrapper.impl.formatDisplayName(displayName), nameVisibleWatcher, true));
}
if(Core.getVersion() > 8 && noGravity)
packetSink.accept(getDataWatcherPacket(noGravityDataWatcher,this.noGravity));
}
void tick() {
@ -274,6 +306,8 @@ public class REntity {
status |= 0x10;
if(invisible)
status |= 0x20;
if(Core.getVersion() > 8 && isGlowing)
status |= 0x40;
return status;
}
@ -344,11 +378,32 @@ public class REntity {
protected static Function<REntity, Object> spawnPacketGenerator(Class<?> spawnPacket, int posOffset) {
Reflection.FieldAccessor<Integer> entityId = Reflection.getField(spawnPacket, int.class, 0);
int index;
switch (Core.getVersion()) {
case 8:
index = 10;
break;
case 9:
case 14:
case 12:
case 10:
case 15:
case 18:
index = 6;
break;
default:
index = 7;
break;
}
Reflection.FieldAccessor<Integer> additionalData = Reflection.getField(spawnPacket, int.class, index);
BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset);
return entity -> {
Object packet = Reflection.newInstance(spawnPacket);
entityId.set(packet, entity.entityId);
additionalData.set(packet,entity.objectData);
position.set(packet, entity.x, entity.y, entity.z);
return packet;
};

Datei anzeigen

@ -0,0 +1,33 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.entity;
import de.steamwar.core.Core;
import de.steamwar.techhider.BlockIds;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
public class RFallingBlockEntity extends REntity{
public RFallingBlockEntity(REntityServer server, Location location, Material material) {
super(server, EntityType.FALLING_BLOCK, location, BlockIds.impl.materialToId(material) >> (Core.getVersion() <= 12 ? 4 : 0));
}
}

Datei anzeigen

@ -76,7 +76,7 @@ public class RPlayer extends REntity {
private final String name;
public RPlayer(REntityServer server, UUID uuid, String name, Location location) {
super(server, EntityType.PLAYER, uuid, location);
super(server, EntityType.PLAYER, uuid, location,0);
this.name = name;
//team.addEntry(name);
}