use of dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method injectStackedSpawnerTile.
@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
Block block = stackedSpawner.getBlock();
ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
BlockEntity blockEntity = level.getBlockEntity(new BlockPos(block.getX(), block.getY(), block.getZ()));
if (blockEntity instanceof SpawnerBlockEntity) {
SpawnerBlockEntity spawnerBlockEntity = (SpawnerBlockEntity) blockEntity;
if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
return stackedSpawnerTile;
} else {
StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
spawnerTile.updateStackedSpawner(stackedSpawner);
return spawnerTile;
}
}
return null;
}
use of dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method injectStackedSpawnerTile.
@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
Block block = stackedSpawner.getBlock();
WorldServer level = ((CraftWorld) block.getWorld()).getHandle();
TileEntity blockEntity = level.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
if (blockEntity instanceof TileEntityMobSpawner) {
TileEntityMobSpawner spawnerBlockEntity = (TileEntityMobSpawner) blockEntity;
if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
return stackedSpawnerTile;
} else {
StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
spawnerTile.updateStackedSpawner(stackedSpawner);
return spawnerTile;
}
}
return null;
}
use of dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile 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);
}
use of dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method injectStackedSpawnerTile.
@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
Block block = stackedSpawner.getBlock();
ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
BlockEntity blockEntity = level.getBlockEntity(new BlockPos(block.getX(), block.getY(), block.getZ()));
if (blockEntity instanceof SpawnerBlockEntity) {
SpawnerBlockEntity spawnerBlockEntity = (SpawnerBlockEntity) blockEntity;
if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
return stackedSpawnerTile;
} else {
StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
spawnerTile.updateStackedSpawner(stackedSpawner);
return spawnerTile;
}
}
return null;
}
use of dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method injectStackedSpawnerTile.
@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
Block block = stackedSpawner.getBlock();
ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
BlockEntity blockEntity = level.getBlockEntity(new BlockPos(block.getX(), block.getY(), block.getZ()));
if (blockEntity instanceof SpawnerBlockEntity) {
SpawnerBlockEntity spawnerBlockEntity = (SpawnerBlockEntity) blockEntity;
if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
return stackedSpawnerTile;
} else {
StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
spawnerTile.updateStackedSpawner(stackedSpawner);
return spawnerTile;
}
}
return null;
}
Aggregations