Search in sources :

Example 1 with MobSpawningMethod

use of dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method c.

@Override
public void c() {
    World level = this.a();
    if (level == null)
        return;
    // 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, this.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.isBlockIndirectlyPowered(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.spawnData != null) {
        MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().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
    if (!this.mobs.isEmpty())
        this.setSpawnData(WeightedRandom.a(this.a().random, this.mobs));
}
Also used : EntityType(org.bukkit.entity.EntityType) SpawnerStackSettings(dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings) MobSpawningMethod(dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R2.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) World(net.minecraft.server.v1_16_R2.World) MinecraftKey(net.minecraft.server.v1_16_R2.MinecraftKey)

Example 2 with MobSpawningMethod

use of dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod in project RoseStacker by Rosewood-Development.

the class StackedSpawnerTileImpl method c.

@Override
public void c() {
    World level = this.a();
    if (level == null)
        return;
    // 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, this.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.isBlockIndirectlyPowered(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.spawnData != null) {
        MinecraftKey resourceLocation = MinecraftKey.a(this.spawnData.getEntity().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
    if (!this.mobs.isEmpty())
        this.setSpawnData(WeightedRandom.a(this.a().random, this.mobs));
}
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_16_R3.util.CraftNamespacedKey) World(net.minecraft.server.v1_16_R3.World) MinecraftKey(net.minecraft.server.v1_16_R3.MinecraftKey)

Example 3 with MobSpawningMethod

use of dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod 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.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);
        }
    }
    // 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_R1.util.CraftNamespacedKey) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 4 with MobSpawningMethod

use of dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod 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 5 with MobSpawningMethod

use of dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod 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)

Aggregations

MobSpawningMethod (dev.rosewood.rosestacker.spawner.spawning.MobSpawningMethod)5 SpawnerStackSettings (dev.rosewood.rosestacker.stack.settings.SpawnerStackSettings)5 NamespacedKey (org.bukkit.NamespacedKey)5 EntityType (org.bukkit.entity.EntityType)5 ResourceLocation (net.minecraft.resources.ResourceLocation)3 MinecraftKey (net.minecraft.server.v1_16_R2.MinecraftKey)1 World (net.minecraft.server.v1_16_R2.World)1 MinecraftKey (net.minecraft.server.v1_16_R3.MinecraftKey)1 World (net.minecraft.server.v1_16_R3.World)1 CraftNamespacedKey (org.bukkit.craftbukkit.v1_16_R2.util.CraftNamespacedKey)1 CraftNamespacedKey (org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey)1 CraftNamespacedKey (org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey)1 CraftNamespacedKey (org.bukkit.craftbukkit.v1_18_R1.util.CraftNamespacedKey)1 CraftNamespacedKey (org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey)1