use of net.minecraft.server.v1_14_R1.MinecraftKey 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));
}
use of net.minecraft.server.v1_14_R1.MinecraftKey in project RoseStacker by Rosewood-Development.
the class StackedSpawnerTileImpl method getSpawnedType.
@Override
public EntityType getSpawnedType() {
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)
return entityType;
}
return EntityType.PIG;
}
use of net.minecraft.server.v1_14_R1.MinecraftKey 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));
}
use of net.minecraft.server.v1_14_R1.MinecraftKey in project SilkSpawners by timbru31.
the class NMSHandler method getMobNameOfSpawner.
@Override
public String getMobNameOfSpawner(final BlockState blockState) {
// Get our spawner;
final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
// Get the mob ID ourselves if we can
try {
final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
// Get the name from the field of our spawner
final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
return minecraftKey != null ? minecraftKey.b() : "";
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
e.printStackTrace();
}
return "";
}
use of net.minecraft.server.v1_14_R1.MinecraftKey in project SilkSpawners by timbru31.
the class NMSHandler method setMobNameOfSpawner.
@Override
public boolean setMobNameOfSpawner(final BlockState blockState, final String mobID) {
// Prevent ResourceKeyInvalidException: Non [a-z0-9/._-] character in path of location
final String safeMobID = caseFormatOf(mobID.replace(" ", "_")).to(CaseFormat.LOWER_UNDERSCORE, mobID.replace(" ", "_")).toLowerCase(Locale.ENGLISH);
final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
try {
final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
tile.getSpawner().setMobName(new MinecraftKey(safeMobID));
return true;
} catch (IllegalArgumentException | IllegalAccessException e) {
Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
e.printStackTrace();
}
return false;
}
Aggregations