:zoomeyes: 😓
Just something I was playing around with
This commit is contained in:
parent
26af9d5c6d
commit
2ca458aaea
14 changed files with 0 additions and 432 deletions
|
@ -1,36 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Category {
|
||||
|
||||
private final Guide owner;
|
||||
private final String name;
|
||||
private final Map<String, Entry> entries;
|
||||
|
||||
public Category(Guide owner, String name, Consumer<Category> $) {
|
||||
this.owner = owner;
|
||||
this.name = name;
|
||||
entries = Maps.newLinkedHashMap();
|
||||
|
||||
$.accept(this);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(Minecraft minecraft, ScaledResolution resolution, FontRenderer font) {
|
||||
|
||||
}
|
||||
|
||||
public Entry addEntry(Entry entry) {
|
||||
entries.put(entry.getId(), entry);
|
||||
return entry;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.wayoftime.bloodmagic.guide.page.PageComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Entry {
|
||||
|
||||
private final String id;
|
||||
private final List<PageComponent> components;
|
||||
|
||||
public Entry(String id, Consumer<Entry> $) {
|
||||
this.id = id;
|
||||
this.components = Lists.newArrayList();
|
||||
|
||||
$.accept(this);
|
||||
}
|
||||
|
||||
public PageComponent appendComponent(PageComponent component) {
|
||||
components.add(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Guide {
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final List<Category> categories;
|
||||
|
||||
public Guide(ResourceLocation id, Consumer<Guide> $) {
|
||||
this.id = id;
|
||||
this.categories = Lists.newArrayList();
|
||||
|
||||
$.accept(this);
|
||||
}
|
||||
|
||||
public Category addCategory(String name, Consumer<Category> category) {
|
||||
Category cat = new Category(this, name, category);
|
||||
categories.add(cat);
|
||||
return cat;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import com.wayoftime.bloodmagic.guide.Guide;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PageComponent {
|
||||
|
||||
private final int height;
|
||||
private IComponentSplitter splitter;
|
||||
private IViewingRequirement viewingRequirement;
|
||||
|
||||
public PageComponent(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void draw(Minecraft minecraft, ScaledResolution resolution, FontRenderer font) {
|
||||
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IComponentSplitter getSplitter() {
|
||||
return splitter;
|
||||
}
|
||||
|
||||
public PageComponent withComponentSplitter(IComponentSplitter splitter) {
|
||||
this.splitter = splitter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IViewingRequirement getViewingRequirement() {
|
||||
return viewingRequirement;
|
||||
}
|
||||
|
||||
public PageComponent withViewingRequirement(IViewingRequirement viewingRequirement) {
|
||||
this.viewingRequirement = viewingRequirement;
|
||||
return this;
|
||||
}
|
||||
|
||||
public interface IComponentSplitter {
|
||||
void split(Consumer<PageComponent> components, int currentPosition, int pageHeight);
|
||||
}
|
||||
|
||||
public interface IViewingRequirement {
|
||||
boolean canView(EntityPlayer player, World world, ItemStack guideStack, Guide guide);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
public class PageComponentFiller extends PageComponent {
|
||||
|
||||
public PageComponentFiller() {
|
||||
super(-1);
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.vecmath.Point2i;
|
||||
|
||||
public class PageComponentImage extends PageComponent {
|
||||
|
||||
private final Sprite sprite;
|
||||
|
||||
public PageComponentImage(Sprite sprite) {
|
||||
super(sprite.size.y);
|
||||
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
public static class Sprite {
|
||||
private final ResourceLocation location;
|
||||
private final Point2i startPosition;
|
||||
private final Point2i size;
|
||||
|
||||
public Sprite(ResourceLocation location, Point2i startPosition, Point2i size) {
|
||||
this.location = location;
|
||||
this.startPosition = startPosition;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void draw(int x, int y) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PageComponentItem extends PageComponent {
|
||||
|
||||
private final ItemStack item;
|
||||
|
||||
public PageComponentItem(ItemStack item) {
|
||||
super(18);
|
||||
|
||||
this.item = item;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PageComponentRecipe extends PageComponent {
|
||||
|
||||
private final Supplier<IRecipe> recipeGetter;
|
||||
private IRecipe recipe;
|
||||
|
||||
public PageComponentRecipe(ResourceLocation recipe) {
|
||||
super(60);
|
||||
|
||||
this.recipeGetter = () -> ForgeRegistries.RECIPES.getValue(recipe);
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PageComponentSmelting extends PageComponent {
|
||||
|
||||
private final ItemStack output;
|
||||
private final Supplier<ItemStack> inputGetter;
|
||||
private ItemStack input;
|
||||
|
||||
public PageComponentSmelting(ItemStack output) {
|
||||
super(20);
|
||||
|
||||
this.output = output;
|
||||
this.inputGetter = () -> FurnaceRecipes.instance().getSmeltingResult(output);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.page;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PageComponentText extends PageComponent {
|
||||
|
||||
private final ITextComponent textComponent;
|
||||
|
||||
public PageComponentText(ITextComponent text) {
|
||||
super(-1);
|
||||
|
||||
this.textComponent = text;
|
||||
withComponentSplitter(new StringSplitter(textComponent));
|
||||
}
|
||||
|
||||
private static class StringSplitter implements IComponentSplitter {
|
||||
|
||||
private final ITextComponent component;
|
||||
|
||||
public StringSplitter(ITextComponent component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void split(Consumer<PageComponent> components, int currentPosition, int pageHeight) {
|
||||
String fullText = component.getFormattedText();
|
||||
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
List<String> lines = fontRenderer.listFormattedStringToWidth(fullText, 300);
|
||||
int remainingSpace = pageHeight - currentPosition;
|
||||
for (String line : lines) {
|
||||
List<String> componentLines = Lists.newArrayList();
|
||||
if (remainingSpace >= fontRenderer.FONT_HEIGHT + 3) {
|
||||
componentLines.add(line);
|
||||
remainingSpace += fontRenderer.FONT_HEIGHT + 3;
|
||||
} else {
|
||||
remainingSpace = pageHeight;
|
||||
components.accept(new PageComponentText(new TextComponentString(String.join(" ", componentLines))));
|
||||
componentLines.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.wayoftime.bloodmagic.guide.Entry;
|
||||
import com.wayoftime.bloodmagic.guide.Guide;
|
||||
import com.wayoftime.bloodmagic.guide.page.PageComponentFiller;
|
||||
import com.wayoftime.bloodmagic.guide.page.PageComponentItem;
|
||||
import com.wayoftime.bloodmagic.guide.page.PageComponentText;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mod(modid = "test_guide")
|
||||
@Mod.EventBusSubscriber(modid = "test_guide")
|
||||
public class GuideTest {
|
||||
|
||||
public static final List<Guide> GUIDES = Lists.newArrayList();
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
GUIDES.add(new Guide(new ResourceLocation("guide_test", "test"), guide -> {
|
||||
guide.addCategory("test_cat_1", category -> {
|
||||
category.addEntry(new Entry("test_entry_1", test1 -> {
|
||||
test1.appendComponent(new PageComponentText(new TextComponentString("doot")));
|
||||
}));
|
||||
});
|
||||
|
||||
guide.addCategory("test_cat_2", category -> {
|
||||
category.addEntry(new Entry("test_entry_2", test2 -> {
|
||||
test2.appendComponent(new PageComponentText(new TextComponentString("what's up bud")));
|
||||
test2.appendComponent(new PageComponentItem(new ItemStack(Items.DIAMOND)));
|
||||
test2.appendComponent(new PageComponentFiller());
|
||||
}));
|
||||
|
||||
category.addEntry(new Entry("test_entry_3", test3 -> {
|
||||
test3.appendComponent(new PageComponentFiller());
|
||||
test3.appendComponent(new PageComponentFiller());
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerItems(RegistryEvent.Register<Item> event) {
|
||||
for (Guide guide : GUIDES)
|
||||
event.getRegistry().register(new ItemGuide(guide));
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.test;
|
||||
|
||||
import com.wayoftime.bloodmagic.guide.Guide;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemGuide extends Item {
|
||||
|
||||
public ItemGuide(Guide guide) {
|
||||
setRegistryName(guide.getId().toString().replace(":", "_"));
|
||||
setTranslationKey(guide.getId().toString());
|
||||
setMaxStackSize(1);
|
||||
setCreativeTab(CreativeTabs.MISC);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.test.gui;
|
||||
|
||||
import com.wayoftime.bloodmagic.guide.Category;
|
||||
import com.wayoftime.bloodmagic.guide.Entry;
|
||||
|
||||
public class Bookmark {
|
||||
|
||||
private Category category;
|
||||
private Entry entry;
|
||||
|
||||
public Bookmark atPosition(Category category, Entry entry) {
|
||||
this.category = category;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public Entry getEntry() {
|
||||
return entry;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.wayoftime.bloodmagic.guide.test.gui;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.wayoftime.bloodmagic.guide.Guide;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class GuiGuide extends GuiScreen {
|
||||
|
||||
private static final Map<Guide, GuiGuide> SCREENS = Maps.newHashMap();
|
||||
|
||||
private final Guide guide;
|
||||
private final Bookmark bookmark;
|
||||
|
||||
public GuiGuide(Guide guide) {
|
||||
this.guide = guide;
|
||||
this.bookmark = new Bookmark();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
// TODO update bookmark
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
public static GuiGuide getGui(Guide guide) {
|
||||
return SCREENS.compute(guide, (k, v) -> v == null ? new GuiGuide(guide) : v);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue