Search in sources :

Example 6 with SpawnerStackSettings

use of dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings in project RoseStacker by Rosewood-Development.

the class StackedSpawnerGui method buildGui.

/**
 * Builds the GUI from scratch
 */
private void buildGui() {
    this.guiContainer = GuiFactory.createContainer().setTickRate(Setting.SPAWNER_GUI_TICK_UPDATE_RATE.getInt());
    SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
    GuiScreen mainScreen = GuiFactory.createScreen(this.guiContainer, GuiSize.ROWS_THREE).setTitle(this.localeManager.getLocaleMessage("gui-stacked-spawner-title", StringPlaceholders.single("name", stackSettings.getDisplayName()))).addButtonAt(11, GuiFactory.createButton()).addButtonAt(13, GuiFactory.createButton()).addButtonAt(15, GuiFactory.createButton());
    List<Integer> fillerSlots = IntStream.range(0, GuiSize.ROWS_THREE.getNumSlots()).boxed().collect(Collectors.toList());
    fillerSlots.removeAll(Arrays.asList(4, 7, 8, 9, 11, 13, 15, 17, 18, 19));
    Material filler = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_BORDER_MATERIAL.getString());
    Material corner = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_BORDER_CORNER_MATERIAL.getString());
    Material accent = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_BORDER_ACCENT_MATERIAL.getString());
    Material info = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_SPAWNER_STATS_MATERIAL.getString());
    Material spawner = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_CENTRAL_MATERIAL.getString());
    Material conditionsValid = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_VALID_SPAWN_CONDITIONS_MATERIAL.getString());
    Material conditionsInvalid = GuiHelper.parseMaterial(Setting.SPAWNER_GUI_INVALID_SPAWN_CONDITIONS_MATERIAL.getString());
    ItemStack fillerItem = new ItemStack(filler);
    ItemMeta fillerItemMeta = fillerItem.getItemMeta();
    if (fillerItemMeta != null) {
        fillerItemMeta.setDisplayName(" ");
        fillerItemMeta.addItemFlags(ItemFlag.values());
        fillerItem.setItemMeta(fillerItemMeta);
    }
    for (int slot : fillerSlots) mainScreen.addItemStackAt(slot, fillerItem);
    ItemStack cornerItem = fillerItem.clone();
    cornerItem.setType(corner);
    for (int slot : Arrays.asList(8, 18)) mainScreen.addItemStackAt(slot, cornerItem);
    ItemStack accentItem = fillerItem.clone();
    accentItem.setType(accent);
    for (int slot : Arrays.asList(7, 9, 17, 19)) mainScreen.addItemStackAt(slot, accentItem);
    ItemStack skull = RoseStacker.getInstance().getManager(StackSettingManager.class).getEntityStackSettings(stackSettings.getEntityType()).getEntityTypeData().getSkullItem();
    ItemMeta skullMeta = skull.getItemMeta();
    if (skullMeta != null) {
        String displayString;
        if (this.stackedSpawner.getStackSize() == 1 && !Setting.SPAWNER_DISPLAY_TAGS_SINGLE_AMOUNT.getBoolean()) {
            displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display-single", StringPlaceholders.builder("amount", this.stackedSpawner.getStackSize()).addPlaceholder("name", this.stackedSpawner.getStackSettings().getDisplayName()).build());
        } else {
            displayString = RoseStacker.getInstance().getManager(LocaleManager.class).getLocaleMessage("spawner-stack-display", StringPlaceholders.builder("amount", this.stackedSpawner.getStackSize()).addPlaceholder("name", this.stackedSpawner.getStackSettings().getDisplayName()).build());
        }
        skullMeta.setDisplayName(displayString);
        skull.setItemMeta(skullMeta);
    }
    mainScreen.addButtonAt(4, GuiFactory.createButton(skull));
    mainScreen.addButtonAt(11, GuiFactory.createButton().setIcon(info).setName(this.getString("stats")).setLoreSupplier(() -> {
        List<GuiString> lore = new ArrayList<>();
        StackedSpawnerTile spawnerTile = this.stackedSpawner.getSpawnerTile();
        lore.add(this.getString("min-spawn-delay", StringPlaceholders.single("delay", spawnerTile.getMinSpawnDelay())));
        lore.add(this.getString("max-spawn-delay", StringPlaceholders.single("delay", spawnerTile.getMaxSpawnDelay())));
        lore.add(this.getString("disabled-mob-ai", StringPlaceholders.single("disabled", String.valueOf(stackSettings.isMobAIDisabled()))));
        int range = stackSettings.getEntitySearchRange() == -1 ? spawnerTile.getSpawnRange() : stackSettings.getEntitySearchRange();
        lore.add(this.getString("entity-search-range", StringPlaceholders.single("range", range)));
        lore.add(this.getString("player-activation-range", StringPlaceholders.single("range", spawnerTile.getRequiredPlayerRange())));
        lore.add(this.getString("spawn-range", StringPlaceholders.single("range", spawnerTile.getSpawnRange())));
        if (stackSettings.getSpawnCountStackSizeMultiplier() != -1) {
            if (Setting.SPAWNER_SPAWN_COUNT_STACK_SIZE_RANDOMIZED.getBoolean()) {
                lore.add(this.getString("min-spawn-amount", StringPlaceholders.single("amount", this.stackedSpawner.getStackSize())));
                lore.add(this.getString("max-spawn-amount", StringPlaceholders.single("amount", spawnerTile.getSpawnCount())));
            } else {
                lore.add(this.getString("spawn-amount", StringPlaceholders.single("amount", spawnerTile.getSpawnCount())));
            }
        } else {
            lore.add(this.getString("min-spawn-amount", StringPlaceholders.single("amount", 1)));
            lore.add(this.getString("max-spawn-amount", StringPlaceholders.single("amount", spawnerTile.getSpawnCount())));
        }
        lore.add(GuiFactory.createString());
        lore.add(this.getString("spawn-conditions"));
        List<ConditionTag> spawnConditions = stackSettings.getSpawnRequirements();
        for (ConditionTag conditionTag : spawnConditions) for (String line : conditionTag.getInfoMessage(this.localeManager)) lore.add(GuiFactory.createString(line));
        return lore;
    }));
    mainScreen.addButtonAt(13, GuiFactory.createButton().setIcon(spawner).setNameSupplier(() -> this.getString("time-until-next-spawn", StringPlaceholders.single("time", this.stackedSpawner.getSpawnerTile().getDelay() + 1))).setLoreSupplier(() -> Collections.singletonList(this.getString("total-spawns", StringPlaceholders.single("amount", StackerUtils.formatNumber(PersistentDataUtils.getTotalSpawnCount(this.stackedSpawner.getSpawnerTile())))))));
    mainScreen.addButtonAt(15, GuiFactory.createButton().setIconSupplier(() -> GuiFactory.createIcon(this.stackedSpawner.getLastInvalidConditions().isEmpty() ? conditionsValid : conditionsInvalid)).setNameSupplier(() -> {
        if (this.stackedSpawner.getLastInvalidConditions().isEmpty()) {
            return this.getString("valid-spawn-conditions");
        } else {
            return this.getString("invalid-spawn-conditions");
        }
    }).setLoreSupplier(() -> {
        List<Class<? extends ConditionTag>> invalidConditions = this.stackedSpawner.getLastInvalidConditions();
        if (invalidConditions.isEmpty())
            return Collections.singletonList(this.getString("entities-can-spawn"));
        List<GuiString> lore = new ArrayList<>();
        lore.add(this.getString("conditions-preventing-spawns"));
        for (Class<? extends ConditionTag> conditionTagClass : invalidConditions) lore.add(GuiFactory.createString(ConditionTags.getErrorMessage(conditionTagClass, this.localeManager)));
        return lore;
    }));
    this.guiContainer.addScreen(mainScreen);
    this.guiFramework.getGuiManager().registerGui(this.guiContainer);
}
Also used : SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) ConditionTag(dev.rosewood.rosestacker.spawner.conditions.ConditionTag) Material(org.bukkit.Material) StackSettingManager(dev.rosewood.rosestacker.manager.StackSettingManager) GuiString(dev.rosewood.guiframework.gui.GuiString) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) GuiScreen(dev.rosewood.guiframework.gui.screen.GuiScreen) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 7 with SpawnerStackSettings

