use of dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry in project RoseStacker by Rosewood-Development.
the class StackerUtils method deconstructStackedEntities.
public static List<LivingEntity> deconstructStackedEntities(StackedEntity stackedEntity) {
List<StackedEntityDataEntry<?>> stackedEntityDataEntry = stackedEntity.getStackedEntityNBT().getAll();
List<LivingEntity> livingEntities = new ArrayList<>(stackedEntityDataEntry.size());
Location location = stackedEntity.getLocation();
NMSHandler nmsHandler = NMSAdapter.getHandler();
for (StackedEntityDataEntry<?> nbt : stackedEntityDataEntry) livingEntities.add(nmsHandler.createEntityFromNBT(nbt, location, false, stackedEntity.getEntity().getType()));
return livingEntities;
}
use of dev.rosewood.rosestacker.nms.storage.StackedEntityDataEntry in project RoseStacker by Rosewood-Development.
the class StackingThread method stackEntities.
private void stackEntities() {
boolean itemStackingEnabled = this.stackManager.isItemStackingEnabled();
boolean entityStackingEnabled = this.stackManager.isEntityStackingEnabled();
if (!entityStackingEnabled)
return;
// Auto unstack entities
if (!this.stackManager.isEntityUnstackingTemporarilyDisabled()) {
boolean minSplitIfLower = Setting.ENTITY_MIN_SPLIT_IF_LOWER.getBoolean();
for (StackedEntity stackedEntity : this.stackedEntities.values()) {
if (!stackedEntity.shouldStayStacked() && stackedEntity.getEntity().isValid()) {
Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
if (stackedEntity.getStackSize() > 1)
this.splitEntityStack(stackedEntity);
});
} else if (minSplitIfLower && stackedEntity.getStackSize() < stackedEntity.getStackSettings().getMinStackSize()) {
NMSHandler nmsHandler = NMSAdapter.getHandler();
StackedEntityDataStorage nbt = stackedEntity.getStackedEntityNBT();
stackedEntity.setStackedEntityNBT(nmsHandler.createEntityDataStorage(stackedEntity.getEntity()));
Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
for (StackedEntityDataEntry<?> stackedEntityDataEntry : nbt.getAll()) nmsHandler.createEntityFromNBT(stackedEntityDataEntry, stackedEntity.getLocation(), true, stackedEntity.getEntity().getType());
});
}
}
}
// Auto stack entities
if (this.entityStackSwitch) {
for (StackedEntity stackedEntity : this.stackedEntities.values()) {
LivingEntity livingEntity = stackedEntity.getEntity();
if (this.isRemoved(livingEntity)) {
this.removeEntityStack(stackedEntity);
continue;
}
this.tryStackEntity(stackedEntity);
}
}
// Run entity stacking half as often as the unstacking
this.entityStackSwitch = !this.entityStackSwitch;
// Cleans up entities/items that aren't stacked
this.cleanupTimer++;
if (this.cleanupTimer >= CLEANUP_TIMER_TARGET) {
Bukkit.getScheduler().runTask(this.rosePlugin, () -> {
for (Entity entity : this.targetWorld.getEntities()) {
if (this.isRemoved(entity))
continue;
if (entity instanceof LivingEntity && entity.getType() != EntityType.ARMOR_STAND && entity.getType() != EntityType.PLAYER) {
LivingEntity livingEntity = (LivingEntity) entity;
if (!this.isEntityStacked(livingEntity))
this.createEntityStack(livingEntity, false);
} else if (itemStackingEnabled && entity.getType() == EntityType.DROPPED_ITEM) {
Item item = (Item) entity;
if (!this.isItemStacked(item))
this.createItemStack(item, false);
}
}
});
this.cleanupTimer = 0;
}
}
Aggregations