ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/booklet/chapter/BookletChapter.java

97 lines
2.9 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.common.booklet.chapter;
2015-08-28 21:17:09 +02:00
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.api.misc.IDisableableItem;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.util.StringUtil;
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
2017-02-18 00:54:58 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-08-28 21:17:09 +02:00
2019-05-02 09:10:29 +02:00
public class BookletChapter implements IBookletChapter {
2015-08-28 21:17:09 +02:00
public final IBookletPage[] pages;
2016-01-05 14:57:50 +01:00
public final IBookletEntry entry;
public final ItemStack displayStack;
private final String identifier;
2016-11-22 22:54:35 +01:00
private final int priority;
2016-03-18 23:47:22 +01:00
public TextFormatting color;
2015-08-28 21:17:09 +02:00
2019-05-02 09:10:29 +02:00
public BookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, IBookletPage... pages) {
2016-11-22 22:54:35 +01:00
this(identifier, entry, displayStack, 0, pages);
}
2019-05-02 09:10:29 +02:00
public BookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, int priority, IBookletPage... pages) {
this.pages = pages;
this.identifier = identifier;
2015-08-28 21:17:09 +02:00
this.entry = entry;
this.displayStack = displayStack;
2019-05-02 09:10:29 +02:00
if (displayStack.getItem() instanceof IDisableableItem && ((IDisableableItem) displayStack.getItem()).isDisabled()) displayStack = ItemStack.EMPTY;
2016-11-22 22:54:35 +01:00
this.priority = priority;
this.color = TextFormatting.RESET;
this.entry.addChapter(this);
2019-05-02 09:10:29 +02:00
for (IBookletPage page : this.pages) {
2015-08-28 21:17:09 +02:00
page.setChapter(this);
}
}
2016-01-05 14:57:50 +01:00
@Override
2019-05-02 09:10:29 +02:00
public IBookletPage[] getAllPages() {
2016-01-05 14:57:50 +01:00
return this.pages;
}
@Override
2017-02-18 00:54:58 +01:00
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public String getLocalizedName() {
return StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".chapter." + this.getIdentifier() + ".name");
2016-01-05 14:57:50 +01:00
}
@Override
2017-02-18 00:54:58 +01:00
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public String getLocalizedNameWithFormatting() {
return this.color + this.getLocalizedName();
}
2016-01-05 14:57:50 +01:00
@Override
2019-05-02 09:10:29 +02:00
public IBookletEntry getEntry() {
2016-01-05 14:57:50 +01:00
return this.entry;
}
@Override
2019-05-02 09:10:29 +02:00
public ItemStack getDisplayItemStack() {
2016-01-05 14:57:50 +01:00
return this.displayStack;
2015-10-28 14:46:04 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public String getIdentifier() {
return this.identifier;
}
@Override
2019-05-02 09:10:29 +02:00
public int getPageIndex(IBookletPage page) {
for (int i = 0; i < this.pages.length; i++) {
if (this.pages[i] == page) { return i; }
}
return -1;
}
2016-11-22 22:54:35 +01:00
@Override
2019-05-02 09:10:29 +02:00
public int getSortingPriority() {
2016-11-22 22:54:35 +01:00
return this.priority;
}
2019-05-02 09:10:29 +02:00
public BookletChapter setImportant() {
2016-03-18 23:47:22 +01:00
this.color = TextFormatting.DARK_GREEN;
return this;
}
2019-05-02 09:10:29 +02:00
public BookletChapter setSpecial() {
2016-03-18 23:47:22 +01:00
this.color = TextFormatting.DARK_PURPLE;
return this;
2015-08-28 21:17:09 +02:00
}
}