use of com.bergerkiller.generated.net.minecraft.server.EntityHandle in project BKCommonLib by bergerhealer.
the class ExtendedEntity method setPassengersSilent.
/**
* Sets the passengers of this Vehicle without raising any events
*
* @param newPassenger to set to
*/
public void setPassengersSilent(List<org.bukkit.entity.Entity> newPassengers) {
final EntityHandle handle = this.handle;
// Generate a difference view between the expected list of passengers, and the current
List<EntityHandle> removedPassengers = new ArrayList<EntityHandle>(handle.getPassengers().size());
List<org.bukkit.entity.Entity> keptPassengers = new ArrayList<org.bukkit.entity.Entity>(newPassengers.size());
for (EntityHandle oldPassenger : handle.getPassengers()) {
boolean found = false;
for (org.bukkit.entity.Entity p : newPassengers) {
if (oldPassenger.getRaw() == Conversion.toEntityHandle.convert(p)) {
found = true;
keptPassengers.add(p);
break;
}
}
if (!found) {
removedPassengers.add(oldPassenger);
}
}
// Remove vehicle information and passenger information for all removed passengers
for (EntityHandle passenger : removedPassengers) {
passenger.setVehicle(null);
handle.getPassengers().remove(passenger);
}
// Add new passengers as required
List<EntityHandle> currPassengers = handle.getPassengers();
for (org.bukkit.entity.Entity p : newPassengers) {
EntityHandle passengerHandle = EntityHandle.fromBukkit(p);
if (!currPassengers.contains(passengerHandle)) {
currPassengers.add(passengerHandle);
passengerHandle.setVehicle(handle);
// Send mount packet
CommonPacket packet = PacketType.OUT_MOUNT.newInstance(entity, keptPassengers);
PacketUtil.broadcastEntityPacket(entity, packet);
}
}
CommonPacket packet = PacketType.OUT_MOUNT.newInstanceHandles(entity, currPassengers);
PacketUtil.broadcastEntityPacket(entity, packet);
// Synchronize entity tracker of the vehicle to make sure it does not try to synchronize a second time
Object entry = WorldUtil.getTracker(entity.getWorld()).getEntry(entity);
if (entry != null) {
NMSEntityTrackerEntry.passengers.set(entry, newPassengers);
}
}
use of com.bergerkiller.generated.net.minecraft.server.EntityHandle in project BKCommonLib by bergerhealer.
the class CommonEventFactory method handleEntityMove.
/**
* Fires Entity Move events for all entities that moved on the server
*/
public void handleEntityMove() {
if (!CommonUtil.hasHandlers(EntityMoveEvent.getHandlerList())) {
return;
}
for (World world : WorldUtil.getWorlds()) {
entityMoveEntities.addAll(WorldHandle.fromBukkit(world).getEntityList());
}
for (EntityHandle entity : entityMoveEntities) {
if (entity.getLocX() != entity.getLastX() || entity.getLocY() != entity.getLastY() || entity.getLocZ() != entity.getLastZ() || entity.getYaw() != entity.getLastYaw() || entity.getPitch() != entity.getLastPitch()) {
entityMoveEvent.setEntity(entity);
CommonUtil.callEvent(entityMoveEvent);
}
}
entityMoveEntities.clear();
}
use of com.bergerkiller.generated.net.minecraft.server.EntityHandle in project BKCommonLib by bergerhealer.
the class CommonEntity method replaceEntity.
@SuppressWarnings("unchecked")
private void replaceEntity(final EntityHandle newInstance) {
final EntityHandle oldInstance = this.handle;
if (oldInstance.getRaw() == newInstance.getRaw()) {
throw new RuntimeException("Can not replace an entity with itself!");
}
// Reset entity state
oldInstance.setDead(true);
newInstance.setDead(false);
oldInstance.setValid(false);
newInstance.setValid(true);
// *** Bukkit Entity ***
CraftEntityHandle craftEntity = CraftEntityHandle.createHandle(this.entity);
craftEntity.setHandle(newInstance);
if (entity instanceof InventoryHolder) {
Inventory inv = ((InventoryHolder) entity).getInventory();
if (CraftInventoryHandle.T.isAssignableFrom(inv)) {
CraftInventoryHandle cInv = CraftInventoryHandle.createHandle(inv);
if (IInventoryHandle.T.isAssignableFrom(newInstance.getRaw())) {
IInventoryHandle iinvHandle = IInventoryHandle.createHandle(newInstance.getRaw());
cInv.setHandleField(iinvHandle);
}
}
}
// *** Give the old entity a new Bukkit Entity ***
oldInstance.setBukkitEntityField(CraftEntityHandle.createCraftEntity(Bukkit.getServer(), oldInstance));
this.handle = newInstance;
// *** Replace entity in passenger and vehicle fields ***
EntityHandle vehicle = newInstance.getVehicle();
if (vehicle != null) {
replaceInList(vehicle.getPassengers(), newInstance);
}
if (newInstance.getPassengers() != null) {
for (EntityHandle passenger : newInstance.getPassengers()) {
if (oldInstance.getRaw() == passenger.getVehicle().getRaw()) {
passenger.setVehicle(newInstance);
}
}
}
// *** DataWatcher field of the old Entity ***
Object dataWatcher = EntityHandle.T.datawatcherField.raw.get(newInstance.getRaw());
if (dataWatcher != null) {
DataWatcherHandle.T.owner.set(dataWatcher, newInstance);
}
// *** Perform further replacement all over the place in the server ***
replaceEntityInServer(oldInstance, newInstance);
// *** Repeat the replacement in the server the next tick to make sure nothing lingers ***
CommonUtil.nextTick(new Runnable() {
@Override
public void run() {
replaceEntityInServer(oldInstance, newInstance);
}
});
// *** Make sure a controller is set when hooked ***
if (this.isHooked()) {
DefaultEntityController controller = new DefaultEntityController();
controller.bind(this);
}
}
use of com.bergerkiller.generated.net.minecraft.server.EntityHandle in project BKCommonLib by bergerhealer.
the class CommonEntity method replaceInEntityTracker.
private static void replaceInEntityTracker(int entityId, EntityHandle newInstance) {
final EntityTracker trackerMap = WorldUtil.getTracker(newInstance.getWorld().getWorld());
Object entry = trackerMap.getEntry(entityId);
if (entry != null) {
EntityHandle tracker = EntityHandle.createHandle(NMSEntityTrackerEntry.tracker.getInternal(entry));
if (tracker != null && tracker.getId() == newInstance.getId()) {
NMSEntityTrackerEntry.tracker.setInternal(entry, newInstance.getRaw());
}
replaceInList((List<?>) NMSEntityTrackerEntry.passengers.getInternal(entry), newInstance);
}
}
use of com.bergerkiller.generated.net.minecraft.server.EntityHandle in project BKCommonLib by bergerhealer.
the class EntityMoveHandler method world_getCubes.
private List<AxisAlignedBBHandle> world_getCubes(EntityHandle entity, AxisAlignedBBHandle axisalignedbb) {
// BKCommonLib edit: use cached list
collisions_buffer.clear();
// BKCommonLib start: replace world_getBlockCollisions call; use cached list instead
//world.a(entity, axisalignedbb, false, arraylist);
world_getBlockCollisions(entity, axisalignedbb, false);
if (entity != null) {
List<EntityHandle> list = entity.getWorld().getEntities(entity, axisalignedbb.growUniform(0.25D));
for (int i = 0; i < list.size(); i++) {
EntityHandle entity1 = list.get(i);
if (!entity.isInSameVehicle(entity1)) {
// BKCommonLib start: block collision event handler
AxisAlignedBBHandle axisalignedbb1 = entity1.getOtherBoundingBox();
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
collisions_buffer.add(axisalignedbb1);
}
axisalignedbb1 = entity.getEntityBoundingBox(entity1);
if (axisalignedbb1 != null && axisalignedbb1.bbTransformA(axisalignedbb) && controller.onEntityCollision(entity1.getBukkitEntity())) {
collisions_buffer.add(axisalignedbb1);
}
/*
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
axisalignedbb1 = entity.j(entity1);
if ((axisalignedbb1 != null) && (axisalignedbb1.c(axisalignedbb))) {
list.add(axisalignedbb1);
}
*/
// BKCommonLib end
}
}
}
return collisions_buffer;
}
Aggregations