use of dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings in project RoseStacker by Rosewood-Development.

the class MaxNearbyEntityConditionTag method check.

@Override
public boolean check(StackedSpawner stackedSpawner, Block spawnBlock) {
    if (this.stackManager == null || this.entityCacheManager == null) {
        this.stackManager = RoseStacker.getInstance().getManager(StackManager.class);
        this.entityCacheManager = RoseStacker.getInstance().getManager(EntityCacheManager.class);
    }
    SpawnerStackSettings stackSettings = stackedSpawner.getStackSettings();
    int detectionRange = stackSettings.getEntitySearchRange() == -1 ? stackedSpawner.getSpawnerTile().getSpawnRange() : stackSettings.getEntitySearchRange();
    Block block = stackedSpawner.getBlock();
    EntityType entityType = stackedSpawner.getSpawnerTile().getSpawnedType();
    Collection<Entity> nearbyEntities = this.entityCacheManager.getNearbyEntities(block.getLocation().clone().add(0.5, 0.5, 0.5), detectionRange, entity -> entity.getType() == entityType);
    if (Setting.SPAWNER_MAX_NEARBY_ENTITIES_INCLUDE_STACKS.getBoolean()) {
        return nearbyEntities.stream().mapToInt(x -> {
            StackedEntity stackedEntity = this.stackManager.getStackedEntity((LivingEntity) x);
            return stackedEntity == null ? 1 : stackedEntity.getStackSize();
        }).sum() < this.maxNearbyEntities;
    } else {
        return nearbyEntities.size() < this.maxNearbyEntities;
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) Entity(org.bukkit.entity.Entity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) LivingEntity(org.bukkit.entity.LivingEntity) StackedEntity(dev.rosewood.rosestacker.stack.StackedEntity) StackManager(dev.rosewood.rosestacker.manager.StackManager) EntityCacheManager(dev.rosewood.rosestacker.manager.EntityCacheManager) Block(org.bukkit.block.Block)

Example 8 with SpawnerStackSettings

use of dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method serverTick.

@Override
public void serverTick(ServerLevel level, BlockPos blockPos) {
    // Only tick the spawner if a player is nearby
    this.playersTimeSinceLastCheck = (this.playersTimeSinceLastCheck + 1) % Setting.SPAWNER_PLAYER_CHECK_FREQUENCY.getInt();
    if (this.playersTimeSinceLastCheck == 0)
        this.playersNearby = this.isNearPlayer(level, blockPos);
    if (!this.playersNearby)
        return;
    // if (!this.nextSpawnData.getEntityToSpawn().getString("id").equals("minecraft:item")) {
    // CompoundTag tag = new CompoundTag();
    // tag.putString("id", "minecraft:item");
    // CompoundTag item = new CompoundTag();
    // item.putString("id", "minecraft:diamond");
    // item.putByte("Count", (byte) 1);
    // tag.put("Item", item);
    // this.nextSpawnData = new SpawnData(tag, Optional.empty());
    // this.updateTile();
    // }
    SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
    // Handle redstone deactivation if enabled
    if (Setting.SPAWNER_DEACTIVATE_WHEN_POWERED.getBoolean()) {
        if (this.redstoneTimeSinceLastCheck == 0) {
            boolean hasSignal = level.hasNeighborSignal(this.blockPos);
            if (this.redstoneDeactivated && !hasSignal) {
                this.redstoneDeactivated = false;
                this.requiredPlayerRange = stackSettings.getPlayerActivationRange();
                this.updateTile();
            } else if (!this.redstoneDeactivated && hasSignal) {
                this.redstoneDeactivated = true;
                this.requiredPlayerRange = 0;
                this.updateTile();
            }
            if (this.redstoneDeactivated)
                return;
        }
        this.redstoneTimeSinceLastCheck = (this.redstoneTimeSinceLastCheck + 1) % Setting.SPAWNER_POWERED_CHECK_FREQUENCY.getInt();
    }
    // Count down spawn timer unless we are ready to spawn
    if (this.spawnDelay > 0) {
        this.spawnDelay--;
        return;
    }
    // Reset spawn delay
    this.spawnDelay = level.getRandom().nextInt(this.maxSpawnDelay - this.minSpawnDelay + 1) + this.minSpawnDelay;
    this.updateTile();
    // Execute spawning method
    if (this.nextSpawnData != null) {
        ResourceLocation resourceLocation = ResourceLocation.tryParse(this.nextSpawnData.getEntityToSpawn().getString("id"));
        if (resourceLocation != null) {
            NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
            EntityType entityType = this.fromKey(namespacedKey);
            if (entityType != null)
                new MobSpawningMethod(entityType).spawn(this.stackedSpawner);
        }
    }
    // new ItemSpawningMethod(Material.DIAMOND).spawn(this.stackedSpawner);
    // Randomize spawn potentials
    this.spawnPotentials.getRandom(level.getRandom()).ifPresent(x -> this.nextSpawnData = x.getData());
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) MobSpawningMethod(dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod) NamespacedKey(org.bukkit.NamespacedKey) CraftNamespacedKey(org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 9 with SpawnerStackSettings

use of dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method serverTick.

@Override
public void serverTick(ServerLevel level, BlockPos blockPos) {
    // Only tick the spawner if a player is nearby
    this.playersTimeSinceLastCheck = (this.playersTimeSinceLastCheck + 1) % Setting.SPAWNER_PLAYER_CHECK_FREQUENCY.getInt();
    if (this.playersTimeSinceLastCheck == 0)
        this.playersNearby = this.isNearPlayer(level, blockPos);
    if (!this.playersNearby)
        return;
    SpawnerStackSettings stackSettings = this.stackedSpawner.getStackSettings();
    // Handle redstone deactivation if enabled
    if (Setting.SPAWNER_DEACTIVATE_WHEN_POWERED.getBoolean()) {
        if (this.redstoneTimeSinceLastCheck == 0) {
            boolean hasSignal = level.hasNeighborSignal(this.blockPos);
            if (this.redstoneDeactivated && !hasSignal) {
                this.redstoneDeactivated = false;
                this.requiredPlayerRange = stackSettings.getPlayerActivationRange();
                this.updateTile();
            } else if (!this.redstoneDeactivated && hasSignal) {
                this.redstoneDeactivated = true;
                this.requiredPlayerRange = 0;
                this.updateTile();
            }
            if (this.redstoneDeactivated)
                return;
        }
        this.redstoneTimeSinceLastCheck = (this.redstoneTimeSinceLastCheck + 1) % Setting.SPAWNER_POWERED_CHECK_FREQUENCY.getInt();
    }
    // Count down spawn timer unless we are ready to spawn
    if (this.spawnDelay > 0) {
        this.spawnDelay--;
        return;
    }
    // Reset spawn delay
    this.spawnDelay = level.getRandom().nextInt(this.maxSpawnDelay - this.minSpawnDelay + 1) + this.minSpawnDelay;
    this.updateTile();
    // Execute spawning method
    if (this.nextSpawnData != null) {
        ResourceLocation resourceLocation = ResourceLocation.tryParse(this.nextSpawnData.getTag().getString("id"));
        if (resourceLocation != null) {
            NamespacedKey namespacedKey = CraftNamespacedKey.fromMinecraft(resourceLocation);
            EntityType entityType = this.fromKey(namespacedKey);
            if (entityType != null)
                new MobSpawningMethod(entityType).spawn(this.stackedSpawner);
        }
    }
    // Randomize spawn potentials
    this.spawnPotentials.getRandom(level.getRandom()).ifPresent(x -> this.nextSpawnData = x);
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) MobSpawningMethod(dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod) NamespacedKey(org.bukkit.NamespacedKey) CraftNamespacedKey(org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 10 with SpawnerStackSettings

use of dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings in project RoseStacker by Rosewood-Development.

the class EntityListener method onSpawnerSpawn.

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSpawnerSpawn(SpawnerSpawnEvent event) {
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    StackManager stackManager = this.rosePlugin.getManager(StackManager.class);
    if (stackManager.isWorldDisabled(event.getEntity().getWorld()))
        return;
    LivingEntity entity = (LivingEntity) event.getEntity();
    PersistentDataUtils.tagSpawnedFromSpawner(entity);
    SpawnerStackSettings stackSettings = this.stackSettingManager.getSpawnerStackSettings(event.getSpawner());
    StackedSpawner stackedSpawner = this.stackManager.getStackedSpawner(event.getSpawner().getBlock());
    if (stackedSpawner == null)
        stackedSpawner = stackManager.createSpawnerStack(event.getSpawner().getBlock(), 1, false);
    boolean placedByPlayer = stackedSpawner != null && stackedSpawner.isPlacedByPlayer();
    if (stackSettings.isMobAIDisabled() && (!Setting.SPAWNER_DISABLE_MOB_AI_ONLY_PLAYER_PLACED.getBoolean() || placedByPlayer))
        PersistentDataUtils.removeEntityAi(entity);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) StackManager(dev.rosewood.rosestacker.manager.StackManager) EventHandler(org.bukkit.event.EventHandler)

Aggregations

SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)14 EntityType (org.bukkit.entity.EntityType)10 MobSpawningMethod (dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod)5 ArrayList (java.util.ArrayList)5 Material (org.bukkit.Material)5 NamespacedKey (org.bukkit.NamespacedKey)5 Block (org.bukkit.block.Block)5 StackManager (dev.rosewood.rosestacker.manager.StackManager)4 StackedSpawner (dev.rosewood.rosestacker.stack.StackedSpawner)4 List (java.util.List)4 LivingEntity (org.bukkit.entity.LivingEntity)4 StackSettingManager (dev.rosewood.rosestacker.manager.StackSettingManager)3 StackedSpawnerTile (dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile)3 ConditionTag (dev.rosewood.rosestacker.spawner.conditions.ConditionTag)3 BlockStackSettings (dev.rosewood.rosestacker.stack.settings.BlockStackSettings)3 EntityStackSettings (dev.rosewood.rosestacker.stack.settings.EntityStackSettings)3 StackerUtils (dev.rosewood.rosestacker.utils.StackerUtils)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3