diff --git a/build.properties b/build.properties index 7ecc704..604033f 100644 --- a/build.properties +++ b/build.properties @@ -1,10 +1,7 @@ mod_version=0.9.2 -minecraft_version=1.8.9 -forge_version=11.15.1.1722 -mappings=snapshot_20151212 +minecraft_version=1.9 +forge_version=12.16.0.1804-1.9 +mappings=snapshot_20160324 -CCLIB_version=1.1.2.133 -ccc_version=1.0.5.36 -NEI_version=1.0.5.104 -jei_version=2.24.+ +jei_version=3.0.+ configurate_version=2.0 diff --git a/src/main/java/slimeknights/mantle/Mantle.java b/src/main/java/slimeknights/mantle/Mantle.java index 715843b..74af4c7 100644 --- a/src/main/java/slimeknights/mantle/Mantle.java +++ b/src/main/java/slimeknights/mantle/Mantle.java @@ -4,6 +4,7 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -16,7 +17,7 @@ import slimeknights.mantle.common.CommonProxy; * * @author Sunstrike */ -@Mod(modid = Mantle.modId, name = Mantle.modName, version = Mantle.modVersion, dependencies = "required-after:Forge@[11.15,)", acceptedMinecraftVersions="[1.8.8,1.8.9]") +@Mod(modid = Mantle.modId, name = Mantle.modName, version = Mantle.modVersion, dependencies = "required-after:Forge@[12.16.0.1804,)", acceptedMinecraftVersions = "[1.9,]") public class Mantle { public static final String modId = "mantle"; @@ -31,4 +32,9 @@ public class Mantle { /* Proxies for sides, used for graphics processing */ @SidedProxy(clientSide = "slimeknights.mantle.client.ClientProxy", serverSide = "slimeknights.mantle.common.CommonProxy") public static CommonProxy proxy; + + @Mod.EventHandler + public void preInit(FMLPreInitializationEvent event){ + proxy.preInit(); + } } diff --git a/src/main/java/slimeknights/mantle/block/BlockInventory.java b/src/main/java/slimeknights/mantle/block/BlockInventory.java index 4c5e173..e0fb51a 100644 --- a/src/main/java/slimeknights/mantle/block/BlockInventory.java +++ b/src/main/java/slimeknights/mantle/block/BlockInventory.java @@ -9,8 +9,10 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import slimeknights.mantle.tileentity.TileInventory; @@ -37,7 +39,7 @@ public abstract class BlockInventory extends BlockContainer { protected abstract boolean openGui(EntityPlayer player, World world, BlockPos pos); @Override - public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float clickX, float clickY, float clickZ) { if(player.isSneaking()) { return false; @@ -50,7 +52,6 @@ public abstract class BlockInventory extends BlockContainer { return true; } - @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { @@ -82,10 +83,10 @@ public abstract class BlockInventory extends BlockContainer { return getMetaFromState(state); } - // BlockContainer sets this to -1, which equals invisible - // we need 3 for standard forge rendering + // BlockContainer sets this to invisible + // we need model for standard forge rendering @Override - public int getRenderType() { - return 3; + public EnumBlockRenderType getRenderType(IBlockState state) { + return EnumBlockRenderType.MODEL; } } diff --git a/src/main/java/slimeknights/mantle/block/EnumBlock.java b/src/main/java/slimeknights/mantle/block/EnumBlock.java index 0405870..8bab9ef 100644 --- a/src/main/java/slimeknights/mantle/block/EnumBlock.java +++ b/src/main/java/slimeknights/mantle/block/EnumBlock.java @@ -3,7 +3,7 @@ package slimeknights.mantle.block; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyEnum; -import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; @@ -15,6 +15,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class EnumBlock & EnumBlock.IEnumMeta & IStringSerializable> extends Block { + public final PropertyEnum prop; private final E[] values; @@ -28,7 +29,7 @@ public class EnumBlock & EnumBlock.IEnumMeta & IStringSerializ @SuppressWarnings("unchecked") private static Material preInit(Material material, PropertyEnum property) { - tmp=property; + tmp = property; return material; } @@ -41,11 +42,11 @@ public class EnumBlock & EnumBlock.IEnumMeta & IStringSerializ } @Override - protected BlockState createBlockState() { + protected BlockStateContainer createBlockState() { if(prop == null) { - return new BlockState(this, tmp); + return new BlockStateContainer(this, tmp); } - return new BlockState(this, prop); + return new BlockStateContainer(this, prop); } @Override @@ -55,7 +56,7 @@ public class EnumBlock & EnumBlock.IEnumMeta & IStringSerializ @Override public int getMetaFromState(IBlockState state) { - return ((E) state.getValue(prop)).getMeta(); + return state.getValue(prop).getMeta(); } @Override @@ -72,6 +73,7 @@ public class EnumBlock & EnumBlock.IEnumMeta & IStringSerializ } public interface IEnumMeta { + int getMeta(); } } diff --git a/src/main/java/slimeknights/mantle/client/ClientProxy.java b/src/main/java/slimeknights/mantle/client/ClientProxy.java index fb018d3..cfabbca 100644 --- a/src/main/java/slimeknights/mantle/client/ClientProxy.java +++ b/src/main/java/slimeknights/mantle/client/ClientProxy.java @@ -1,6 +1,11 @@ package slimeknights.mantle.client; +import slimeknights.mantle.client.book.BookLoader; import slimeknights.mantle.common.CommonProxy; public class ClientProxy extends CommonProxy { + @Override + public void preInit() { + new BookLoader(); + } } diff --git a/src/main/java/slimeknights/mantle/client/ModelHelper.java b/src/main/java/slimeknights/mantle/client/ModelHelper.java index 94370b6..ec85aac 100644 --- a/src/main/java/slimeknights/mantle/client/ModelHelper.java +++ b/src/main/java/slimeknights/mantle/client/ModelHelper.java @@ -1,18 +1,6 @@ package slimeknights.mantle.client; -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.reflect.TypeToken; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -20,31 +8,23 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.resources.IResource; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.model.IColoredBakedQuad; -import net.minecraftforge.client.model.IModelPart; -import net.minecraftforge.client.model.IModelState; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraftforge.common.model.IModelPart; +import net.minecraftforge.common.model.IModelState; import net.minecraftforge.client.model.SimpleModelState; -import net.minecraftforge.client.model.TRSRTransformation; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Type; -import java.util.Map; +import net.minecraftforge.common.model.TRSRTransformation; +import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; +import net.minecraftforge.client.model.pipeline.VertexTransformer; import javax.vecmath.Vector3f; public class ModelHelper { - static final Type maptype = new TypeToken>() {}.getType(); - private static final Gson - GSON = - new GsonBuilder().registerTypeAdapter(maptype, ModelTextureDeserializer.INSTANCE).create(); - - public static final Optional DEFAULT_ITEM_STATE; - public static final Optional DEFAULT_TOOL_STATE; + public static final IModelState DEFAULT_ITEM_STATE; + public static final IModelState DEFAULT_TOOL_STATE; + public static final TRSRTransformation BLOCK_THIRD_PERSON_RIGHT; + public static final TRSRTransformation BLOCK_THIRD_PERSON_LEFT; public static TextureAtlasSprite getTextureFromBlock(Block block, int meta) { IBlockState state = block.getStateFromMeta(meta); @@ -56,104 +36,83 @@ public class ModelHelper { } public static BakedQuad colorQuad(int color, BakedQuad quad) { - int[] data = quad.getVertexData(); - - int a = (color >> 24); - if(a == 0) { - a = 255; - } - - int c = 0; - c |= ((color >> 16) & 0xFF) << 0; // red - c |= ((color >> 8) & 0xFF) << 8; // green - c |= ((color >> 0) & 0xFF) << 16; // blue - c |= (a & 0xFF) << 24; // alpha - - // update color in the data. all 4 Vertices. - for(int i = 0; i < 4; i++) { - data[i * 7 + 3] = c; - } - - return new IColoredBakedQuad.ColoredBakedQuad(data, -1, quad.getFace()); + ColorTransformer transformer = new ColorTransformer(color, quad.getFormat()); + quad.pipe(transformer); + return transformer.build(); } - public static Map loadTexturesFromJson(ResourceLocation location) throws IOException { - // get the json - IResource - iresource = - Minecraft.getMinecraft().getResourceManager() - .getResource(new ResourceLocation(location.getResourceDomain(), location.getResourcePath() + ".json")); - Reader reader = new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8); - - return GSON.fromJson(reader, maptype); - } - - public static ImmutableList loadTextureListFromJson(ResourceLocation location) throws IOException { - ImmutableList.Builder builder = ImmutableList.builder(); - for(String s : loadTexturesFromJson(location).values()) { - builder.add(new ResourceLocation(s)); - } - - return builder.build(); - } - - public static ResourceLocation getModelLocation(ResourceLocation location) { - return new ResourceLocation(location.getResourceDomain(), "models/" + location.getResourcePath() + ".json"); + private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s) { + return TRSRTransformation.blockCenterToCorner(new TRSRTransformation( + new Vector3f(tx / 16, ty / 16, tz / 16), + TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)), + new Vector3f(s, s, s), + null)); } static { { // equals forge:default-item - TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( - new Vector3f(0, 1f / 16, -3f / 16), - TRSRTransformation.quatFromYXZDegrees(new Vector3f(-90, 0, 0)), - new Vector3f(0.55f, 0.55f, 0.55f), - null)); - TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( - new Vector3f(0, 4f / 16, 2f / 16), - TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)), - new Vector3f(1.7f, 1.7f, 1.7f), - null)); - DEFAULT_ITEM_STATE = Optional.of(new SimpleModelState(ImmutableMap.of(ItemCameraTransforms.TransformType.THIRD_PERSON, thirdperson, ItemCameraTransforms.TransformType.FIRST_PERSON, firstperson))); + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.put(ItemCameraTransforms.TransformType.GROUND, get(0, 2, 0, 0, 0, 0, 0.5f)); + builder.put(ItemCameraTransforms.TransformType.HEAD, get(0, 13, 7, 0, 180, 0, 1)); + builder.put(ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 3, 1, 0, 0, 0, 0.55f)); + builder.put(ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, get(0, 3, 1, 0, 0, 0, 0.55f)); + builder.put(ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f)); + builder.put(ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f)); + DEFAULT_ITEM_STATE = new SimpleModelState(builder.build()); } { - TRSRTransformation thirdperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( - new Vector3f(0, 1.25f / 16, -3.5f / 16), - TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, 90, -35)), - new Vector3f(0.85f, 0.85f, 0.85f), - null)); - TRSRTransformation firstperson = TRSRTransformation.blockCenterToCorner(new TRSRTransformation( - new Vector3f(0, 4f / 16, 2f / 16), - TRSRTransformation.quatFromYXZDegrees(new Vector3f(0, -135, 25)), - new Vector3f(1.7f, 1.7f, 1.7f), - null)); - DEFAULT_TOOL_STATE = Optional.of(new SimpleModelState(ImmutableMap - .of(ItemCameraTransforms.TransformType.THIRD_PERSON, thirdperson, ItemCameraTransforms.TransformType.FIRST_PERSON, firstperson))); + // equals forge:default-tool + DEFAULT_TOOL_STATE = new SimpleModelState(ImmutableMap.of( + ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, get(0, 4, 0.5f, 0, -90, 55, 0.85f), + ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, get(0, 4, 0.5f, 0, 90, -55, 0.85f), + ItemCameraTransforms.TransformType.FIRST_PERSON_RIGHT_HAND, get(1.13f, 3.2f, 1.13f, 0, -90, 25, 0.68f), + ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, get(1.13f, 3.2f, 1.13f, 0, 90, -25, 0.68f))); + } + { + BLOCK_THIRD_PERSON_RIGHT = get(0, 2.5f, 0, 75, 45, 0, 0.375f); + BLOCK_THIRD_PERSON_LEFT = get(0, 0, 0, 0, 255, 0, 0.4f); } } - /** - * Deseralizes a json in the format of { "textures": { "foo": "texture",... }} - * Ignores all invalid json - */ - public static class ModelTextureDeserializer implements JsonDeserializer> { - public static final ModelTextureDeserializer INSTANCE = new ModelTextureDeserializer(); + private static class ColorTransformer extends VertexTransformer { - private static final Gson GSON = new Gson(); + private final float r,g,b,a; + + public ColorTransformer(int color, VertexFormat format) { + super(new UnpackedBakedQuad.Builder(format)); + + int a = (color >> 24); + if(a == 0) { + a = 255; + } + int r = (color >> 16) & 0xFF; + int g = (color >> 8) & 0xFF; + int b = (color >> 0) & 0xFF; + + this.r = (float)r/255f; + this.g = (float)g/255f; + this.b = (float)b/255f; + this.a = (float)a/255f; + } @Override - public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { + public void put(int element, float... data) { + VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); - JsonObject obj = json.getAsJsonObject(); - JsonElement texElem = obj.get("textures"); - - if(texElem == null) { - throw new JsonParseException("Missing textures entry in json"); + // transform normals and position + if(usage == VertexFormatElement.EnumUsage.COLOR && data.length >= 4) { + data[0] = r; + data[1] = g; + data[2] = b; + data[3] = a; } + super.put(element, data); + } - return GSON.fromJson(texElem, maptype); + public UnpackedBakedQuad build() { + return ((UnpackedBakedQuad.Builder) parent).build(); } } } diff --git a/src/main/java/slimeknights/mantle/client/book/BookHelper.java b/src/main/java/slimeknights/mantle/client/book/BookHelper.java new file mode 100644 index 0000000..0a2154d --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/BookHelper.java @@ -0,0 +1,38 @@ +package slimeknights.mantle.client.book; + +import java.util.Arrays; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; + +public class BookHelper { + + public static String getSavedPage(ItemStack item) { + if (item != null && item.hasTagCompound()) { + NBTTagCompound mantleBook = item.getTagCompound().getCompoundTag("mantle").getCompoundTag("book"); + + if (mantleBook.hasKey("page", Arrays.asList(NBTBase.NBT_TYPES).indexOf("STRING"))) { + return mantleBook.getString("page"); + } + } + + return ""; + } + + public static void writeSavedPage(ItemStack item, String page) { + NBTTagCompound compound = item.getTagCompound(); + + if (compound == null) + compound = new NBTTagCompound(); + + NBTTagCompound mantle = compound.getCompoundTag("mantle"); + NBTTagCompound book = mantle.getCompoundTag("book"); + + book.setString("page", page); + + mantle.setTag("book", book); + compound.setTag("mantle", mantle); + item.setTagCompound(compound); + } + +} diff --git a/src/main/java/slimeknights/mantle/client/book/BookLoader.java b/src/main/java/slimeknights/mantle/client/book/BookLoader.java new file mode 100644 index 0000000..0609282 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/BookLoader.java @@ -0,0 +1,183 @@ +package slimeknights.mantle.client.book; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.util.HashMap; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IReloadableResourceManager; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumHand; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.Mantle; +import slimeknights.mantle.client.book.action.StringActionProcessor; +import slimeknights.mantle.client.book.action.protocol.ProtocolGoToPage; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.PageData; +import slimeknights.mantle.client.book.data.SectionData; +import slimeknights.mantle.client.book.data.content.ContentBlank; +import slimeknights.mantle.client.book.data.content.ContentBlockInteraction; +import slimeknights.mantle.client.book.data.content.ContentCrafting; +import slimeknights.mantle.client.book.data.content.ContentError; +import slimeknights.mantle.client.book.data.content.ContentImage; +import slimeknights.mantle.client.book.data.content.ContentImageText; +import slimeknights.mantle.client.book.data.content.ContentSmelting; +import slimeknights.mantle.client.book.data.content.ContentSmithing; +import slimeknights.mantle.client.book.data.content.ContentStructure; +import slimeknights.mantle.client.book.data.content.ContentText; +import slimeknights.mantle.client.book.data.content.ContentTextImage; +import slimeknights.mantle.client.book.data.content.ContentTextLeftImage; +import slimeknights.mantle.client.book.data.content.ContentTextRightImage; +import slimeknights.mantle.client.book.data.content.PageContent; +import slimeknights.mantle.client.book.data.deserializer.HexStringDeserializer; +import slimeknights.mantle.client.book.repository.BookRepository; +import slimeknights.mantle.network.NetworkWrapper; +import slimeknights.mantle.network.book.PacketUpdateSavedPage; + +@SideOnly(Side.CLIENT) +public class BookLoader implements IResourceManagerReloadListener { + + /** GSON object to be used for book loading purposes */ + public static final Gson GSON = new GsonBuilder().registerTypeAdapter(int.class, new HexStringDeserializer()).create(); + + /** Maps page content presets to names */ + private static final HashMap> typeToContentMap = new HashMap<>(); + + /** Internal registry of all books for the purposes of the reloader, maps books to name */ + private static final HashMap books = new HashMap<>(); + + private static final NetworkWrapper wrapper = new NetworkWrapper("mantle:books"); + + public BookLoader() { + ((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this); + + wrapper.registerPacketServer(PacketUpdateSavedPage.class); + + // Register page types + registerPageType("blank", ContentBlank.class); + registerPageType("text", ContentText.class); + registerPageType("image", ContentImage.class); + registerPageType("image with text below", ContentImageText.class); + registerPageType("text with image below", ContentTextImage.class); + registerPageType("text with left image etch", ContentTextLeftImage.class); + registerPageType("text with right image etch", ContentTextRightImage.class); + registerPageType("crafting", ContentCrafting.class); + registerPageType("smelting", ContentSmelting.class); + registerPageType("smithing", ContentSmithing.class); + registerPageType("block interaction", ContentBlockInteraction.class); + registerPageType("structure", ContentStructure.class); + + // Register action protocols + StringActionProcessor.registerProtocol(new ProtocolGoToPage()); + StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, "-rtn")); + } + + /** + * Registers a type of page prefabricate + * + * @param name The name of the page type + * @param clazz The PageContent class for this page type + * @RecommendedInvoke init + */ + public static void registerPageType(String name, Class clazz) { + if (typeToContentMap.containsKey(name)) + throw new IllegalArgumentException("Page type " + name + " already in use."); + + typeToContentMap.put(name, clazz); + } + + /** + * Gets a type of page prefabricate by name + * + * @param name The name of the page type + * @return The class of the page type, ContentError.class if page type not registered + */ + public static Class getPageType(String name) { + return typeToContentMap.get(name); + } + + /** + * Adds a book to the loader, and returns a reference object + * Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded + * + * @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added + * @param repositories All the repositories the book will load the sections from + * @return The book object, not immediately populated + */ + public static BookData registerBook(String name, BookRepository... repositories) { + return registerBook(name, true, true, repositories); + } + + /** + * Adds a book to the loader, and returns a reference object + * Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded + * + * @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added + * @param appendIndex Whether an index should be added to the front of the book using a BookTransformer + * @param appendContentTable Whether a table of contents should be added to the front of each section using a BookTransformer + * @param repositories All the repositories the book will load the sections from + * @return The book object, not immediately populated + */ + public static BookData registerBook(String name, boolean appendIndex, boolean appendContentTable, BookRepository... repositories) { + BookData info = new BookData(repositories); + + books.put(name.contains(":") ? name : Loader.instance().activeModContainer().getModId() + ":" + name, info); + + if (appendIndex) + info.addTransformer(new BookTransformer.IndexTranformer()); + if (appendContentTable) + info.addTransformer(new BookTransformer.ContentTableTransformer()); + + return info; + } + + /** + * Returns a book by its name + * + * @param name The name of the book, prefixed with modid: + * @return The instance of the book data, or null if the book is not registered + */ + public static BookData getBook(String name) { + return null; + } + + public static void updateSavedPage(EntityPlayer player, ItemStack item, String page) { + if (player.getHeldItem(EnumHand.MAIN_HAND) == null) + return; + + BookHelper.writeSavedPage(item, page); + wrapper.network.sendToServer(new PacketUpdateSavedPage(page)); + } + + /** + * Reloads all the books, called when the resource manager reloads, such as when the resource pack or the language is changed + */ + @Override + public void onResourceManagerReload(IResourceManager resourceManager) { + Mantle.logger.info("Started loading books..."); + long time = System.nanoTime(); + + for (BookData book : books.values()) { + try { + book.load(); + } catch (Exception e) { + book.sections.clear(); + SectionData section = new SectionData(true); + section.name = "errorenous"; + PageData page = new PageData(true); + page.name = "errorenous"; + page.content = new ContentError("Failed to load the book due to an unexpected error.", e); + section.pages.add(page); + book.sections.add(section); + + e.printStackTrace(); + } + } + + Mantle.logger.info("Book loading completed in " + ((System.nanoTime() - time) / 1000000000D) + " seconds."); + } +} \ No newline at end of file diff --git a/src/main/java/slimeknights/mantle/client/book/BookTransformer.java b/src/main/java/slimeknights/mantle/client/book/BookTransformer.java new file mode 100644 index 0000000..e64bdfe --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/BookTransformer.java @@ -0,0 +1,98 @@ +package slimeknights.mantle.client.book; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import net.minecraft.stats.StatFileWriter; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.PageData; +import slimeknights.mantle.client.book.data.SectionData; +import slimeknights.mantle.client.book.data.content.ContentSectionList; +import slimeknights.mantle.client.book.data.content.ContentTableOfContents; +import slimeknights.mantle.client.book.data.element.TextData; + +public abstract class BookTransformer { + + /** + * Called when all the sections within the book are loaded. + * + * @param book The object to the book to be transformed + */ + public abstract void transform(BookData book); + + protected static class IndexTranformer extends BookTransformer { + + @Override + public void transform(BookData book) { + SectionData index = new SectionData(true) { + @Override + public void update(StatFileWriter writer) { + pages.clear(); + + List visibleSections = parent.getVisibleSections(writer); + + if (visibleSections.isEmpty()) + return; + + visibleSections.remove(0); + + PageData[] pages = new PageData[(int) Math.ceil(visibleSections.size() / 9F)]; + + for (int i = 0; i < pages.length; i++) { + pages[i] = new PageData(true); + + pages[i].name = "page" + (i + 1); + + ContentSectionList content = new ContentSectionList(); + pages[i].content = content; + + for (int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) { + content.addSection(visibleSections.get(j)); + } + } + + this.pages = new ArrayList<>(Arrays.asList(pages)); + } + }; + + index.name = "index"; + book.sections.add(0, index); + } + } + + protected static class ContentTableTransformer extends BookTransformer { + + @Override + public void transform(BookData book) { + final int ENTRIES_PER_PAGE = 24; + + for (SectionData section : book.sections) { + if (section.name.equals("index")) + continue; + + int genPages = (int) Math.ceil(section.getPageCount() * 1.F / ENTRIES_PER_PAGE); + + if (genPages == 0) + continue; + + PageData[] pages = new PageData[genPages]; + + for (int i = 0; i < pages.length; i++) { + pages[i] = new PageData(true); + pages[i].name = "tableofcontents" + i; + TextData[] text = new TextData[i > pages.length - 1 ? ENTRIES_PER_PAGE : section.getPageCount() - (genPages - 1) * ENTRIES_PER_PAGE]; + for (int j = 0; j < text.length; j++) { + text[j] = new TextData((i * ENTRIES_PER_PAGE + j + 1) + ". " + section.pages.get(i * ENTRIES_PER_PAGE + j).getTitle()); + text[j].action = "go-to-page-rtn:" + section.name + "." + section.pages.get(i * ENTRIES_PER_PAGE + j).name; + } + + pages[i].content = new ContentTableOfContents(i == 0 ? section.getTitle() : "", text); + } + + for (int i = pages.length - 1; i >= 0; i--) { + section.pages.add(0, pages[i]); + } + } + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/action/StringActionProcessor.java b/src/main/java/slimeknights/mantle/client/book/action/StringActionProcessor.java new file mode 100644 index 0000000..dba8d5d --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/action/StringActionProcessor.java @@ -0,0 +1,33 @@ +package slimeknights.mantle.client.book.action; + +import java.util.HashMap; +import slimeknights.mantle.client.book.action.protocol.ActionProtocol; +import slimeknights.mantle.client.gui.book.GuiBook; + +public class StringActionProcessor { + + public static final String PROTOCOL_SEPARATOR = ":"; + + private static final HashMap protocols = new HashMap<>(); + + public static void registerProtocol(ActionProtocol protocol) { + if (protocol == null || protocol.protocol == null || protocol.protocol.isEmpty()) + throw new IllegalArgumentException("Protocol must be defined and must not have an empty protocol identifier."); + if (protocols.containsKey(protocol.protocol)) + throw new IllegalArgumentException("Protocol " + protocol.protocol + " already registered."); + + protocols.put(protocol.protocol, protocol); + } + + //Format: action://param + public static void process(String action, GuiBook book) { + if (!action.contains(PROTOCOL_SEPARATOR)) + return; + + String protoId = action.substring(0, action.indexOf(PROTOCOL_SEPARATOR)); + String protoParam = action.substring(action.indexOf(PROTOCOL_SEPARATOR) + PROTOCOL_SEPARATOR.length()); + + if (protocols.containsKey(protoId)) + protocols.get(protoId).processCommand(book, protoParam); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/action/protocol/ActionProtocol.java b/src/main/java/slimeknights/mantle/client/book/action/protocol/ActionProtocol.java new file mode 100644 index 0000000..c583aca --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/action/protocol/ActionProtocol.java @@ -0,0 +1,14 @@ +package slimeknights.mantle.client.book.action.protocol; + +import slimeknights.mantle.client.gui.book.GuiBook; + +public abstract class ActionProtocol { + + public final String protocol; + + public ActionProtocol(String protocol) { + this.protocol = protocol; + } + + public abstract void processCommand(GuiBook book, String param); +} diff --git a/src/main/java/slimeknights/mantle/client/book/action/protocol/ProtocolGoToPage.java b/src/main/java/slimeknights/mantle/client/book/action/protocol/ProtocolGoToPage.java new file mode 100644 index 0000000..4c00673 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/action/protocol/ProtocolGoToPage.java @@ -0,0 +1,26 @@ +package slimeknights.mantle.client.book.action.protocol; + +import slimeknights.mantle.client.gui.book.GuiBook; + +public class ProtocolGoToPage extends ActionProtocol { + + private final boolean returner; + + public ProtocolGoToPage() { + this(false, ""); + } + + public ProtocolGoToPage(boolean returner, String suffix) { + super("go-to-page" + suffix); + + this.returner = returner; + } + + @Override + public void processCommand(GuiBook book, String param) { + int pageNum = book.book.findPageNumber(param); + + if (pageNum >= 0) + book.openPage(pageNum, returner); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/AppearanceData.java b/src/main/java/slimeknights/mantle/client/book/data/AppearanceData.java new file mode 100644 index 0000000..3672121 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/AppearanceData.java @@ -0,0 +1,21 @@ +package slimeknights.mantle.client.book.data; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class AppearanceData implements IDataItem { + + public int coverColor = 0x8B4631; + public int arrowColor = 0xFFFFD3; + public int arrowColorHover = 0xFF541C; + public int lockedSectionColor = 0x000000; + public String title = ""; + public String subtitle = ""; + public boolean drawPageNumbers = true; + + @Override + public void load() { + + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/BookData.java b/src/main/java/slimeknights/mantle/client/book/data/BookData.java new file mode 100644 index 0000000..65149a7 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/BookData.java @@ -0,0 +1,292 @@ +package slimeknights.mantle.client.book.data; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import javax.annotation.Nullable; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.StatFileWriter; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.BookTransformer; +import slimeknights.mantle.client.book.data.content.ContentError; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.repository.BookRepository; +import slimeknights.mantle.client.gui.book.GuiBook; + +@SideOnly(Side.CLIENT) +public class BookData implements IDataItem { + + public transient int unnamedSectionCounter = 0; + public transient ArrayList sections = new ArrayList<>(); + public transient AppearanceData appearance = new AppearanceData(); + public transient ArrayList itemLinks = new ArrayList<>(); + public transient HashMap strings = new HashMap<>(); + + protected final transient ArrayList transformers = new ArrayList<>(); + + private ArrayList repositories; + + public BookData(BookRepository... repositories) { + this.repositories = new ArrayList<>(Arrays.asList(repositories)); + } + + @Override + public void load() { + sections.clear(); + appearance = new AppearanceData(); + itemLinks.clear(); + + for (BookRepository repo : repositories) { + try { + List repoContents = repo.getSections(); + sections.addAll(repoContents); + + for (SectionData section : repoContents) { + section.source = repo; + } + } catch (Exception e) { + SectionData error = new SectionData(); + error.name = "errorenous"; + PageData page = new PageData(true); + page.name = "errorenous"; + page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e); + error.pages.add(page); + sections.add(error); + } + + ResourceLocation appearanceLocation = repo.getResourceLocation("appearance.json"); + + if (repo.resourceExists(appearanceLocation)) + try { + appearance = BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(appearanceLocation)), AppearanceData.class); + } catch (Exception ignored) { + } + + appearance.load(); + + ResourceLocation itemLinkLocation = repo.getResourceLocation("items.json"); + + if (repo.resourceExists(itemLinkLocation)) { + try { + itemLinks = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(itemLinkLocation)), ItemStackData.ItemLink[].class))); + } catch (Exception ignored) { + } + } + + ResourceLocation languageLocation = repo.getResourceLocation("language.lang"); + + if (repo.resourceExists(languageLocation)) { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(repo.getResource(languageLocation).getInputStream())); + + String next = br.readLine(); + + while (next != null) { + if (!next.startsWith("//") && next.contains("=")) { + String key = next.substring(0, next.indexOf('=')); + String value = next.substring(next.indexOf('=') + 1); + + strings.put(key, value); + } + + next = br.readLine(); + } + } catch (Exception ignored) { + } + } + } + + for (SectionData section : sections) { + if (section.source == null) + section.source = BookRepository.DUMMY; + + section.parent = this; + section.load(); + } + + for (BookTransformer transformer : transformers) + transformer.transform(this); + + // Loads orphaned sections, unless something went wrong, that would only be sections added by a transformer + for (SectionData section : sections) { + if (section.source == null) + section.source = BookRepository.DUMMY; + + if (section.parent == null) { + section.parent = this; + section.load(); + } + } + } + + public SectionData findSection(String name) { + return findSection(name, null); + } + + public SectionData findSection(String name, @Nullable StatFileWriter writer) { + for (SectionData section : sections) { + section.update(writer); + + if (section.name.equals(name.toLowerCase())) + return section.isUnlocked(writer) ? section : null; + } + + return null; + } + + public int getFirstPageNumber(SectionData section) { + return getFirstPageNumber(section, null); + } + + public int getFirstPageNumber(SectionData section, @Nullable StatFileWriter writer) { + int pages = 0; + for (SectionData sect : sections) { + sect.update(writer); + + if (section == sect) + return section.isUnlocked(writer) ? pages + 1 : -1; + + if (!sect.isUnlocked(writer)) + continue; + + pages += sect.getPageCount(); + } + + return -1; + } + + public PageData findPage(int number) { + return findPage(number, null); + } + + public PageData findPage(int number, @Nullable StatFileWriter writer) { + if (number < 0) + return null; + + int pages = 0; + for (SectionData section : sections) { + section.update(writer); + + if (!section.isUnlocked(writer)) + continue; + + if (pages + section.getPageCount() > number) + return section.pages.get(number - pages); + else + pages += section.getPageCount(); + } + + return null; + } + + public PageData findPage(String location) { + return findPage(location, null); + } + + public PageData findPage(String location, @Nullable StatFileWriter writer) { + return findPage(findPageNumber(location, writer)); + } + + public int findPageNumber(String location) { + return findPageNumber(location, null); + } + + public int findPageNumber(String location, @Nullable StatFileWriter writer) { + location = location.toLowerCase(); + + int pages = 0; + + if (!location.contains(".")) + return -1; + + String sectionName = location.substring(0, location.indexOf('.')); + String pageName = location.substring(location.indexOf('.') + 1); + + for (SectionData section : sections) { + section.update(writer); + + if (!section.isUnlocked(writer)) + continue; + + if (!sectionName.equals(section.name)) { + pages += section.getPageCount(); + continue; + } + + for (PageData page : section.pages) { + if (!pageName.equals(page.name)) { + pages++; + continue; + } + + return pages + 1; + } + } + + return -1; + } + + public int getPageCount() { + return getPageCount(null); + } + + public int getPageCount(@Nullable StatFileWriter writer) { + int pages = 0; + for (SectionData section : sections) { + section.update(writer); + + pages += section.isUnlocked(writer) ? section.getPageCount() : 0; + } + return pages; + } + + public int getFullPageCount() { + return getFullPageCount(null); + } + + public int getFullPageCount(@Nullable StatFileWriter writer) { + return (int) Math.ceil((getPageCount(writer) - 1) / 2F) + 1; + } + + public String getItemAction(ItemStackData item) { + for (ItemStackData.ItemLink link : itemLinks) { + if (item.id.equals(link.item.id) && (!link.damageSensitive || item.damage == link.item.damage)) + return link.action; + } + + return ""; + } + + public List getVisibleSections(StatFileWriter writer) { + List visible = new ArrayList<>(); + + for (SectionData section : sections) { + if (section.isUnlocked(writer) || !section.hideWhenLocked) + visible.add(section); + } + + return visible; + } + + public void openGui(@Nullable ItemStack item) { + if (Minecraft.getMinecraft().thePlayer != null) + Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, Minecraft.getMinecraft().thePlayer.getStatFileWriter(), item)); + } + + public void addRepository(BookRepository repository) { + if (repository != null && !this.repositories.contains(repository)) + this.repositories.add(repository); + } + + public void addTransformer(BookTransformer transformer) { + if (transformer != null && !transformers.contains(transformer)) + transformers.add(transformer); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/BookmarkData.java b/src/main/java/slimeknights/mantle/client/book/data/BookmarkData.java new file mode 100644 index 0000000..60d6d04 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/BookmarkData.java @@ -0,0 +1,21 @@ +package slimeknights.mantle.client.book.data; + +public class BookmarkData { + + public String text = ""; + public int color = 0x464646; // Index bookmark : 0x1ED400 + public String page = ""; + + public BookmarkData() { + this(""); + } + + public BookmarkData(String page) { + this(page, ""); + } + + public BookmarkData(String page, String text) { + this.page = page; + this.text = text; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/IDataItem.java b/src/main/java/slimeknights/mantle/client/book/data/IDataItem.java new file mode 100644 index 0000000..9aeda20 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/IDataItem.java @@ -0,0 +1,10 @@ +package slimeknights.mantle.client.book.data; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public interface IDataItem { + + void load(); +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/PageData.java b/src/main/java/slimeknights/mantle/client/book/data/PageData.java new file mode 100644 index 0000000..d4b3b76 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/PageData.java @@ -0,0 +1,167 @@ +package slimeknights.mantle.client.book.data; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import net.minecraft.client.resources.IResource; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.data.content.ContentError; +import slimeknights.mantle.client.book.data.content.PageContent; +import slimeknights.mantle.client.book.data.element.BlockData; +import slimeknights.mantle.client.book.data.element.DataLocation; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.repository.BookRepository; + +@SideOnly(Side.CLIENT) +public class PageData implements IDataItem { + + private static final transient ArrayList hotswaps = new ArrayList<>(); + + public String name = null; + public String type = ""; + public String data = ""; + + public transient SectionData parent; + public transient BookRepository source; + public transient PageContent content; + + public PageData() { + this(false); + } + + public PageData(boolean custom) { + if (custom) + data = "no-load"; + } + + @Override + @SuppressWarnings("unchecked") + public void load() { + if (name == null) + name = "page" + parent.unnamedPageCounter++; + + name = name.toLowerCase(); + + if (!data.equals("no-load")) { + IResource pageInfo = source.getResource(source.getResourceLocation(data)); + if (pageInfo != null) { + String data = source.resourceToString(pageInfo); + if (!data.isEmpty()) { + Class ctype = BookLoader.getPageType(type); + + try { + content = BookLoader.GSON.fromJson(data, ctype); + } catch (Exception e) { + content = new ContentError(ctype == null ? "Failed to create a page of type \"" + type + "\", perhaps the type is not registered?" : "Failed to create a page of type \"" + type + "\", perhaps the page file \"" + this.data + "\" is missing or invalid?", e); + } + } + } + } + + if (content == null) { + try { + content = BookLoader.getPageType(type).newInstance(); + } catch (InstantiationException | IllegalAccessException | NullPointerException e) { + content = new ContentError("Failed to create a page of type \"" + type + "\", perhaps the type is not registered?"); + } + } + + try { + content.parent = this; + content.load(); + } catch (Exception e) { + content = new ContentError("Failed to load page " + parent.name + "." + name + ".", e); + e.printStackTrace(); + } + + content.source = source; + + for (Field f : content.getClass().getFields()) { + if (Modifier.isTransient(f.getModifiers()) || Modifier.isStatic(f.getModifiers()) || Modifier.isFinal(f.getModifiers())) + continue; + + try { + if (f.get(content) == null) + continue; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + for (ValueHotswap swap : hotswaps) { + Class c = f.getType(); + + if (c.isArray() && c.getComponentType().isAssignableFrom(swap.t)) + try { + f.setAccessible(true); + Object[] o = (Object[]) f.get(content); + + for (Object ob : o) + swap.swap(source, ob); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + else if (swap.t.isAssignableFrom(c)) { + try { + f.setAccessible(true); + Object o = f.get(content); + + swap.swap(source, o); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + } + } + + public static void addSwap(Class t, Class swap) { + try { + ValueHotswap hotswap = swap.newInstance(); + hotswap.t = t; + + hotswaps.add(hotswap); + } catch (InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + } + + public String getTitle() { + String title = parent.parent.strings.get(parent.name + "." + name); + return title == null ? name : title; + } + + static { + addSwap(DataLocation.class, new ValueHotswap() { + @Override + public void swap(BookRepository source, DataLocation object) { + object.location = source.getResourceLocation(object.file, true); + } + }.getClass()); + addSwap(ItemStackData.class, new ValueHotswap() { + @Override + public void swap(BookRepository source, ItemStackData object) { + object.source = source; + object.itemListLocation = source.getResourceLocation(object.itemList); + + if (object.itemListLocation != null) + object.id = "->itemList"; + } + }.getClass()); + addSwap(BlockData.class, new ValueHotswap() { + @Override + public void swap(BookRepository source, BlockData object) { + if (object.endPos == null) + object.endPos = object.pos; + } + }.getClass()); + } + + public static abstract class ValueHotswap { + + protected Class t; + + public abstract void swap(BookRepository source, T object); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/SectionData.java b/src/main/java/slimeknights/mantle/client/book/data/SectionData.java new file mode 100644 index 0000000..5c7455d --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/SectionData.java @@ -0,0 +1,118 @@ +package slimeknights.mantle.client.book.data; + +import java.util.ArrayList; +import java.util.Arrays; +import javax.annotation.Nullable; +import net.minecraft.client.resources.IResource; +import net.minecraft.stats.Achievement; +import net.minecraft.stats.AchievementList; +import net.minecraft.stats.StatFileWriter; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.data.content.ContentError; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.repository.BookRepository; + +@SideOnly(Side.CLIENT) +public class SectionData implements IDataItem { + + public String name = null; + public ImageData icon = new ImageData(); + public String[] requirements = new String[0]; + public boolean hideWhenLocked = false; + public String data = ""; + + public transient int unnamedPageCounter = 0; + public transient BookData parent; + public transient BookRepository source; + public transient ArrayList pages = new ArrayList<>(); + + public SectionData() { + this(false); + } + + public SectionData(boolean custom) { + if (custom) + data = "no-load"; + } + + @Override + public void load() { + if (name == null) + name = "section" + parent.unnamedSectionCounter++; + + name = name.toLowerCase(); + + if (!data.equals("no-load")) { + IResource pagesInfo = source.getResource(source.getResourceLocation(data)); + if (pagesInfo != null) { + String data = source.resourceToString(pagesInfo); + if (!data.isEmpty()) + try { + pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class))); + } catch (Exception e) { + pages = new ArrayList<>(); + PageData pdError = new PageData(true); + pdError.name = "errorrenous"; + pdError.content = new ContentError("Failed to load section " + name + ".", e); + pages.add(pdError); + } + } + } + + for (PageData page : pages) { + page.parent = this; + page.source = source; + page.load(); + } + + icon.location = source.getResourceLocation(icon.file, true); + } + + public void update(@Nullable StatFileWriter writer) { + } + + public String getTitle() { + String title = parent.strings.get(name); + return title == null ? name : title; + } + + public int getPageCount() { + return pages.size(); + } + + public boolean isUnlocked(StatFileWriter writer) { + if (writer == null || requirements == null || requirements.length == 0) + return true; + + for (String achievement : requirements) { + if (!requirementSatisfied(achievement, writer)) + return false; + } + + return true; + } + + public static boolean requirementSatisfied(String requirement, StatFileWriter writer) { + if (writer == null) + return true; + + Achievement achievement = findAchievement(requirement); + + return achievement == null || writer.hasAchievementUnlocked(achievement); + + } + + public static Achievement findAchievement(String name) { + if (name == null || name.isEmpty()) + return null; + + for (Achievement achievement : AchievementList.ACHIEVEMENTS) { + if (achievement.statId.equals(name)) + return achievement; + } + + return null; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlank.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlank.java new file mode 100644 index 0000000..c94212e --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlank.java @@ -0,0 +1,15 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.gui.book.element.BookElement; + +@SideOnly(Side.CLIENT) +public class ContentBlank extends PageContent { + + @Override + public void build(BookData book, ArrayList list) { + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlockInteraction.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlockInteraction.java new file mode 100644 index 0000000..ffa880a --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentBlockInteraction.java @@ -0,0 +1,57 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementItem; +import slimeknights.mantle.client.gui.book.element.ElementText; +import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC; + +public class ContentBlockInteraction extends PageContent { + + public static final transient int TEX_SIZE = 512; + public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 0, 0, 88, 55, TEX_SIZE, TEX_SIZE); + + public static final transient int INPUT_X = 6; + public static final transient int INPUT_Y = 18; + public static final transient int BLOCK_X = 40; + public static final transient int BLOCK_Y = 26; + + public static final transient float ITEM_SCALE = 2.0F; + public static final transient float BLOCK_SCALE = 5.0F; + + public String title = "Block Interaction"; + public ItemStackData input; + public ItemStackData block; + public TextData[] description; + + @Override + public void build(BookData book, ArrayList list) { + int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2 - 10; + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor)); + + if (input != null && !input.id.equals("")) { + list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); + } + + if (block != null && !block.id.equals("")) { + list.add(new ElementItem(x + BLOCK_X, y + BLOCK_Y, BLOCK_SCALE, block.getItems(), block.action)); + } + + if (description != null && description.length > 0) { + list.add(new ElementText(0, IMG_SMITHING.height + y + 50, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 50, description)); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentCrafting.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentCrafting.java new file mode 100644 index 0000000..549915f --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentCrafting.java @@ -0,0 +1,79 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementItem; +import slimeknights.mantle.client.gui.book.element.ElementText; +import static slimeknights.mantle.client.gui.book.Textures.TEX_CRAFTING; + +public class ContentCrafting extends PageContent { + + public static final transient int TEX_SIZE = 256; + public static final transient ImageData IMG_CRAFTING_LARGE = new ImageData(TEX_CRAFTING, 0, 0, 183, 114, TEX_SIZE, TEX_SIZE); + public static final transient ImageData IMG_CRAFTING_SMALL = new ImageData(TEX_CRAFTING, 0, 114, 155, 78, TEX_SIZE, TEX_SIZE); + + public static final transient int X_RESULT_SMALL = 118; + public static final transient int Y_RESULT_SMALL = 23; + public static final transient int X_RESULT_LARGE = 146; + public static final transient int Y_RESULT_LARGE = 41; + + public static final transient float ITEM_SCALE = 2.0F; + public static final transient int SLOT_MARGIN = 5; + public static final transient int SLOT_PADDING = 4; + + public String title = "Crafting"; + public String grid_size = "large"; + public ItemStackData[][] grid; + public ItemStackData result; + public TextData[] description; + + @Override + public void build(BookData book, ArrayList list) { + int x = 0; + int y = 16; + int height = 100; + int resultX = 100; + int resultY = 50; + + TextData tdTitle = new TextData(title); + tdTitle.underlined = true; + list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle})); + + if (grid_size.equalsIgnoreCase("small")) { + x = GuiBook.PAGE_WIDTH / 2 - IMG_CRAFTING_SMALL.width / 2; + height = y + IMG_CRAFTING_SMALL.height; + list.add(new ElementImage(x, y, IMG_CRAFTING_SMALL.width, IMG_CRAFTING_SMALL.height, IMG_CRAFTING_SMALL, book.appearance.coverColor)); + resultX = x + X_RESULT_SMALL; + resultY = y + Y_RESULT_SMALL; + } else if (grid_size.equalsIgnoreCase("large")) { + x = GuiBook.PAGE_WIDTH / 2 - IMG_CRAFTING_LARGE.width / 2; + height = y + IMG_CRAFTING_LARGE.height; + list.add(new ElementImage(x, y, IMG_CRAFTING_LARGE.width, IMG_CRAFTING_LARGE.height, IMG_CRAFTING_LARGE, book.appearance.coverColor)); + resultX = x + X_RESULT_LARGE; + resultY = y + Y_RESULT_LARGE; + } + + if (grid != null) + for (int i = 0; i < grid.length; i++) { + for (int j = 0; j < grid[i].length; j++) { + if (grid[i][j].id.equals("")) + continue; + list.add(new ElementItem(x + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * j, y + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * i, ITEM_SCALE, grid[i][j].getItems(), grid[i][j].action)); + } + } + + if (result != null) { + list.add(new ElementItem(resultX, resultY, ITEM_SCALE, result.getItems(), result.action)); + } + + if (description != null && description.length > 0) { + list.add(new ElementText(0, height + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - height - 5, description)); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentDummy.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentDummy.java new file mode 100644 index 0000000..c26e58a --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentDummy.java @@ -0,0 +1,16 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.gui.book.element.BookElement; + +@SideOnly(Side.CLIENT) +public class ContentDummy extends PageContent { + + @Override + public void build(BookData book, ArrayList list) { + //TODO load from JSON + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentError.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentError.java new file mode 100644 index 0000000..0fb9d04 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentError.java @@ -0,0 +1,48 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentError extends PageContent { + + private String errorStage; + private Exception exception; + + public ContentError(String errorStage) { + this.errorStage = errorStage; + } + + public ContentError(String errorStage, Exception e) { + this(errorStage); + this.exception = e; + } + + @Override + public void build(BookData book, ArrayList list) { + addTitle(list, "Error"); + + TextData[] text = new TextData[1 + (exception != null ? 2 : 0)]; + text[0] = new TextData(errorStage); + text[0].color = "dark_red"; + text[0].underlined = true; + + if (exception != null) { + text[1] = new TextData("The following error has occured: "); + text[1].color = "dark_red"; + text[1].paragraph = true; + + text[2] = new TextData(exception.getMessage() != null ? exception.getMessage() : exception.getClass().getSimpleName()); + text[2].color = "dark_red"; + text[2].paragraph = true; + } + + list.add(new ElementText(0, TITLE_HEIGHT, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - TITLE_HEIGHT, text)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentImage.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentImage.java new file mode 100644 index 0000000..4e770f3 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentImage.java @@ -0,0 +1,32 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; + +@SideOnly(Side.CLIENT) +public class ContentImage extends PageContent { + + public String title = null; + public ImageData image; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (image != null && image.location != null) + list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, image)); + else + list.add(new ElementImage(ImageData.MISSING)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentImageText.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentImageText.java new file mode 100644 index 0000000..f3d8865 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentImageText.java @@ -0,0 +1,38 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentImageText extends PageContent { + + public String title = null; + public ImageData image; + public TextData[] text; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (image != null && image.location != null) + list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, 100, image)); + else + list.add(new ElementImage(0, y, 32, 32, ImageData.MISSING)); + + if (text != null && text.length > 0) + list.add(new ElementText(0, y + 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105 - y, text)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentSectionList.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSectionList.java new file mode 100644 index 0000000..bdc7792 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSectionList.java @@ -0,0 +1,32 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.SectionData; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementSection; + +public class ContentSectionList extends PageContent { + + protected ArrayList sections = new ArrayList<>(); + + public boolean addSection(SectionData data) { + return sections.size() < 9 && sections.add(data); + } + + @Override + public void build(BookData book, ArrayList list) { + int width = (ElementSection.WIDTH + 5) * 3 - 5; + int height = (ElementSection.HEIGHT + 5) * 3 - 5; + + for (int i = 0; i < sections.size(); i++) { + int ix = i % 3; + int iy = (int) Math.floor(i / 3F); + + int x = ix * (ElementSection.WIDTH + 5); + int y = iy * (ElementSection.HEIGHT + 5); + + list.add(new ElementSection(x, y, sections.get(i))); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmelting.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmelting.java new file mode 100644 index 0000000..c0d1494 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmelting.java @@ -0,0 +1,82 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementItem; +import slimeknights.mantle.client.gui.book.element.ElementText; +import static slimeknights.mantle.client.gui.book.Textures.TEX_SMELTING; + +public class ContentSmelting extends PageContent { + + public static final transient int TEX_SIZE = 128; + public static final transient ImageData IMG_SMELTING = new ImageData(TEX_SMELTING, 0, 0, 110, 114, TEX_SIZE, TEX_SIZE); + + public static final transient int INPUT_X = 5; + public static final transient int INPUT_Y = 5; + public static final transient int RESULT_X = 74; + public static final transient int RESULT_Y = 41; + public static final transient int FUEL_X = 5; + public static final transient int FUEL_Y = 77; + + public static final transient float ITEM_SCALE = 2.0F; + + public String title = "Smelting"; + public ItemStackData input; + public ItemStackData result; + public TextData[] description; + + @Override + public void build(BookData book, ArrayList list) { + int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMELTING.width / 2; + int y = TITLE_HEIGHT; + + TextData tdTitle = new TextData(title); + tdTitle.underlined = true; + list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle})); + list.add(new ElementImage(x, y, IMG_SMELTING.width, IMG_SMELTING.height, IMG_SMELTING, book.appearance.coverColor)); + + if (input != null && !input.id.equals("")) { + list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); + } + + if (result != null && !result.id.equals("")) { + list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action)); + } + + list.add(new ElementItem(x + FUEL_X, y + FUEL_Y, ITEM_SCALE, getFuelsList())); + + if (description != null && description.length > 0) { + list.add(new ElementText(0, IMG_SMELTING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y - 5, description)); + } + } + + public ItemStack[] getFuelsList() { + //TODO ask JEI for fuel list if it is present + + ItemStack[] fuels = new ItemStack[13]; + fuels[0] = new ItemStack(Blocks.wooden_slab); + fuels[1] = new ItemStack(Blocks.planks); + fuels[2] = new ItemStack(Blocks.coal_block); + fuels[3] = new ItemStack(Items.wooden_pickaxe); + fuels[4] = new ItemStack(Items.wooden_sword); + fuels[5] = new ItemStack(Items.wooden_hoe); + fuels[6] = new ItemStack(Items.stick); + fuels[7] = new ItemStack(Items.coal); + fuels[8] = new ItemStack(Items.lava_bucket); + fuels[9] = new ItemStack(Blocks.sapling); + fuels[10] = new ItemStack(Items.blaze_rod); + fuels[11] = new ItemStack(Items.wooden_shovel); + fuels[12] = new ItemStack(Items.wooden_axe); + + return fuels; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmithing.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmithing.java new file mode 100644 index 0000000..faf8ea6 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentSmithing.java @@ -0,0 +1,63 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementItem; +import slimeknights.mantle.client.gui.book.element.ElementText; +import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC; + +public class ContentSmithing extends PageContent { + + public static final transient int TEX_SIZE = 512; + public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 88, 0, 210, 42, TEX_SIZE, TEX_SIZE); + + public static final transient int INPUT_X = 5; + public static final transient int INPUT_Y = 5; + public static final transient int MODIFIER_X = 89; + public static final transient int MODIFIER_Y = 5; + public static final transient int RESULT_X = 173; + public static final transient int RESULT_Y = 5; + + public static final transient float ITEM_SCALE = 2.0F; + + public String title = "Smithing"; + public ItemStackData input; + public ItemStackData modifier; + public ItemStackData result; + public TextData[] description; + + @Override + public void build(BookData book, ArrayList list) { + int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2; + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor)); + + if (input != null && !input.id.equals("")) { + list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action)); + } + + if (modifier != null && !modifier.id.equals("")) { + list.add(new ElementItem(x + MODIFIER_X, y + MODIFIER_Y, ITEM_SCALE, modifier.getItems(), modifier.action)); + } + + if (result != null && !result.id.equals("")) { + list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action)); + } + + if (description != null && description.length > 0) { + list.add(new ElementText(0, IMG_SMITHING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 5, description)); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentStructure.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentStructure.java new file mode 100644 index 0000000..d4f7065 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentStructure.java @@ -0,0 +1,53 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraft.util.ResourceLocation; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.BlockData; +import slimeknights.mantle.client.book.repository.BookRepository; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementStructure; +import slimeknights.mantle.client.gui.book.element.ElementText; + +public class ContentStructure extends PageContent { + + public String title; + public String data; + + public int[] size; + public BlockData[] structure; + + @Override + public void load() { + BookRepository repo = parent.source; + + if (data == null || data.isEmpty()) + return; + + ResourceLocation location = repo.getResourceLocation(data); + + if (location != null && repo.resourceExists(location)) { + ContentStructure structure = BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(location)), ContentStructure.class); + structure.parent = parent; + structure.load(); + size = structure.size; + this.structure = structure.structure; + } + } + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (size != null && size.length == 3 && structure != null && structure.length > 0) + list.add(new ElementStructure(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y - 10, size, structure)); + + list.add(new ElementText(0, GuiBook.PAGE_HEIGHT - 10, GuiBook.PAGE_WIDTH, 10, "WIP - Not Yet Implemented")); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentTableOfContents.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTableOfContents.java new file mode 100644 index 0000000..bcea5b4 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTableOfContents.java @@ -0,0 +1,35 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementText; + +public class ContentTableOfContents extends PageContent { + + public String title; + public TextData[] data; + + public ContentTableOfContents(String title, TextData... contents) { + this.title = title; + data = contents; + } + + @Override + public void build(BookData book, ArrayList list) { + int y = 0; + + if (title != null && !title.trim().isEmpty()) { + addTitle(list, title); + y += TITLE_HEIGHT; + } + + for (int i = 0; i < data.length; i++) { + TextData text = data[i]; + list.add(new ElementText(0, y + i * (int) (Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT * text.scale), GuiBook.PAGE_WIDTH, Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, new TextData[]{text})); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentText.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentText.java new file mode 100644 index 0000000..60ea086 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentText.java @@ -0,0 +1,30 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentText extends PageContent { + + public String title = null; + public TextData[] text; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (text != null && text.length > 0) + list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, text)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextImage.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextImage.java new file mode 100644 index 0000000..3430ced --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextImage.java @@ -0,0 +1,43 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentTextImage extends PageContent { + + public String title = null; + public TextData[] text; + public ImageData image; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (text != null && text.length > 0) + list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text)); + + if (image != null && image.location != null) + list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, image)); + else + list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, ImageData.MISSING)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextLeftImage.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextLeftImage.java new file mode 100644 index 0000000..8bf5776 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextLeftImage.java @@ -0,0 +1,42 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentTextLeftImage extends PageContent { + + public String title = null; + public ImageData image; + public TextData[] text1; + public TextData[] text2; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (image != null && image.location != null) + list.add(new ElementImage(0, y, 50, 50, image)); + else + list.add(new ElementImage(0, y, 50, 50, ImageData.MISSING)); + + if (text1 != null && text1.length > 0) + list.add(new ElementText(55, y, GuiBook.PAGE_WIDTH - 55, 50, text1)); + + if (text2 != null && text2.length > 0) + list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextRightImage.java b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextRightImage.java new file mode 100644 index 0000000..7a93199 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/ContentTextRightImage.java @@ -0,0 +1,42 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.element.ImageData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementImage; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public class ContentTextRightImage extends PageContent { + + public String title; + public TextData[] text1; + public TextData[] text2; + public ImageData image; + + @Override + public void build(BookData book, ArrayList list) { + int y = TITLE_HEIGHT; + + if (title == null || title.isEmpty()) + y = 0; + else + addTitle(list, title); + + if (text1 != null && text1.length > 0) + list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH - 55, 50, text1)); + + if (image != null && image.location != null) + list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, image)); + else + list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, ImageData.MISSING)); + + if (text2 != null && text2.length > 0) + list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/content/PageContent.java b/src/main/java/slimeknights/mantle/client/book/data/content/PageContent.java new file mode 100644 index 0000000..efe64da --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/content/PageContent.java @@ -0,0 +1,36 @@ +package slimeknights.mantle.client.book.data.content; + +import java.util.ArrayList; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.PageData; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.book.repository.BookRepository; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.element.BookElement; +import slimeknights.mantle.client.gui.book.element.ElementText; + +@SideOnly(Side.CLIENT) +public abstract class PageContent { + + public static final transient int TITLE_HEIGHT = 16; + + public transient PageData parent; + public transient BookRepository source; + + public void load() { + } + + public abstract void build(BookData book, ArrayList list); + + public void addTitle(ArrayList list, String title) { + TextData tdTitle = new TextData(title); + tdTitle.underlined = true; + addTitle(list, new TextData[]{tdTitle}); + } + + public void addTitle(ArrayList list, TextData[] title) { + list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, title)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/deserializer/HexStringDeserializer.java b/src/main/java/slimeknights/mantle/client/book/data/deserializer/HexStringDeserializer.java new file mode 100644 index 0000000..acc928b --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/deserializer/HexStringDeserializer.java @@ -0,0 +1,29 @@ +package slimeknights.mantle.client.book.data.deserializer; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import java.lang.reflect.Type; + +public class HexStringDeserializer implements JsonDeserializer { + + @Override + public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber()) + return json.getAsInt(); + else if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) { + try { + String s = json.getAsString(); + + if (s.toLowerCase().startsWith("0b")) + return Integer.parseInt(s.substring(2), 2); + else if (s.toLowerCase().startsWith("0x")) + return Integer.parseInt(s.substring(2), 16); + } catch (NumberFormatException ignored) { + } + } + + return null; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/element/BlockData.java b/src/main/java/slimeknights/mantle/client/book/data/element/BlockData.java new file mode 100644 index 0000000..c6feb15 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/element/BlockData.java @@ -0,0 +1,12 @@ +package slimeknights.mantle.client.book.data.element; + +import com.google.gson.JsonObject; + +public class BlockData { + + public int[] pos; + public int[] endPos; + public String block; + public byte meta; + public JsonObject nbt; +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/element/DataLocation.java b/src/main/java/slimeknights/mantle/client/book/data/element/DataLocation.java new file mode 100644 index 0000000..c2ed7ea --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/element/DataLocation.java @@ -0,0 +1,9 @@ +package slimeknights.mantle.client.book.data.element; + +import net.minecraft.util.ResourceLocation; + +public class DataLocation { + + public String file; + public transient ResourceLocation location; +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/element/ImageData.java b/src/main/java/slimeknights/mantle/client/book/data/element/ImageData.java new file mode 100644 index 0000000..4ca924e --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/element/ImageData.java @@ -0,0 +1,59 @@ +package slimeknights.mantle.client.book.data.element; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class ImageData extends DataLocation { + + public static final ImageData MISSING = new ImageData(); + + public int u = 0; + public int v = 0; + public int uw = 256; + public int vh = 256; + public int texWidth = 256; + public int texHeight = 256; + public int x = -1; + public int y = -1; + public int width = -1; + public int height = -1; + public int colorMultiplier = 0xFFFFFF; + + public ImageData() { + } + + public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight) { + this(location, u, v, uw, vh, texWidth, texHeight, uw, vh, 0xFFFFFF); + } + + public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int colorMultiplier) { + this(location, u, v, uw, vh, texWidth, texHeight, uw, vh); + } + + public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int width, int height) { + this(location, u, v, uw, vh, texWidth, texHeight, width, height, 0xFFFFFF); + } + + public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int width, int height, int colorMultiplier) { + this.location = location; + this.u = u; + this.v = v; + this.uw = uw; + this.vh = vh; + this.texWidth = texWidth; + this.texHeight = texHeight; + this.width = width; + this.height = height; + this.colorMultiplier = colorMultiplier; + } + + static { + MISSING.location = new ResourceLocation("mantle:textures/gui/missingno.png"); + MISSING.texWidth = 32; + MISSING.texHeight = 32; + MISSING.uw = 32; + MISSING.vh = 32; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/element/ItemStackData.java b/src/main/java/slimeknights/mantle/client/book/data/element/ItemStackData.java new file mode 100644 index 0000000..f191ba2 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/element/ItemStackData.java @@ -0,0 +1,118 @@ +package slimeknights.mantle.client.book.data.element; + +import com.google.gson.JsonObject; +import net.minecraft.command.CommandGive; +import net.minecraft.command.NumberInvalidException; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.ResourceLocation; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.repository.BookRepository; + +public class ItemStackData { + + public String itemList = null; + public transient BookRepository source; + public transient ResourceLocation itemListLocation = null; + public transient String action; + + public String id = ""; + public byte amount = 1; + public short damage = 0; + public JsonObject nbt; + + public ItemStack[] getItems() { + if (itemListLocation != null && source.resourceExists(itemListLocation)) { + try { + ItemsList itemsList = BookLoader.GSON.fromJson(source.resourceToString(source.getResource(itemListLocation)), ItemsList.class); + ItemStack[] items = new ItemStack[itemsList.items.length]; + + for (int i = 0; i < itemsList.items.length; i++) { + items[i] = itemsList.items[i].getItem(); + } + + this.action = itemsList.action; + + return items; + } catch (Exception ignored) { + } + } + + return new ItemStack[]{getItem()}; + } + + private ItemStack getItem() { + Item item; + boolean isMissingItem = false; + try { + item = CommandGive.getItemByText(null, id); + } catch (NumberInvalidException e) { + item = Item.getItemFromBlock(Blocks.barrier); + isMissingItem = true; + } + + if (item == null) { + item = Item.getItemFromBlock(Blocks.barrier); + isMissingItem = true; + } + + ItemStack itemStack = new ItemStack(item, amount, damage); + + if (nbt != null) { + try { + itemStack.setTagCompound(JsonToNBT.getTagFromJson(filterJsonQuotes(nbt.toString()))); + } catch (NBTException ignored) { + } + } + + if (isMissingItem) { + NBTTagCompound display = itemStack.getSubCompound("display", true); + display.setString("Name", "\u00A7rUnknown Item"); + NBTTagList lore = new NBTTagList(); + lore.appendTag(new NBTTagString("\u00A7r\u00A7eItem Name:")); + lore.appendTag(new NBTTagString("\u00A7r\u00A7e" + id)); + display.setTag("Lore", lore); + } + + return itemStack; + } + + public static ItemStackData getItemStackData(ItemStack stack) { + return getItemStackData(stack, false); + } + + public static ItemStackData getItemStackData(ItemStack stack, boolean ignoreNbt) { + ItemStackData data = new ItemStackData(); + data.id = Item.itemRegistry.getNameForObject(stack.getItem()).toString(); + data.amount = (byte) stack.stackSize; + data.damage = (short) stack.getItemDamage(); + if (!ignoreNbt && stack.getTagCompound() != null) { + data.nbt = BookLoader.GSON.toJsonTree(stack.getTagCompound(), NBTTagCompound.class).getAsJsonObject(); + } + + return data; + } + + public static String filterJsonQuotes(String s) { + return s.replaceAll("\"(\\w+)\"\\s*:", "$1: "); + } + + private static class ItemsList { + + public ItemStackData[] items = new ItemStackData[0]; + public String action; + } + + public static class ItemLink { + + public ItemStackData item = new ItemStackData(); + public boolean damageSensitive = false; + public String action = ""; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/data/element/TextData.java b/src/main/java/slimeknights/mantle/client/book/data/element/TextData.java new file mode 100644 index 0000000..96000b4 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/data/element/TextData.java @@ -0,0 +1,28 @@ +package slimeknights.mantle.client.book.data.element; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + + +@SideOnly(Side.CLIENT) +public class TextData { + + public String text; + public String color = "black"; + public boolean bold = false; + public boolean italic = false; + public boolean underlined = false; + public boolean strikethrough = false; + public boolean obfuscated = false; + public boolean paragraph = false; + public float scale = 1.F; + public String action = ""; + public String[] tooltip = null; + + public TextData() { + } + + public TextData(String text) { + this.text = text; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/repository/BookRepository.java b/src/main/java/slimeknights/mantle/client/book/repository/BookRepository.java new file mode 100644 index 0000000..d4667b6 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/repository/BookRepository.java @@ -0,0 +1,33 @@ +package slimeknights.mantle.client.book.repository; + +import java.util.List; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; +import slimeknights.mantle.client.book.data.SectionData; + +public abstract class BookRepository { + + public static final BookRepository DUMMY = new DummyRepository(); + + public abstract List getSections(); + + public ResourceLocation getResourceLocation(String path) { + return getResourceLocation(path, false); + } + + public abstract ResourceLocation getResourceLocation(String path, boolean safe); + + public abstract IResource getResource(ResourceLocation loc); + + public boolean resourceExists(String location) { + return resourceExists(new ResourceLocation(location)); + } + + public abstract boolean resourceExists(ResourceLocation location); + + public String resourceToString(IResource resource) { + return resourceToString(resource, true); + } + + public abstract String resourceToString(IResource resource, boolean skipCommments); +} diff --git a/src/main/java/slimeknights/mantle/client/book/repository/DummyRepository.java b/src/main/java/slimeknights/mantle/client/book/repository/DummyRepository.java new file mode 100644 index 0000000..3eb5d2e --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/repository/DummyRepository.java @@ -0,0 +1,34 @@ +package slimeknights.mantle.client.book.repository; + +import java.util.List; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; +import slimeknights.mantle.client.book.data.SectionData; + +public class DummyRepository extends BookRepository { + + @Override + public List getSections() { + return null; + } + + @Override + public ResourceLocation getResourceLocation(String path, boolean safe) { + return null; + } + + @Override + public IResource getResource(ResourceLocation loc) { + return null; + } + + @Override + public boolean resourceExists(ResourceLocation location) { + return false; + } + + @Override + public String resourceToString(IResource resource, boolean skipCommments) { + return null; + } +} diff --git a/src/main/java/slimeknights/mantle/client/book/repository/FileRepository.java b/src/main/java/slimeknights/mantle/client/book/repository/FileRepository.java new file mode 100644 index 0000000..0ae0edf --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/book/repository/FileRepository.java @@ -0,0 +1,117 @@ +package slimeknights.mantle.client.book.repository; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.IResource; +import net.minecraft.util.ResourceLocation; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.data.SectionData; + +public class FileRepository extends BookRepository { + + public final String location; + + public FileRepository(String location) { + this.location = location; + } + + @Override + public List getSections() { + return new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(resourceToString(getResource(getResourceLocation("index.json"))), SectionData[].class))); + } + + @Override + public ResourceLocation getResourceLocation(String path, boolean safe) { + if (path == null) + return safe ? new ResourceLocation("") : null; + if (!path.contains(":")) { + String langPath = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode(); + String defaultLangPath = "en_US"; + + ResourceLocation res = new ResourceLocation(location + "/" + langPath + "/" + path); + if (resourceExists(res)) + return res; + res = new ResourceLocation(location + "/" + defaultLangPath + "/" + path); + if (resourceExists(res)) + return res; + res = new ResourceLocation(location + "/" + path); + if (resourceExists(res)) + return res; + return safe ? new ResourceLocation("") : null; + } else { + ResourceLocation res = new ResourceLocation(path); + if (resourceExists(res)) + return res; + return safe ? new ResourceLocation("") : null; + } + } + + @Override + public IResource getResource(ResourceLocation loc) { + if (loc == null) + return null; + try { + return Minecraft.getMinecraft().getResourceManager().getResource(loc); + } catch (IOException e) { + return null; + } + } + + @Override + public boolean resourceExists(ResourceLocation location) { + if (location == null) + return false; + try { + Minecraft.getMinecraft().getResourceManager().getResource(location); + return true; + } catch (IOException e) { + return false; + } + } + + @Override + public String resourceToString(IResource resource, boolean skipCommments) { + if (resource == null) + return ""; + try { + Iterator iterator = IOUtils.readLines(resource.getInputStream(), Charsets.UTF_8).iterator(); + StringBuilder builder = new StringBuilder(); + + boolean isLongComment = false; + + while (iterator.hasNext()) { + String s = ((String) iterator.next()).trim() + "\n"; + + // Comment skipper + if (skipCommments) { + if (isLongComment) { + if (s.endsWith("*/")) + isLongComment = false; + continue; + } else { + if (s.startsWith("/*")) { + isLongComment = true; + continue; + } + } + if (s.startsWith("//")) + continue; + } + + builder.append(s); + } + + return builder.toString().trim(); + } catch (IOException e) { + e.printStackTrace(); + } + + return ""; + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/GuiModule.java b/src/main/java/slimeknights/mantle/client/gui/GuiModule.java index a700f7e..8774dca 100644 --- a/src/main/java/slimeknights/mantle/client/gui/GuiModule.java +++ b/src/main/java/slimeknights/mantle/client/gui/GuiModule.java @@ -6,9 +6,8 @@ import net.minecraft.inventory.Slot; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.awt.Rectangle; +import java.awt.*; import java.io.IOException; -import java.util.List; // a sub-gui. Mostly the same as a separate GuiContainer, but doesn't do the calls that affect the game as if this were the only gui @SideOnly(Side.CLIENT) @@ -79,7 +78,7 @@ public abstract class GuiModule extends GuiContainer { } public boolean isMouseOverFullSlot(int mouseX, int mouseY) { - for(Slot slot : (List)inventorySlots.inventorySlots) { + for(Slot slot : inventorySlots.inventorySlots) { if(parent.isMouseOverSlot(slot, mouseX, mouseY) && slot.getHasStack()) { return true; } diff --git a/src/main/java/slimeknights/mantle/client/gui/GuiMultiModule.java b/src/main/java/slimeknights/mantle/client/gui/GuiMultiModule.java index f328f74..a6249af 100644 --- a/src/main/java/slimeknights/mantle/client/gui/GuiMultiModule.java +++ b/src/main/java/slimeknights/mantle/client/gui/GuiMultiModule.java @@ -7,18 +7,15 @@ import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.awt.Rectangle; +import java.awt.*; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import slimeknights.mantle.Mantle; @@ -61,7 +58,7 @@ public class GuiMultiModule extends GuiContainer { //implements INEIGuiHandler { public List getModuleAreas() { List areas = new ArrayList(modules.size()); - for (GuiModule module : modules) { + for(GuiModule module : modules) { areas.add(module.getArea()); } return areas; @@ -101,7 +98,7 @@ public class GuiMultiModule extends GuiContainer { //implements INEIGuiHandler { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { drawContainerName(); drawPlayerInventoryName(); - + for(GuiModule module : modules) { // set correct state for the module GlStateManager.pushMatrix(); @@ -121,9 +118,9 @@ public class GuiMultiModule extends GuiContainer { //implements INEIGuiHandler { protected void drawContainerName() { ContainerMultiModule multiContainer = (ContainerMultiModule) this.inventorySlots; - IChatComponent localizedName = multiContainer.getInventoryDisplayName(); + String localizedName = multiContainer.getInventoryDisplayName(); if(localizedName != null) { - this.fontRendererObj.drawString(localizedName.getUnformattedText(), 8, 6, 0x404040); + this.fontRendererObj.drawString(localizedName, 8, 6, 0x404040); } } diff --git a/src/main/java/slimeknights/mantle/client/gui/GuiWidgetSlider.java b/src/main/java/slimeknights/mantle/client/gui/GuiWidgetSlider.java index 5078059..9df26bb 100644 --- a/src/main/java/slimeknights/mantle/client/gui/GuiWidgetSlider.java +++ b/src/main/java/slimeknights/mantle/client/gui/GuiWidgetSlider.java @@ -1,6 +1,6 @@ package slimeknights.mantle.client.gui; -import net.minecraft.util.MathHelper; +import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; diff --git a/src/main/java/slimeknights/mantle/client/gui/GuiWidgetTabs.java b/src/main/java/slimeknights/mantle/client/gui/GuiWidgetTabs.java index be8c438..6f28c9c 100644 --- a/src/main/java/slimeknights/mantle/client/gui/GuiWidgetTabs.java +++ b/src/main/java/slimeknights/mantle/client/gui/GuiWidgetTabs.java @@ -5,7 +5,7 @@ import com.google.common.collect.Lists; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.client.renderer.RenderItem; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; diff --git a/src/main/java/slimeknights/mantle/client/gui/book/BoxRenderer.java b/src/main/java/slimeknights/mantle/client/gui/book/BoxRenderer.java new file mode 100644 index 0000000..631ac71 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/BoxRenderer.java @@ -0,0 +1,66 @@ +package slimeknights.mantle.client.gui.book; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.math.MathHelper; + +import static slimeknights.mantle.client.gui.book.Textures.TEX_BOX; + +public class BoxRenderer { + + public static final int TEX_SIZE = 128; + + public static void drawBox(int x, int y, int width, int height, int index) { + drawBox(x, y, width, height, index, 16, 16, 4, 4, 2, 2); + } + + public static void drawBox(int x, int y, int width, int height, int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH) { + Minecraft.getMinecraft().renderEngine.bindTexture(TEX_BOX); + + int sx = x, sy = y; + + for (int i = 0; i < 3; i++) { + int sgW = width - segW * 2; + + if (i % 2 == 0) + sgW = segW; + + for (int j = 0; j < 3; j++) { + int sgH = height - segH * 2; + + if (j % 2 == 0) + sgH = segH; + + int[] matrix = getTextureMatrixCoords(index, sprW, sprH, segW, segH, segGW, segGH, i + j * 3); + Gui.drawScaledCustomSizeModalRect(sx, sy, matrix[0], matrix[1], segW, segH, sgW, sgH, TEX_SIZE, TEX_SIZE); + + sy += sgH; + } + + sx += sgW; + sy = y; + } + } + + public static int[] getTextureMatrixCoords(int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH, int segId) { + int totalWidth = segW * 3 + segGW * 2; + int totalHeight = segH * 3 + segGH * 2; + + return getTextureMatrixCoords((index % (256 / sprW) * sprW) + (sprW / 2 - totalWidth / 2), (MathHelper + .floor_float(index / (256F / sprH)) * sprH) + (sprH / 2 - totalHeight / 2), segW, segH, segGW, segGH, segId); + } + + public static int[] getTextureMatrixCoords(int u, int v, int segW, int segH, int segGW, int segGH, int segId) { + int[] coords = new int[4]; + + int col = segId % 3; + int row = MathHelper.floor_float(segId / 3F); + + coords[0] = u + col * segW + col * segGW; + coords[1] = v + row * segH + row * segGH; + coords[2] = coords[0] + segW; + coords[3] = coords[1] + segH; + + return coords; + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/GuiArrow.java b/src/main/java/slimeknights/mantle/client/gui/book/GuiArrow.java new file mode 100644 index 0000000..15ca069 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/GuiArrow.java @@ -0,0 +1,50 @@ +package slimeknights.mantle.client.gui.book; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK; + +@SideOnly(Side.CLIENT) +public class GuiArrow extends GuiButton { + + private static final int X = 412; + + public static final int WIDTH = 18; + public static final int HEIGHT = 10; + + // Appearance + public int arrowType; + public int color; + public int hoverColor; + + public GuiArrow(int buttonId, int x, int y, int arrowType, int color, int hoverColor) { + super(buttonId, x, y, WIDTH, HEIGHT, ""); + + this.arrowType = arrowType; + this.color = color; + this.hoverColor = hoverColor; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (this.visible) { + mc.getTextureManager().bindTexture(TEX_BOOK); + + this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + + int color = this.hovered ? this.hoverColor : this.color; + + float r = ((color >> 16) & 0xff) / 255.F; + float g = ((color >> 8) & 0xff) / 255.F; + float b = (color & 0xff) / 255.F; + + GlStateManager.color(r, g, b); + Gui.drawScaledCustomSizeModalRect(xPosition, yPosition, X, HEIGHT * arrowType, WIDTH, HEIGHT, width, height, 512, 512); + this.mouseDragged(mc, mouseX, mouseY); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/GuiBook.java b/src/main/java/slimeknights/mantle/client/gui/book/GuiBook.java new file mode 100644 index 0000000..d9ac01e --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/GuiBook.java @@ -0,0 +1,489 @@ +package slimeknights.mantle.client.gui.book; + +import java.io.IOException; +import java.util.ArrayList; +import javax.annotation.Nullable; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.IProgressMeter; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.I18n; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.CPacketClientStatus; +import net.minecraft.stats.StatFileWriter; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import slimeknights.mantle.client.book.BookHelper; +import slimeknights.mantle.client.book.BookLoader; +import slimeknights.mantle.client.book.action.StringActionProcessor; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.book.data.PageData; +import slimeknights.mantle.client.book.data.element.ItemStackData; +import slimeknights.mantle.client.gui.book.element.BookElement; +import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK; +import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOKFRONT; + +@SideOnly(Side.CLIENT) +public class GuiBook extends GuiScreen implements IProgressMeter { + + public static boolean debug = false; + + public static final int TEX_SIZE = 512; + + public static final int PAGE_PADDING = 8; + public static final int PAGE_MARGIN = 18; + + public static final float PAGE_SCALE = 0.5F; + public static final int PAGE_WIDTH_UNSCALED = 206; + public static final int PAGE_HEIGHT_UNSCALED = 200; + + // For best results, make sure both PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 and PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 divide evenly into PAGE_SCALE (without remainder) + public static final int PAGE_WIDTH = (int) ((PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE); + public static final int PAGE_HEIGHT = (int) ((PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE); + + private boolean loadingAchievements = true; + private GuiArrow previousArrow, nextArrow, backArrow, indexArrow; + + public final BookData book; + private ItemStack item; + + private int page = -1; + private int oldPage = -2; + private ArrayList leftElements = new ArrayList<>(); + private ArrayList rightElements = new ArrayList<>(); + + public StatFileWriter statFile; + + public GuiBook(BookData book, StatFileWriter statFile, @Nullable ItemStack item) { + this.book = book; + this.item = item; + + this.statFile = statFile; + } + + public void drawerTransform(boolean rightSide) { + if (rightSide) + GlStateManager.translate(width / 2 + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0); + else + GlStateManager.translate(width / 2 - PAGE_WIDTH_UNSCALED + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0); + + } + + @Override + @SuppressWarnings("ForLoopReplaceableByForEach") + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + FontRenderer font = mc.fontRendererObj; + + if (loadingAchievements) { + this.drawDefaultBackground(); + + this.drawCenteredString(this.fontRendererObj, I18n.format("multiplayer.downloadingStats"), this.width / 2, this.height / 2, 16777215); + this.drawCenteredString(this.fontRendererObj, lanSearchStates[(int) (Minecraft.getSystemTime() / 150L % (long) lanSearchStates.length)], this.width / 2, this.height / 2 + this.fontRendererObj.FONT_HEIGHT * 2, 16777215); + + return; + } + + if (debug) { + drawRect(0, 0, font.getStringWidth("DEBUG") + 4, font.FONT_HEIGHT + 4, 0x55000000); + font.drawString("DEBUG", 2, 2, 0xFFFFFFFF); + } + + GlStateManager.enableAlpha(); + GlStateManager.enableBlend(); + + // The books are unreadable at Gui Scale set to small, so we'll double the scale + if (mc.gameSettings.guiScale == 1) { + GlStateManager.scale(2F, 2F, 2F); + + mouseX /= 2; + mouseY /= 2; + } + + GlStateManager.pushMatrix(); + GlStateManager.color(1F, 1F, 1F); + + float coverR = ((book.appearance.coverColor >> 16) & 0xff) / 255.F; + float coverG = ((book.appearance.coverColor >> 8) & 0xff) / 255.F; + float coverB = (book.appearance.coverColor & 0xff) / 255.F; + + TextureManager render = this.mc.renderEngine; + + if (page == -1) { + render.bindTexture(TEX_BOOKFRONT); + + GlStateManager.color(coverR, coverG, coverB); + drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, 0, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); + GlStateManager.color(1F, 1F, 1F); + + if (!book.appearance.title.isEmpty()) { + drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); + + GlStateManager.pushMatrix(); + + float scale = font.getStringWidth(book.appearance.title) <= 67 ? 2.5F : 2F; + + GlStateManager.scale(scale, scale, 1F); + font.drawString(book.appearance.title, (width / 2) / scale + 3 - font.getStringWidth(book.appearance.title) / 2, (height / 2 - font.FONT_HEIGHT / 2) / scale - 4, 0xAE8000, true); + GlStateManager.popMatrix(); + } + + if (!book.appearance.subtitle.isEmpty()) { + GlStateManager.pushMatrix(); + GlStateManager.scale(1.5F, 1.5F, 1F); + font.drawString(book.appearance.subtitle, (width / 2) / 1.5F + 7 - font.getStringWidth(book.appearance.subtitle) / 2, (height / 2 + 100 - font.FONT_HEIGHT * 2) / 1.5F, 0xAE8000, true); + GlStateManager.popMatrix(); + } + } else { + render.bindTexture(TEX_BOOK); + + GlStateManager.color(coverR, coverG, coverB); + drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, 0, PAGE_WIDTH_UNSCALED * 2, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); + + GlStateManager.color(1F, 1F, 1F); + + if (page != 0) { + drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); + + GlStateManager.pushMatrix(); + drawerTransform(false); + + GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F); + + if (book.appearance.drawPageNumbers) { + String pNum = (page - 1) * 2 + 2 + ""; + font.drawString(pNum, PAGE_WIDTH / 2 - font.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false); + } + + int mX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + int mY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + + // Not foreach to prevent conmodification crashes + for (int i = 0; i < leftElements.size(); i++) { + BookElement element = leftElements.get(i); + + GlStateManager.color(1F, 1F, 1F, 1F); + element.draw(mX, mY, partialTicks); + } + + // Not foreach to prevent conmodification crashes + for (int i = 0; i < leftElements.size(); i++) { + BookElement element = leftElements.get(i); + + GlStateManager.color(1F, 1F, 1F, 1F); + element.drawOverlay(mX, mY, partialTicks); + } + + GlStateManager.popMatrix(); + } + + // Rebind texture as the font renderer binds its own texture + render.bindTexture(TEX_BOOK); + // Set color back to white + GlStateManager.color(1F, 1F, 1F, 1F); + + if ((page < book.getFullPageCount(statFile) - 1 || book.getPageCount(statFile) % 2 != 0) && page < book.getFullPageCount(statFile)) { + drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE); + + GlStateManager.pushMatrix(); + drawerTransform(true); + + GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F); + + if (book.appearance.drawPageNumbers) { + String pNum = (page - 1) * 2 + 3 + ""; + font.drawString(pNum, PAGE_WIDTH / 2 - font.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false); + } + + int mX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + int mY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + + // Not foreach to prevent conmodification crashes + for (int i = 0; i < rightElements.size(); i++) { + BookElement element = rightElements.get(i); + + GlStateManager.color(1F, 1F, 1F, 1F); + element.draw(mX, mY, partialTicks); + } + + // Not foreach to prevent conmodification crashes + for (int i = 0; i < rightElements.size(); i++) { + BookElement element = rightElements.get(i); + + GlStateManager.color(1F, 1F, 1F, 1F); + element.drawOverlay(mX, mY, partialTicks); + } + + GlStateManager.popMatrix(); + } + } + + super.drawScreen(mouseX, mouseY, partialTicks); + + GlStateManager.popMatrix(); + } + + public int openPage(int page) { + return openPage(page, false); + } + + public int openPage(int page, boolean returner) { + if (loadingAchievements) + return -1; + + if (page < 0) + return -1; + + int bookPage; + if (page == 1) + bookPage = 0; + else if (page % 2 == 0) + bookPage = (page - 1) / 2 + 1; + else + bookPage = (page - 2) / 2 + 1; + + if (bookPage >= -1 && bookPage < book.getFullPageCount(statFile)) { + if (returner) + oldPage = this.page; + + _setPage(bookPage); + } + + return page % 2 == 0 ? 0 : 1; + } + + public void _setPage(int page) { + this.page = page; + buildPages(); + } + + public int getPage(int side) { + if (page == 0 && side == 0) + return -1; + else if (page == 0 && side == 1) + return 0; + else if (side == 0) + return (page - 1) * 2 + 1; + else if (side == 1) + return (page - 2) * 2 + 2; + else + return -1; + } + + public int getPage_() { + return page; + } + + public ArrayList getElements(int side) { + return side == 0 ? leftElements : side == 1 ? rightElements : null; + } + + public void openCover() { + if (loadingAchievements) + return; + + _setPage(-1); + + this.leftElements.clear(); + this.rightElements.clear(); + buildPages(); + } + + public void itemClicked(ItemStack item) { + StringActionProcessor.process(book.getItemAction(ItemStackData.getItemStackData(item, true)), this); + } + + private void buildPages() { + if (loadingAchievements) + return; + + leftElements.clear(); + rightElements.clear(); + + if (page == -1) + return; + + if (page == 0) { + PageData page = book.findPage(0, statFile); + + if (page != null) + page.content.build(book, rightElements); + } else { + PageData leftPage = book.findPage((page - 1) * 2 + 1, statFile); + PageData rightPage = book.findPage((page - 1) * 2 + 2, statFile); + + if (leftPage != null) + leftPage.content.build(book, leftElements); + if (rightPage != null) + rightPage.content.build(book, rightElements); + } + + for (BookElement element : leftElements) + element.parent = this; + for (BookElement element : rightElements) + element.parent = this; + } + + @Override + public void initGui() { + super.initGui(); + + if (loadingAchievements) { + this.mc.getNetHandler().addToSendQueue(new CPacketClientStatus(CPacketClientStatus.State.REQUEST_STATS)); + return; + } + + // The books are unreadable at Gui Scale set to small, so we'll double the scale, and of course half the size so that all our code still works as it should + if (mc.gameSettings.guiScale == 1) { + width /= 2F; + height /= 2F; + } + + previousArrow = new GuiArrow(0, -50, -50, 1, book.appearance.arrowColor, book.appearance.arrowColorHover); + nextArrow = new GuiArrow(1, -50, -50, 0, book.appearance.arrowColor, book.appearance.arrowColorHover); + backArrow = new GuiArrow(2, width / 2 - GuiArrow.WIDTH / 2, height / 2 - GuiArrow.HEIGHT / 2 + PAGE_HEIGHT / 3, 3, book.appearance.arrowColor, book.appearance.arrowColorHover); + indexArrow = new GuiArrow(3, width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2 - 3, 3, book.appearance.arrowColor, book.appearance.arrowColorHover); + + buttonList.add(previousArrow); + buttonList.add(nextArrow); + buttonList.add(backArrow); + buttonList.add(indexArrow); + + buildPages(); + } + + @Override + public void updateScreen() { + super.updateScreen(); + + if (loadingAchievements) + return; + + previousArrow.visible = page != -1; + nextArrow.visible = page < book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1); + backArrow.visible = oldPage >= -1; + + if (page == -1) { + nextArrow.xPosition = width / 2 + 80; + indexArrow.visible = false; + } else { + previousArrow.xPosition = width / 2 - 184; + nextArrow.xPosition = width / 2 + 165; + + indexArrow.visible = book.findSection("index") != null && (page - 1) * 2 + 2 > book.findSection("index").getPageCount(); + } + + previousArrow.yPosition = height / 2 + 75; + nextArrow.yPosition = height / 2 + 75; + } + + @Override + public void doneLoading() { + loadingAchievements = false; + + initGui(); + openPage(book.findPageNumber(BookHelper.getSavedPage(item), statFile)); + } + + @Override + public void actionPerformed(GuiButton button) { + if (loadingAchievements) + return; + + if (button instanceof GuiBookmark) { + openPage(book.findPageNumber(((GuiBookmark) button).data.page, statFile)); + + return; + } + + if (button == previousArrow) { + page--; + if (page < -1) + page = -1; + } else if (button == nextArrow) { + page++; + if (page > book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1)) + page = book.getFullPageCount(statFile) - 1; + } else if (button == backArrow) { + if (oldPage >= -1) + page = oldPage; + } else if (button == indexArrow) { + openPage(book.findPageNumber("index.page1")); + } + + oldPage = -2; + buildPages(); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + + if (loadingAchievements) + return; + + switch (keyCode) { + case Keyboard.KEY_LEFT: + case Keyboard.KEY_A: + actionPerformed(previousArrow); + break; + case Keyboard.KEY_RIGHT: + case Keyboard.KEY_D: + actionPerformed(nextArrow); + break; + case Keyboard.KEY_F3: + debug = !debug; + break; + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + if (loadingAchievements) + return; + + super.mouseClicked(mouseX, mouseY, mouseButton); + + boolean right = false; + + mouseX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + mouseY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + + if (mouseX > PAGE_WIDTH + (PAGE_MARGIN + PAGE_PADDING) / PAGE_SCALE) { + mouseX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE); + right = true; + } + + // Not foreach to prevent conmodification crashes + for (int i = 0; right ? i < rightElements.size() : i < leftElements.size(); i++) { + BookElement element = right ? rightElements.get(i) : leftElements.get(i); + + element.mouseClicked(mouseX, mouseY, mouseButton); + } + } + + @Override + public void onGuiClosed() { + if (loadingAchievements) + return; + + PageData page = this.page == 0 ? book.findPage(0, statFile) : book.findPage((this.page - 1) * 2 + 1, statFile); + + if (page == null) + page = book.findPage((this.page - 1) * 2 + 2, statFile); + + if (this.page == -1) + BookLoader.updateSavedPage(mc.thePlayer, item, ""); + else if (page != null && page.parent != null) + BookLoader.updateSavedPage(mc.thePlayer, item, page.parent.name + "." + page.name); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/GuiBookmark.java b/src/main/java/slimeknights/mantle/client/gui/book/GuiBookmark.java new file mode 100644 index 0000000..caa0388 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/GuiBookmark.java @@ -0,0 +1,56 @@ +package slimeknights.mantle.client.gui.book; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; +import slimeknights.mantle.client.book.data.BookmarkData; + +public class GuiBookmark extends GuiButton { + + private static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book.png"); + + public static final int WIDTH = 31; + public static final int HEIGHT = 9; + public static final int TEX_X = 0, TEX_Y = 400; + public static final int ADD_W = 5, ADD_H = 5, ADD_X = 32, ADD_Y = 402; + + public static final float TEXT_SCALE = 0.5F; + + public int type = 0; + + public final BookmarkData data; + + public GuiBookmark(BookmarkData data) { + super(-1337, -500, -500, WIDTH, HEIGHT, ""); + + this.data = data; + } + + @Override + public void drawButton(Minecraft mc, int mouseX, int mouseY) { + if (visible) { + int tex_y = TEX_Y + HEIGHT * type; + + mc.renderEngine.bindTexture(TEX_BOOK); + + float r = ((data.color >> 16) & 0xff) / 255.F; + float g = ((data.color >> 8) & 0xff) / 255.F; + float b = (data.color & 0xff) / 255.F; + + GlStateManager.color(r, g, b); + Gui.drawScaledCustomSizeModalRect(xPosition, yPosition, TEX_X, tex_y, WIDTH, HEIGHT, width, height, 512, 512); + + if (data.text != null && !data.text.isEmpty()) { + TextDataRenderer.drawScaledString(mc.fontRendererObj, data.text, xPosition + 1, yPosition + height / 2 - mc.fontRendererObj.FONT_HEIGHT * TEXT_SCALE / 2 + 1, 0xFFFFFFFF, true, TEXT_SCALE); + } + + GlStateManager.color(1F, 1F, 1F); + + if (data.page.equals("ADD")) { + Gui.drawModalRectWithCustomSizedTexture(xPosition + width / 2 - ADD_W / 2, yPosition + height / 2 - ADD_H / 2, ADD_X, ADD_Y, ADD_W, ADD_H, 512, 512); + } + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/TextDataRenderer.java b/src/main/java/slimeknights/mantle/client/gui/book/TextDataRenderer.java new file mode 100644 index 0000000..2d32ee2 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/TextDataRenderer.java @@ -0,0 +1,268 @@ +package slimeknights.mantle.client.gui.book; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.element.TextData; + +@SideOnly(Side.CLIENT) +public class TextDataRenderer { + + public static String drawText(int x, int y, int boxWidth, int boxHeight, TextData[] data, int mouseX, int mouseY) { + String action = ""; + + String[] drawLabel = null; + + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; + + int atX = x; + int atY = y; + + float prevScale = 1.F; + + for (TextData item : data) { + int box1X, box1Y, box1W = 9999, box1H = y + fr.FONT_HEIGHT; + int box2X, box2Y = 9999, box2W, box2H; + int box3X = 9999, box3Y = 9999, box3W, box3H; + + if (item.text == null || item.text.isEmpty()) + continue; + + if (item.paragraph) { + atX = x; + atY += fr.FONT_HEIGHT * 2 * prevScale; + } + + prevScale = item.scale; + + String modifiers = ""; + + modifiers += TextFormatting.getValueByName(item.color); + + if (item.bold) + modifiers += TextFormatting.BOLD; + if (item.italic) + modifiers += TextFormatting.ITALIC; + if (item.underlined) + modifiers += TextFormatting.UNDERLINE; + if (item.strikethrough) + modifiers += TextFormatting.STRIKETHROUGH; + if (item.obfuscated) + modifiers += TextFormatting.OBFUSCATED; + + String[] split = cropStringBySize(item.text, modifiers, boxWidth, boxHeight - (atY - y), boxWidth - (atX - x), fr, item.scale); + + box1X = atX; + box1Y = atY; + box2X = x; + box2W = x + boxWidth; + + for (int i = 0; i < split.length; i++) { + if (i == split.length - 1) { + box3X = atX; + box3Y = atY; + } + + String s = split[i]; + drawScaledString(fr, modifiers + s, atX, atY, 0, false, item.scale); + + if (i < split.length - 1) { + atY += fr.FONT_HEIGHT; + atX = x; + } + + if (i == 0) { + box2Y = atY; + + if (atX == x) + box1W = x + boxWidth; + else + box1W = atX; + } + } + + box2H = atY; + + atX += fr.getStringWidth(split[split.length - 1]) * item.scale; + if (atX - x >= boxWidth) { + atX = x; + atY += fr.FONT_HEIGHT * item.scale; + } + + box3W = atX; + box3H = (int) (atY + fr.FONT_HEIGHT * item.scale); + + if (item.tooltip != null && item.tooltip.length > 0) { + // Uncomment to render bounding boxes for event handling + /*drawGradientRect(box1X, box1Y, box1W, box1H, 0xFF00FF00, 0xFF00FF00); + drawGradientRect(box2X, box2Y, box2W, box2H, 0xFFFF0000, 0xFFFF0000); + drawGradientRect(box3X, box3Y, box3W, box3H, 0xFF0000FF, 0xFF0000FF); + drawGradientRect(mouseX, mouseY, mouseX + 5, mouseY + 5, 0xFFFF00FF, 0xFFFFFF00);*/ + + if ((mouseX >= box1X && mouseX <= box1W && mouseY >= box1Y && mouseY <= box1H && box1X != box1W && box1Y != box1H) || (mouseX >= box2X && mouseX <= box2W && mouseY >= box2Y && mouseY <= box2H && box2X != box2W && box2Y != box2H) || (mouseX >= box3X && mouseX <= box3W && mouseY >= box3Y && mouseY <= box3H && box3X != box3W && box1Y != box3H)) { + drawLabel = item.tooltip; + } + } + + if (item.action != null && !item.action.isEmpty()) + if ((mouseX >= box1X && mouseX <= box1W && mouseY >= box1Y && mouseY <= box1H && box1X != box1W && box1Y != box1H) || (mouseX >= box2X && mouseX <= box2W && mouseY >= box2Y && mouseY <= box2H && box2X != box2W && box2Y != box2H) || (mouseX >= box3X && mouseX <= box3W && mouseY >= box3Y && mouseY <= box3H && box3X != box3W && box1Y != box3H)) { + action = item.action; + } + + if (atY >= y + boxHeight) { + fr.drawString("...", atX, atY, 0, false); + break; + } + y = atY; + } + + if (GuiBook.debug && action != null && !action.isEmpty()) { + String[] label = drawLabel; + drawLabel = new String[label != null ? label.length + 2 : 1]; + + if (label != null) + for (int i = 0; i < label.length; i++) + drawLabel[i] = label[i]; + + drawLabel[drawLabel.length > 1 ? drawLabel.length - 2 : 0] = ""; + drawLabel[drawLabel.length - 1] = TextFormatting.GRAY + "Action: " + action; + } + + if (drawLabel != null) { + drawHoveringText(drawLabel, mouseX, mouseY, fr); + } + + return action; + } + + public static String[] cropStringBySize(String s, String modifiers, int width, int height, FontRenderer fr, float scale) { + return cropStringBySize(s, modifiers, width, height, width, fr, scale); + } + + public static String[] cropStringBySize(String s, String modifiers, int width, int height, int firstWidth, FontRenderer fr, float scale) { + int curWidth = 0; + int curHeight = (int) (fr.FONT_HEIGHT * scale); + + for (int i = 0; i < s.length(); i++) { + curWidth += fr.getStringWidth(modifiers + Character.toString(s.charAt(i))) * scale; + + if ((curHeight == (int) (fr.FONT_HEIGHT * scale) && curWidth > firstWidth) || (curHeight != (int) (fr.FONT_HEIGHT * scale) && curWidth > width)) { + int oldI = i; + while (i >= 0 && s.charAt(i) != ' ') + i--; + if (i <= 0) + i = oldI; + + s = s.substring(0, i) + "\r" + s.substring(i + (i == oldI ? 0 : 1)); + + i++; + curWidth = 0; + curHeight += fr.FONT_HEIGHT * scale; + + if (curHeight >= height) + return s.substring(0, i).split("\r"); + } + } + + return s.split("\r"); + } + + //BEGIN METHODS FROM GUI + private static void drawHoveringText(String[] textLines, int x, int y, FontRenderer font) { + if (textLines.length > 0) { + GlStateManager.disableDepth(); + int i = 0; + + for (String s : textLines) { + int j = font.getStringWidth(s); + + if (j > i) { + i = j; + } + } + + int l1 = x + 12; + int i2 = y - 12; + int k = 8; + + if (textLines.length > 1) { + k += 2 + (textLines.length - 1) * 10; + } + + if (l1 + i > GuiBook.PAGE_WIDTH) { + l1 -= 28 + i; + } + + if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) { + i2 = GuiBook.PAGE_HEIGHT - k - 6; + } + + int l = -267386864; + drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, l, l); + drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, l, l); + drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, l, l); + drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, l, l); + drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, l, l); + int i1 = 1347420415; + int j1 = (i1 & 16711422) >> 1 | i1 & -16777216; + drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, i1, j1); + drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, i1, j1); + drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, i1, i1); + drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, j1, j1); + + for (int k1 = 0; k1 < textLines.length; ++k1) { + String s1 = textLines[k1]; + font.drawStringWithShadow(s1, (float) l1, (float) i2, -1); + + if (k1 == 0) { + i2 += 2; + } + + i2 += 10; + } + + GlStateManager.enableDepth(); + } + } + + public static void drawScaledString(FontRenderer font, String text, float x, float y, int color, boolean dropShadow, float scale) { + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, 0); + GlStateManager.scale(scale, scale, 1F); + font.drawString(text, 0, 0, color, dropShadow); + GlStateManager.popMatrix(); + } + + private static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) { + float f = (float) (startColor >> 24 & 255) / 255.0F; + float f1 = (float) (startColor >> 16 & 255) / 255.0F; + float f2 = (float) (startColor >> 8 & 255) / 255.0F; + float f3 = (float) (startColor & 255) / 255.0F; + float f4 = (float) (endColor >> 24 & 255) / 255.0F; + float f5 = (float) (endColor >> 16 & 255) / 255.0F; + float f6 = (float) (endColor >> 8 & 255) / 255.0F; + float f7 = (float) (endColor & 255) / 255.0F; + GlStateManager.disableTexture2D(); + GlStateManager.disableAlpha(); + GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); + GlStateManager.shadeModel(7425); + Tessellator tessellator = Tessellator.getInstance(); + VertexBuffer vertexBuffer = tessellator.getBuffer(); + vertexBuffer.begin(7, DefaultVertexFormats.POSITION_COLOR); + vertexBuffer.pos((double) right, (double) top, 0D).color(f1, f2, f3, f).endVertex(); + vertexBuffer.pos((double) left, (double) top, 0D).color(f1, f2, f3, f).endVertex(); + vertexBuffer.pos((double) left, (double) bottom, 0D).color(f5, f6, f7, f4).endVertex(); + vertexBuffer.pos((double) right, (double) bottom, 0D).color(f5, f6, f7, f4).endVertex(); + tessellator.draw(); + GlStateManager.shadeModel(7424); + GlStateManager.enableAlpha(); + GlStateManager.enableTexture2D(); + } + //END METHODS FROM GUI +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/Textures.java b/src/main/java/slimeknights/mantle/client/gui/book/Textures.java new file mode 100644 index 0000000..4d9059b --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/Textures.java @@ -0,0 +1,15 @@ +package slimeknights.mantle.client.gui.book; + +import net.minecraft.util.ResourceLocation; + +public class Textures { + + public static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book/book.png"); + public static final ResourceLocation TEX_BOOKFRONT = new ResourceLocation("mantle:textures/gui/book/bookfront.png"); + public static final ResourceLocation TEX_BOX = new ResourceLocation("mantle:textures/gui/box.png"); + + public static final ResourceLocation TEX_CRAFTING = new ResourceLocation("mantle:textures/gui/book/crafting.png"); + public static final ResourceLocation TEX_SMELTING = new ResourceLocation("mantle:textures/gui/book/smelting.png"); + public static final ResourceLocation TEX_MISC = new ResourceLocation("mantle:textures/gui/book/misc.png"); + +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/editor/GuiBookEditor.java b/src/main/java/slimeknights/mantle/client/gui/book/editor/GuiBookEditor.java new file mode 100644 index 0000000..0162c31 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/editor/GuiBookEditor.java @@ -0,0 +1,85 @@ +package slimeknights.mantle.client.gui.book.editor; + +import javax.annotation.Nullable; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureManager; +import slimeknights.mantle.client.book.data.BookData; +import slimeknights.mantle.client.gui.book.BoxRenderer; +import slimeknights.mantle.client.gui.book.GuiBook; +import slimeknights.mantle.client.gui.book.Textures; + +public class GuiBookEditor extends GuiScreen { + + private static final int SIDEBAR_WIDTH = 120; + + private GuiBook innerUi; + private int side; + + public GuiBookEditor(@Nullable BookData book) { + if (book == null) + book = new BookData(); + + innerUi = new GuiBook(book, null, null); + innerUi.mc = Minecraft.getMinecraft(); + innerUi.doneLoading(); + + innerUi._setPage(-1); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + GlStateManager.pushMatrix(); + + TextureManager render = this.mc.renderEngine; + + if (mc.gameSettings.guiScale == 1) { + GlStateManager.scale(2F, 2F, 2F); + + mouseX /= 2; + mouseY /= 2; + } + + BoxRenderer.drawBox(width / 2 - (GuiBook.PAGE_WIDTH_UNSCALED + SIDEBAR_WIDTH) / 2, height / 2 - (GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING) / 2, SIDEBAR_WIDTH + GuiBook.PAGE_PADDING + GuiBook.PAGE_MARGIN, GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING, 0); + + if (innerUi.getPage_() == -1) { + GlStateManager.pushMatrix(); + if (mc.gameSettings.guiScale == 1) + GlStateManager.scale(0.5F, 0.5F, 0.5F); + innerUi.openCover(); + innerUi.drawScreen(mouseX * (mc.gameSettings.guiScale == 1 ? 2 : 1), mouseY * (mc.gameSettings.guiScale == 1 ? 2 : 1), partialTicks); + GlStateManager.popMatrix(); + } else { + render.bindTexture(Textures.TEX_BOOK); + + GlStateManager.color(1F, 1F, 1F); + drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2, height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2, 0, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE); + drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2 + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2, GuiBook.PAGE_WIDTH_UNSCALED + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE); + } + + super.drawScreen(mouseX, mouseY, partialTicks); + GlStateManager.popMatrix(); + } + + @Override + public void initGui() { + buttonList.clear(); + + innerUi.width = width + SIDEBAR_WIDTH * (mc.gameSettings.guiScale == 1 ? 2 : 1); + innerUi.height = height; + + if (mc.gameSettings.guiScale == 1) { + width /= 2F; + height /= 2F; + } + + innerUi.initGui(); + innerUi.updateScreen(); + innerUi.buttonList.clear(); + + buttonList.add(new GuiButton(0, 0, height - 20, 50, 20, "Import")); + buttonList.add(new GuiButton(1, 55, height - 20, 50, 20, "Export")); + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/BookElement.java b/src/main/java/slimeknights/mantle/client/gui/book/element/BookElement.java new file mode 100644 index 0000000..aed62cd --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/BookElement.java @@ -0,0 +1,111 @@ +package slimeknights.mantle.client.gui.book.element; + +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.gui.book.GuiBook; + +@SideOnly(Side.CLIENT) +public abstract class BookElement extends Gui { + + public GuiBook parent; + + protected Minecraft mc = Minecraft.getMinecraft(); + protected FontRenderer fontRenderer = mc.fontRendererObj; + protected TextureManager renderEngine = mc.renderEngine; + + public int x, y; + + public BookElement(int x, int y) { + this.x = x; + this.y = y; + } + + public abstract void draw(int mouseX, int mouseY, float partialTicks); + + public void drawOverlay(int mouseX, int mouseY, float partialTicks) { + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + + } + + public void renderToolTip(FontRenderer fontRenderer, ItemStack stack, int x, int y) { + List list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips); + + for (int i = 0; i < list.size(); ++i) { + if (i == 0) { + list.set(i, stack.getRarity().rarityColor + list.get(i)); + } else { + list.set(i, TextFormatting.GRAY + list.get(i)); + } + } + + FontRenderer font = stack.getItem().getFontRenderer(stack); + drawHoveringText(list, x, y, (font == null ? fontRenderer : font)); + } + + public void drawHoveringText(List textLines, int x, int y, FontRenderer font) { + if (!textLines.isEmpty()) { + GlStateManager.disableDepth(); + int i = 0; + + for (String s : textLines) { + int j = font.getStringWidth(s); + + if (j > i) { + i = j; + } + } + + int l1 = x + 12; + int i2 = y - 12; + int k = 8; + + if (textLines.size() > 1) { + k += 2 + (textLines.size() - 1) * 10; + } + + if (l1 + i > GuiBook.PAGE_WIDTH) { + l1 -= 28 + i; + } + + if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) { + i2 = GuiBook.PAGE_HEIGHT - k - 6; + } + + int l = -267386864; + this.drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, l, l); + this.drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, l, l); + this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, l, l); + this.drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, l, l); + this.drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, l, l); + int i1 = 1347420415; + int j1 = (i1 & 16711422) >> 1 | i1 & -16777216; + this.drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, i1, j1); + this.drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, i1, j1); + this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, i1, i1); + this.drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, j1, j1); + + for (int k1 = 0; k1 < textLines.size(); ++k1) { + String s1 = textLines.get(k1); + font.drawStringWithShadow(s1, (float) l1, (float) i2, -1); + + if (k1 == 0) { + i2 += 2; + } + + i2 += 10; + } + + GlStateManager.enableDepth(); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/ElementImage.java b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementImage.java new file mode 100644 index 0000000..673c66a --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementImage.java @@ -0,0 +1,61 @@ +package slimeknights.mantle.client.gui.book.element; + +import net.minecraft.client.renderer.GlStateManager; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.data.element.ImageData; + +@SideOnly(Side.CLIENT) +public class ElementImage extends SizedBookElement { + + public ImageData image; + public int colorMultiplier; + + public ElementImage(ImageData image) { + this(image, 0xFFFFFF); + } + + public ElementImage(ImageData image, int colorMultiplier) { + this(image.x, image.y, image.width, image.height, image, colorMultiplier); + } + + public ElementImage(int x, int y, int width, int height, ImageData image) { + this(x, y, width, height, image, image.colorMultiplier); + } + + public ElementImage(int x, int y, int width, int height, ImageData image, int colorMultiplier) { + super(x, y, width, height); + + this.image = image; + + if (image.x != -1) + x = image.x; + if (image.y != -1) + y = image.y; + if (image.width != -1) + width = image.width; + if (image.height != -1) + height = image.height; + if (image.colorMultiplier != 0xFFFFFF) + colorMultiplier = image.colorMultiplier; + + this.x = x == -1 ? 0 : x; + this.y = y == -1 ? 0 : y; + this.width = width; + this.height = height; + this.colorMultiplier = colorMultiplier; + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + renderEngine.bindTexture(image.location); + + float r = ((colorMultiplier >> 16) & 0xff) / 255.F; + float g = ((colorMultiplier >> 8) & 0xff) / 255.F; + float b = (colorMultiplier & 0xff) / 255.F; + + GlStateManager.color(r, g, b); + + drawScaledCustomSizeModalRect(x, y, image.u, image.v, image.uw, image.vh, width, height, image.texWidth, image.texHeight); + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/ElementItem.java b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementItem.java new file mode 100644 index 0000000..2f769d9 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementItem.java @@ -0,0 +1,88 @@ +package slimeknights.mantle.client.gui.book.element; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.action.StringActionProcessor; + +@SideOnly(Side.CLIENT) +public class ElementItem extends BookElement { + + public static final int ITEM_SIZE_HARDCODED = 16; + public static final int ITEM_SWITCH_TICKS = 90; + + public ItemStack[] itemCycle; + public float scale; + public String action; + + public int renderTick = 0; + public int currentItem = 0; + + public ElementItem(int x, int y, float scale, Item item) { + this(x, y, scale, new ItemStack(item)); + } + + public ElementItem(int x, int y, float scale, Block item) { + this(x, y, scale, new ItemStack(item)); + } + + public ElementItem(int x, int y, float scale, ItemStack item) { + this(x, y, scale, new ItemStack[]{item}); + } + + public ElementItem(int x, int y, float scale, ItemStack[] itemCycle) { + this(x, y, scale, itemCycle, null); + } + + public ElementItem(int x, int y, float scale, ItemStack[] itemCycle, String action) { + super(x, y); + + this.itemCycle = itemCycle; + this.scale = scale; + this.action = action; + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + renderTick++; + + if (renderTick > ITEM_SWITCH_TICKS) { + renderTick = 0; + currentItem++; + + if (currentItem >= itemCycle.length) + currentItem = 0; + } + + RenderHelper.enableGUIStandardItemLighting(); + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, 0); + GlStateManager.scale(scale, scale, 1.0F); + + if (currentItem < itemCycle.length) + mc.getRenderItem().renderItemAndEffectIntoGUI(itemCycle[currentItem], 0, 0); + + GlStateManager.popMatrix(); + } + + @Override + public void drawOverlay(int mouseX, int mouseY, float partialTicks) { + if (mouseX >= x && mouseY >= y && mouseX <= x + ITEM_SIZE_HARDCODED * scale && mouseY <= y + ITEM_SIZE_HARDCODED * scale && currentItem < itemCycle.length) { + renderToolTip(fontRenderer, itemCycle[currentItem], mouseX, mouseY); + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0 && mouseX >= x && mouseY >= y && mouseX <= x + ITEM_SIZE_HARDCODED * scale && mouseY <= y + ITEM_SIZE_HARDCODED * scale && currentItem < itemCycle.length) { + if (action != null) + StringActionProcessor.process(action, parent); + else + parent.itemClicked(itemCycle[currentItem]); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/ElementSection.java b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementSection.java new file mode 100644 index 0000000..a9628b4 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementSection.java @@ -0,0 +1,72 @@ +package slimeknights.mantle.client.gui.book.element; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.stats.Achievement; +import net.minecraft.util.text.TextFormatting; + +import slimeknights.mantle.client.book.data.SectionData; + +public class ElementSection extends BookElement { + + public static final int IMG_SIZE = 64; + + public static final int WIDTH = 85; + public static final int HEIGHT = 85; + + private SectionData section; + + public ElementSection(int x, int y, SectionData section) { + super(x, y); + + this.section = section; + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + boolean unlocked = section.isUnlocked(parent.statFile); + boolean hover = mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT; + + if (section.icon != null) { + renderEngine.bindTexture(section.icon.location); + + if (unlocked) + GlStateManager.color(1F, 1F, 1F, hover ? 1F : 0.5F); + else { + float r = ((parent.book.appearance.lockedSectionColor >> 16) & 0xff) / 255.F; + float g = ((parent.book.appearance.lockedSectionColor >> 8) & 0xff) / 255.F; + float b = (parent.book.appearance.lockedSectionColor & 0xff) / 255.F; + GlStateManager.color(r, g, b, 0.75F); + } + + drawScaledCustomSizeModalRect(x + WIDTH / 2 - IMG_SIZE / 2, y + HEIGHT / 2 - IMG_SIZE / 2, section.icon.u, section.icon.v, section.icon.uw, section.icon.vh, IMG_SIZE, IMG_SIZE, section.icon.texWidth, section.icon.texHeight); + } + + fontRenderer.drawString(section.getTitle(), x + WIDTH / 2 - fontRenderer.getStringWidth(section.getTitle()) / 2, y + HEIGHT - fontRenderer.FONT_HEIGHT, hover ? 0xFF000000 : 0x7F000000); + } + + @Override + public void drawOverlay(int mouseX, int mouseY, float partialTicks) { + if (section != null && !section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT) { + List l = new ArrayList<>(); + l.add(TextFormatting.RED + "Locked"); + l.add("Requirements:"); + + for (String requirement : section.requirements) { + Achievement achievement = SectionData.findAchievement(requirement); + if (achievement != null) + l.add((SectionData.requirementSatisfied(requirement, parent.statFile) ? TextFormatting.GREEN : TextFormatting.RED) + TextFormatting + .getTextWithoutFormattingCodes(achievement.getStatName().getFormattedText())); + } + + drawHoveringText(l, mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj); + } + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0 && section != null && section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT) + parent.openPage(parent.book.getFirstPageNumber(section, parent.statFile)); + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/ElementStructure.java b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementStructure.java new file mode 100644 index 0000000..37a2a57 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementStructure.java @@ -0,0 +1,333 @@ +package slimeknights.mantle.client.gui.book.element; + +import java.util.HashMap; +import java.util.List; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.BlockModelRenderer; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.color.BlockColors; +import net.minecraft.client.renderer.color.ItemColors; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.init.Biomes; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.JsonToNBT; +import net.minecraft.nbt.NBTException; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.WorldType; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.fml.common.registry.GameData; +import net.minecraftforge.fml.common.registry.GameRegistry; + +import org.lwjgl.opengl.GL11; +import slimeknights.mantle.client.book.data.element.BlockData; +import slimeknights.mantle.client.book.data.element.ItemStackData; + +public class ElementStructure extends SizedBookElement { + + private BlockColors blockColors = Minecraft.getMinecraft().getBlockColors(); + private ItemColors itemColors = Minecraft.getMinecraft().getItemColors(); + private BlockAccess world; + private float scale = 50.0F; + private float xTranslate = 0F; + private float yTranslate = 0F; + + private float w = 0F; + private float h = 0F; + + private float rotX = -11.25F; + private float rotY = 45F; + private float rotZ = 0F; + + public ElementStructure(int x, int y, int width, int height, int[] size, BlockData[] structure) { + super(x, y, width, height); + world = new BlockAccess(size, structure); + + if (size.length == 3) { + scale = size[0] > size[1] ? width / size[0] - 10F : height / size[1] - 10F; + + if (scale * size[0] > width) + scale = width / size[0] - 10F; + + xTranslate = x + width / 2 - (size[0] * scale) / 2; + yTranslate = y + height / 2 - (size[1] * scale) / 2; + + w = size[0] * scale; + h = size[1] * scale; + } + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + GlStateManager.pushMatrix(); + + GlStateManager.translate(xTranslate, yTranslate, 500F); + + GlStateManager.cullFace(GlStateManager.CullFace.FRONT); + + // Prepare stencil + GL11.glEnable(GL11.GL_STENCIL_TEST); + GL11.glColorMask(false, false, false, false); + GL11.glDepthMask(false); + GL11.glStencilFunc(GL11.GL_NEVER, 1, 0xFF); + GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP); + + GL11.glStencilMask(0xFF); + GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); + + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex2i(0, 0); + GL11.glVertex2i(0, height); + GL11.glVertex2i(width, height); + GL11.glVertex2i(width, 0); + GL11.glEnd(); + + GL11.glColorMask(true, true, true, true); + GL11.glDepthMask(true); + GL11.glStencilMask(0x00); + GL11.glStencilFunc(GL11.GL_EQUAL, 0, 0xFF); + + GlStateManager.color(0F, 1F, 0F, 1F); + GL11.glBegin(GL11.GL_QUADS); + GL11.glVertex2i(0, 0); + GL11.glVertex2i(0, height); + GL11.glVertex2i(width, height); + GL11.glVertex2i(width, 0); + GL11.glEnd(); + + GlStateManager.translate(w / 2, h / 2, 0); + GlStateManager.rotate(rotX, 1F, 0F, 0F); + GlStateManager.rotate(rotY, 0F, 1F, 0F); + GlStateManager.rotate(rotZ, 0F, 0F, 1F); + GlStateManager.translate(-w / 2, -h / 2, 0); + + for (int x = 0; x < world.getWidth(); x++) { + for (int y = 0; y < world.getHeight(); y++) { + for (int z = 0; z < world.getDepth(); z++) { + BlockPos pos = new BlockPos(x, y, z); + IBlockState state = world.getBlockState(pos); + IBakedModel model = mc.getBlockRendererDispatcher().getModelForState(state); + + Block block = state.getBlock(); + + if (block == Blocks.air) + continue; + + GlStateManager.pushMatrix(); + + GlStateManager.enableDepth(); + mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture); + + if (block == null) + return; + + int color = blockColors.colorMultiplier(state, world, pos, 0); + float red = (color >> 16 & 255) / 255.0F; + float green = (color >> 8 & 255) / 255.0F; + float blue = (color & 255) / 255.0F; + GlStateManager.color(red, green, blue); + + GlStateManager.scale(scale, scale, scale); + + GlStateManager.translate(x, world.getHeight() - y, z); + BlockModelRenderer render = mc.getBlockRendererDispatcher().getBlockModelRenderer(); + + // 1.9 remove this? + //block.setBlockBoundsBasedOnState(world, pos); + int i = blockColors.colorMultiplier(state, world, pos, 0); + GlStateManager.rotate(90F, 0, 1, 0); + + if (EntityRenderer.anaglyphEnable) { + i = TextureUtil.anaglyphColor(i); + } + + float r = (float) (i >> 16 & 255) / 255.0F; + float g = (float) (i >> 8 & 255) / 255.0F; + float b = (float) (i & 255) / 255.0F; + + render.renderModelBrightnessColor(model, blockColors.colorMultiplier(state, world, pos, 0), r, g, b); + + GlStateManager.color(1F, 1F, 1F); + GlStateManager.popMatrix(); + renderEngine.getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap(); + } + } + } + + GlStateManager.disableLighting(); + GlStateManager.cullFace(GlStateManager.CullFace.BACK); + GL11.glDisable(GL11.GL_STENCIL_TEST); + GlStateManager.popMatrix(); + } + + private void setupGuiTransform(int xPosition, int yPosition) { + GlStateManager.translate((float) xPosition, (float) yPosition, 100.0F + this.zLevel); + GlStateManager.translate(8.0F, 8.0F, 0.0F); + GlStateManager.scale(1.0F, 1.0F, -1.0F); + GlStateManager.scale(0.5F, 0.5F, 0.5F); + + GlStateManager.scale(40.0F, 40.0F, 40.0F); + GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.enableLighting(); + } + + private void renderQuads(VertexBuffer renderer, List quads, int color, BlockPos pos) { + boolean flag = color == -1; + int i = 0; + + for (int j = quads.size(); i < j; ++i) { + BakedQuad bakedquad = quads.get(i); + int k = color; + + if (flag && bakedquad.hasTintIndex()) { + Block block = world.getBlockState(pos).getBlock(); + k = blockColors.colorMultiplier(world.getBlockState(pos), world, pos, 0); + + if (EntityRenderer.anaglyphEnable) { + k = TextureUtil.anaglyphColor(k); + } + + k = k | -16777216; + } + + net.minecraftforge.client.model.pipeline.LightUtil.renderQuadColor(renderer, bakedquad, k); + } + } + + private class BlockAccess implements IBlockAccess { + + private final int[][][] blocks; + private final byte[][][] meta; + private final int[] size; + private HashMap tileEntityMap = new HashMap<>(); + + public BlockAccess(int[] size, BlockData[] structure) { + this.size = size; + + blocks = new int[size[0]][size[1]][size[2]]; + meta = new byte[size[0]][size[1]][size[2]]; + + for (BlockData block : structure) { + Block tile = Block.getBlockFromName(block.block); + if (tile == null) + continue; + byte metadata = block.meta >= 0 && block.meta < 16 ? block.meta : 0; + + if (block.pos != null && block.pos.length == 3 && block.endPos != null && block.endPos.length == 3) { + for (int x = block.pos[0]; x <= block.endPos[0]; x++) { + for (int y = block.pos[1]; y <= block.endPos[1]; y++) { + for (int z = block.pos[2]; z <= block.endPos[2]; z++) { + if (x >= size[0] || y >= size[1] || z >= size[2]) + continue; + + blocks[x][y][z] = Block.getIdFromBlock(tile); + meta[x][y][z] = metadata; + + TileEntity te = tile.hasTileEntity(tile.getStateFromMeta(metadata)) ? tile.createTileEntity(Minecraft.getMinecraft().theWorld, tile.getStateFromMeta(metadata)) : null; + if (te != null) { + te.setPos(new BlockPos(x, y, z)); + tileEntityMap.put(new Integer[]{x, y, z}, te); + + if (block.nbt != null) { + try { + te.readFromNBT(JsonToNBT.getTagFromJson(ItemStackData.filterJsonQuotes(block.nbt.toString()))); + } catch (NBTException e) { + e.printStackTrace(); + } + } + } + } + } + } + } + } + } + + @Override + public TileEntity getTileEntity(BlockPos pos) { + if (!isValid(pos)) + return null; + return tileEntityMap.get(new Integer[]{pos.getX(), pos.getY(), pos.getZ()}); + } + + @Override + public int getCombinedLight(BlockPos pos, int lightValue) { + return 15; + } + + @Override + public IBlockState getBlockState(BlockPos pos) { + if (!isValid(pos)) + return Blocks.air.getDefaultState(); + Block block = Block.getBlockById(blocks[pos.getX()][pos.getY()][pos.getZ()]); + if (block == null) + return Blocks.air.getDefaultState(); + + return block.getActualState(block.getStateFromMeta(meta[pos.getX()][pos.getY()][pos.getZ()]), this, pos); + } + + @Override + public boolean isAirBlock(BlockPos pos) { + return !isValid(pos) || Block.getBlockById(blocks[pos.getX()][pos.getY()][pos.getZ()]) == Blocks.air; + } + + @Override + public BiomeGenBase getBiomeGenForCoords(BlockPos pos) { + return Biomes.jungle; + } + + @Override + public boolean extendedLevelsInChunkCache() { + return false; + } + + @Override + public int getStrongPower(BlockPos pos, EnumFacing direction) { + if (!isValid(pos)) + return 0; + + IBlockState iblockstate = this.getBlockState(pos); + return iblockstate.getBlock().getStrongPower(iblockstate, this, pos, direction); + } + + @Override + public WorldType getWorldType() { + return WorldType.DEFAULT; + } + + @Override + public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) { + if (!this.isValid(pos)) + return _default; + + return getBlockState(pos).getBlock().isSideSolid(this.getBlockState(pos), this, pos, side); + } + + public boolean isValid(BlockPos pos) { + return pos != null && pos.getX() < size[0] && pos.getY() < size[1] && pos.getZ() < size[2] && pos.getX() >= 0 && pos.getY() >= 0 && pos.getZ() >= 0; + } + + public int getWidth() { + return size[0]; + } + + public int getHeight() { + return size[1]; + } + + public int getDepth() { + return size[2]; + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/ElementText.java b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementText.java new file mode 100644 index 0000000..0f5fd08 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/ElementText.java @@ -0,0 +1,41 @@ +package slimeknights.mantle.client.gui.book.element; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.book.action.StringActionProcessor; +import slimeknights.mantle.client.book.data.element.TextData; +import slimeknights.mantle.client.gui.book.TextDataRenderer; + +@SideOnly(Side.CLIENT) +public class ElementText extends SizedBookElement { + + public TextData[] text; + + private boolean doAction = false; + + public ElementText(int x, int y, int width, int height, String text) { + this(x, y, width, height, new TextData[]{new TextData(text)}); + } + + public ElementText(int x, int y, int width, int height, TextData[] text) { + super(x, y, width, height); + + this.text = text; + } + + @Override + public void draw(int mouseX, int mouseY, float partialTicks) { + String action = TextDataRenderer.drawText(x, y, width, height, text, mouseX, mouseY); + + if (doAction) { + doAction = false; + StringActionProcessor.process(action, parent); + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0) + doAction = true; + } +} diff --git a/src/main/java/slimeknights/mantle/client/gui/book/element/SizedBookElement.java b/src/main/java/slimeknights/mantle/client/gui/book/element/SizedBookElement.java new file mode 100644 index 0000000..27964ef --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/gui/book/element/SizedBookElement.java @@ -0,0 +1,17 @@ +package slimeknights.mantle.client.gui.book.element; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public abstract class SizedBookElement extends BookElement { + + int width, height; + + public SizedBookElement(int x, int y, int width, int height) { + super(x, y); + + this.width = width; + this.height = height; + } +} diff --git a/src/main/java/slimeknights/mantle/client/model/BakedCompositeModel.java b/src/main/java/slimeknights/mantle/client/model/BakedCompositeModel.java new file mode 100644 index 0000000..0051a12 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/model/BakedCompositeModel.java @@ -0,0 +1,35 @@ +package slimeknights.mantle.client.model; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.util.EnumFacing; + +import java.util.List; + +import slimeknights.mantle.util.ImmutableConcatList; + +public class BakedCompositeModel extends BakedWrapper { + + protected final List parts; + + public BakedCompositeModel(IBakedModel parent, List parts) { + super(parent); + this.parts = parts; + } + + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + ImmutableList.Builder> builder = ImmutableList.builder(); + + builder.add(super.getQuads(state, side, rand)); + + for(IBakedModel part : parts) { + builder.add(part.getQuads(state, side, rand)); + } + + return new ImmutableConcatList(builder.build()); + } +} diff --git a/src/main/java/slimeknights/mantle/client/model/BakedSimple.java b/src/main/java/slimeknights/mantle/client/model/BakedSimple.java new file mode 100644 index 0000000..3d734af --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/model/BakedSimple.java @@ -0,0 +1,118 @@ +package slimeknights.mantle.client.model; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.client.model.IPerspectiveAwareModel; +import net.minecraftforge.common.model.TRSRTransformation; + +import org.apache.commons.lang3.tuple.Pair; + +import java.util.List; + +import javax.vecmath.Matrix4f; + +public class BakedSimple implements IPerspectiveAwareModel { + + private final List quads; + private final ImmutableMap transforms; + private final TextureAtlasSprite particle; + private final boolean ambientOcclusion; + private final boolean isGui3d; + private final ItemOverrideList overrides; + + public BakedSimple(ImmutableList quads, ImmutableMap transforms, IBakedModel base) { + this( + (List)quads, + transforms, + base.getParticleTexture(), + base.isAmbientOcclusion(), + base.isGui3d(), + base.getOverrides() + ); + } + + public BakedSimple(List quads, ImmutableMap transforms, IBakedModel base) { + this( + quads, + transforms, + base.getParticleTexture(), + base.isAmbientOcclusion(), + base.isGui3d(), + base.getOverrides() + ); + } + + public BakedSimple(List quads, ImmutableMap transforms, TextureAtlasSprite particle, boolean ambientOcclusion, boolean isGui3d, ItemOverrideList overrides) { + this.quads = quads; + this.particle = particle; + this.transforms = transforms; + this.ambientOcclusion = ambientOcclusion; + this.isGui3d = isGui3d; + this.overrides = overrides; + } + + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + return quads; + } + + @Override + public boolean isAmbientOcclusion() { + return ambientOcclusion; + } + + @Override + public boolean isGui3d() { + return isGui3d; + } + + @Override + public boolean isBuiltInRenderer() { + return false; + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return particle; + } + + @Override + public ItemCameraTransforms getItemCameraTransforms() { + return ItemCameraTransforms.DEFAULT; + } + + @Override + public ItemOverrideList getOverrides() { + return overrides; + } + + @Override + public Pair handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { + return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, cameraTransformType); + } + + public static class Wrapper extends BakedSimple { + + private final IPerspectiveAwareModel parent; + + public Wrapper(ImmutableList quads, IPerspectiveAwareModel base) { + super(quads, null, base); + + parent = base; + } + + @Override + public Pair handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { + Pair pair = parent.handlePerspective(cameraTransformType); + return Pair.of(this, pair.getRight()); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/model/BakedWrapper.java b/src/main/java/slimeknights/mantle/client/model/BakedWrapper.java new file mode 100644 index 0000000..703ea23 --- /dev/null +++ b/src/main/java/slimeknights/mantle/client/model/BakedWrapper.java @@ -0,0 +1,77 @@ +package slimeknights.mantle.client.model; + +import com.google.common.collect.ImmutableMap; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.client.model.IPerspectiveAwareModel; +import net.minecraftforge.common.model.TRSRTransformation; + +import org.apache.commons.lang3.tuple.Pair; + +import java.util.List; + +import javax.vecmath.Matrix4f; + +public class BakedWrapper implements IBakedModel { + + protected final IBakedModel parent; + + public BakedWrapper(IBakedModel parent) { + this.parent = parent; + } + + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + return parent.getQuads(state, side, rand); + } + + @Override + public boolean isAmbientOcclusion() { + return parent.isAmbientOcclusion(); + } + + @Override + public boolean isGui3d() { + return parent.isGui3d(); + } + + @Override + public boolean isBuiltInRenderer() { + return parent.isBuiltInRenderer(); + } + + @Override + public TextureAtlasSprite getParticleTexture() { + return parent.getParticleTexture(); + } + + @Override + public ItemCameraTransforms getItemCameraTransforms() { + return parent.getItemCameraTransforms(); + } + + @Override + public ItemOverrideList getOverrides() { + return parent.getOverrides(); + } + + public static class Perspective extends BakedWrapper implements IPerspectiveAwareModel { + protected final ImmutableMap transforms; + + public Perspective(IBakedModel parent, ImmutableMap transforms) { + super(parent); + this.transforms = transforms; + } + + @Override + public Pair handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { + return IPerspectiveAwareModel.MapWrapper.handlePerspective(this, transforms, cameraTransformType); + } + } +} diff --git a/src/main/java/slimeknights/mantle/client/model/BlockItemModelWrapper.java b/src/main/java/slimeknights/mantle/client/model/BlockItemModelWrapper.java index 7ec36d9..32f0c3a 100644 --- a/src/main/java/slimeknights/mantle/client/model/BlockItemModelWrapper.java +++ b/src/main/java/slimeknights/mantle/client/model/BlockItemModelWrapper.java @@ -1,64 +1,50 @@ package slimeknights.mantle.client.model; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.client.renderer.vertex.VertexFormat; -import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.util.EnumFacing; -import net.minecraftforge.client.model.IFlexibleBakedModel; import net.minecraftforge.client.model.IPerspectiveAwareModel; -import net.minecraftforge.client.model.TRSRTransformation; import org.apache.commons.lang3.tuple.Pair; import java.util.List; import javax.vecmath.Matrix4f; -import javax.vecmath.Vector3f; + +import slimeknights.mantle.client.ModelHelper; /** * Takes a blockmodel and applies the standard-block-perspective for third_person to it */ -public class BlockItemModelWrapper implements IPerspectiveAwareModel, IFlexibleBakedModel { +public class BlockItemModelWrapper implements IPerspectiveAwareModel, IBakedModel { - // copied from the forge variants V1 default-block transform - public static final Matrix4f THIRD_PERSON_BLOCK_TRANSFORM = new TRSRTransformation( - new Vector3f(0, 1.5f / 16, -2.75f / 16), // translation - TRSRTransformation.quatFromYXZDegrees(new Vector3f(10, -45, 170)), // rotation - new Vector3f(0.375f, 0.375f, 0.375f), // scale - null).getMatrix(); + private final IBakedModel parent; - private final IFlexibleBakedModel parent; - - public BlockItemModelWrapper(IFlexibleBakedModel parent) { + public BlockItemModelWrapper(IBakedModel parent) { this.parent = parent; } @Override - public Pair handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { + public Pair handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) { Matrix4f matrix = null; // fix transformation in hand - if(cameraTransformType == ItemCameraTransforms.TransformType.THIRD_PERSON) { - matrix = THIRD_PERSON_BLOCK_TRANSFORM; + if(cameraTransformType == ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND) { + matrix = ModelHelper.BLOCK_THIRD_PERSON_RIGHT.getMatrix(); + } + else if(cameraTransformType == ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND) { + matrix = ModelHelper.BLOCK_THIRD_PERSON_LEFT.getMatrix(); } return Pair.of(this, matrix); } @Override - public List getFaceQuads(EnumFacing p_177551_1_) { - return parent.getFaceQuads(p_177551_1_); - } - - @Override - public List getGeneralQuads() { - return parent.getGeneralQuads(); - } - - @Override - public VertexFormat getFormat() { - return parent.getFormat(); + public List getQuads(IBlockState state, EnumFacing side, long rand) { + return parent.getQuads(state, side, rand); } @Override @@ -85,4 +71,9 @@ public class BlockItemModelWrapper implements IPerspectiveAwareModel, IFlexibleB public ItemCameraTransforms getItemCameraTransforms() { return parent.getItemCameraTransforms(); } + + @Override + public ItemOverrideList getOverrides() { + return null; + } } diff --git a/src/main/java/slimeknights/mantle/client/model/TRSRBakedModel.java b/src/main/java/slimeknights/mantle/client/model/TRSRBakedModel.java index d92af68..a351719 100644 --- a/src/main/java/slimeknights/mantle/client/model/TRSRBakedModel.java +++ b/src/main/java/slimeknights/mantle/client/model/TRSRBakedModel.java @@ -1,21 +1,24 @@ package slimeknights.mantle.client.model; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.IBakedModel; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.block.model.ItemOverride; +import net.minecraft.client.renderer.block.model.ItemOverrideList; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.client.renderer.vertex.VertexFormatElement; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; -import net.minecraftforge.client.model.IFlexibleBakedModel; -import net.minecraftforge.client.model.TRSRTransformation; +import net.minecraft.world.World; +import net.minecraftforge.common.model.TRSRTransformation; import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; import net.minecraftforge.client.model.pipeline.VertexTransformer; -import java.util.EnumMap; import java.util.List; import javax.vecmath.Matrix3f; @@ -24,71 +27,66 @@ import javax.vecmath.Vector3f; import javax.vecmath.Vector4f; // for those wondering TRSR stands for Translation Rotation Scale Rotation -public class TRSRBakedModel implements IFlexibleBakedModel { +public class TRSRBakedModel implements IBakedModel { - protected final ImmutableList general; - protected final ImmutableMap> faces; - protected final IFlexibleBakedModel original; + protected final IBakedModel original; + protected final TRSRTransformation transformation; + private final TRSROverride override; + private final int faceOffset; - public TRSRBakedModel(IFlexibleBakedModel original, float x, float y, float z, float scale) { + public TRSRBakedModel(IBakedModel original, float x, float y, float z, float scale) { this(original, x, y, z, 0, 0, 0, scale, scale, scale); } - public TRSRBakedModel(IFlexibleBakedModel original, float x, float y, float z, float rotX, float rotY, float rotZ, float scale) { + public TRSRBakedModel(IBakedModel original, float x, float y, float z, float rotX, float rotY, float rotZ, float scale) { this(original, x, y, z, rotX, rotY, rotZ, scale, scale, scale); } - public TRSRBakedModel(IFlexibleBakedModel original, float x, float y, float z, float rotX, float rotY, float rotZ, float scaleX, float scaleY, float scaleZ) { + public TRSRBakedModel(IBakedModel original, float x, float y, float z, float rotX, float rotY, float rotZ, float scaleX, float scaleY, float scaleZ) { this(original, new TRSRTransformation(new Vector3f(x, y, z), null, new Vector3f(scaleX, scaleY, scaleZ), - TRSRTransformation.quatFromYXZ(rotY, rotX, rotZ))); + TRSRTransformation.quatFromXYZ(rotX, rotY, rotZ))); } - public TRSRBakedModel(IFlexibleBakedModel original, TRSRTransformation transform) { + public TRSRBakedModel(IBakedModel original, TRSRTransformation transform) { this.original = original; + this.transformation = TRSRTransformation.blockCenterToCorner(transform); + this.override = new TRSROverride(this); + this.faceOffset = 0; + } - ImmutableList.Builder builder; - builder = ImmutableList.builder(); + /** Rotates around the Y axis and adjusts culling appropriately. South is default. */ + public TRSRBakedModel(IBakedModel original, EnumFacing facing) { + this.original = original; + this.override = new TRSROverride(this); - transform = TRSRTransformation.blockCenterToCorner(transform); + this.faceOffset = 4 + EnumFacing.NORTH.getHorizontalIndex() - facing.getHorizontalIndex(); - // face quads - EnumMap> faces = Maps.newEnumMap(EnumFacing.class); - for(EnumFacing face : EnumFacing.values()) { - if(!original.isBuiltInRenderer()) { - for(BakedQuad quad : original.getFaceQuads(face)) { - Transformer transformer = new Transformer(transform, original.getFormat()); - quad.pipe(transformer); - builder.add(transformer.build()); - } - } - //faces.put(face, builder.build()); - faces.put(face, ImmutableList.of()); - } + double r = Math.PI * (360 - facing.getOpposite().getHorizontalIndex() * 90)/180d; + TRSRTransformation t = new TRSRTransformation(null, null, null, TRSRTransformation.quatFromXYZ(0, (float)r, 0)); + this.transformation = TRSRTransformation.blockCenterToCorner(t); + } + + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + // transform quads obtained from parent + + ImmutableList.Builder builder = ImmutableList.builder(); - // general quads - //builder = ImmutableList.builder(); if(!original.isBuiltInRenderer()) { - for(BakedQuad quad : original.getGeneralQuads()) { - Transformer transformer = new Transformer(transform, original.getFormat()); + // adjust side to facing-rotation + if(side != null && side.getHorizontalIndex() > -1) { + side = EnumFacing.getHorizontal((side.getHorizontalIndex() + faceOffset) % 4); + } + for(BakedQuad quad : original.getQuads(state, side, rand)) { + Transformer transformer = new Transformer(transformation, quad.getFormat()); quad.pipe(transformer); builder.add(transformer.build()); } } - this.general = builder.build(); - this.faces = Maps.immutableEnumMap(faces); - } - - @Override - public List getFaceQuads(EnumFacing side) { - return faces.get(side); - } - - @Override - public List getGeneralQuads() { - return general; + return builder.build(); } @Override @@ -117,11 +115,29 @@ public class TRSRBakedModel implements IFlexibleBakedModel { } @Override - public VertexFormat getFormat() { - return original.getFormat(); + public ItemOverrideList getOverrides() { + return override; } - public static class Transformer extends VertexTransformer { + private static class TRSROverride extends ItemOverrideList { + + private final TRSRBakedModel model; + + public TRSROverride(TRSRBakedModel model) { + super(ImmutableList.of()); + + this.model = model; + } + + @Override + public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity) { + IBakedModel baked = model.original.getOverrides().handleItemState(originalModel, stack, world, entity); + + return new TRSRBakedModel(baked, model.transformation); + } + } + + private static class Transformer extends VertexTransformer { protected Matrix4f transformation; protected Matrix3f normalTransformation; @@ -159,7 +175,7 @@ public class TRSRBakedModel implements IFlexibleBakedModel { } public UnpackedBakedQuad build() { - return ((UnpackedBakedQuad.Builder)parent).build(); + return ((UnpackedBakedQuad.Builder) parent).build(); } } } diff --git a/src/main/java/slimeknights/mantle/common/CommonProxy.java b/src/main/java/slimeknights/mantle/common/CommonProxy.java index e2dd4a7..ab788f8 100644 --- a/src/main/java/slimeknights/mantle/common/CommonProxy.java +++ b/src/main/java/slimeknights/mantle/common/CommonProxy.java @@ -1,4 +1,6 @@ package slimeknights.mantle.common; public class CommonProxy { + public void preInit() { + } } diff --git a/src/main/java/slimeknights/mantle/common/GuiHandler.java b/src/main/java/slimeknights/mantle/common/GuiHandler.java index 22bb260..d651bff 100644 --- a/src/main/java/slimeknights/mantle/common/GuiHandler.java +++ b/src/main/java/slimeknights/mantle/common/GuiHandler.java @@ -2,7 +2,7 @@ package slimeknights.mantle.common; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; diff --git a/src/main/java/slimeknights/mantle/common/IInventoryGui.java b/src/main/java/slimeknights/mantle/common/IInventoryGui.java index c4cea7d..822239d 100644 --- a/src/main/java/slimeknights/mantle/common/IInventoryGui.java +++ b/src/main/java/slimeknights/mantle/common/IInventoryGui.java @@ -3,7 +3,7 @@ package slimeknights.mantle.common; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; diff --git a/src/main/java/slimeknights/mantle/inventory/BaseContainer.java b/src/main/java/slimeknights/mantle/inventory/BaseContainer.java index 01a2ffc..4bc6565 100644 --- a/src/main/java/slimeknights/mantle/inventory/BaseContainer.java +++ b/src/main/java/slimeknights/mantle/inventory/BaseContainer.java @@ -12,8 +12,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; -import net.minecraft.util.IChatComponent; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; @@ -43,7 +42,7 @@ public abstract class BaseContainer extends C public void syncOnOpen(EntityPlayerMP playerOpened) { // find another player that already has the gui for this tile open WorldServer server = playerOpened.getServerForPlayer(); - for(EntityPlayer player : (List) server.playerEntities) { + for(EntityPlayer player : server.playerEntities) { if(player == playerOpened) { continue; } @@ -97,12 +96,12 @@ public abstract class BaseContainer extends C @SuppressWarnings("unchecked") public List getInventory() { - return (List) super.getInventory(); + return super.getInventory(); } - public IChatComponent getInventoryDisplayName() { + public String getInventoryDisplayName() { if(tile instanceof IInventory) { - return ((IInventory) tile).getDisplayName(); + return tile.getName(); } return null; } @@ -157,7 +156,7 @@ public abstract class BaseContainer extends C } ItemStack itemstack = null; - Slot slot = (Slot) this.inventorySlots.get(index); + Slot slot = this.inventorySlots.get(index); // slot that was clicked on not empty? if(slot != null && slot.getHasStack()) { @@ -215,7 +214,7 @@ public abstract class BaseContainer extends C if(stack.isStackable()) { while(stack.stackSize > 0 && (!useEndIndex && k < endIndex || useEndIndex && k >= startIndex)) { - slot = (Slot) this.inventorySlots.get(k); + slot = this.inventorySlots.get(k); itemstack1 = slot.getStack(); if(itemstack1 != null && itemstack1.getItem() == stack.getItem() && (!stack.getHasSubtypes() @@ -267,7 +266,7 @@ public abstract class BaseContainer extends C } while(!useEndIndex && k < endIndex || useEndIndex && k >= startIndex) { - Slot slot = (Slot) this.inventorySlots.get(k); + Slot slot = this.inventorySlots.get(k); ItemStack itemstack1 = slot.getStack(); if(itemstack1 == null && slot.isItemValid(stack)) // Forge: Make sure to respect isItemValid in the slot. diff --git a/src/main/java/slimeknights/mantle/inventory/ContainerMultiModule.java b/src/main/java/slimeknights/mantle/inventory/ContainerMultiModule.java index 61b998c..8d9c7b1 100644 --- a/src/main/java/slimeknights/mantle/inventory/ContainerMultiModule.java +++ b/src/main/java/slimeknights/mantle/inventory/ContainerMultiModule.java @@ -5,12 +5,13 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ClickType; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.tuple.Pair; @@ -107,29 +108,21 @@ public class ContainerMultiModule extends Bas } @Override - public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) { - if(slotId == -999 && mode == 5) { + public ItemStack slotClick(int slotId, int dragType, ClickType type, EntityPlayer player) { + if(slotId == -999 && type == ClickType.QUICK_CRAFT) { for(Container container : subContainers) { - container.slotClick(slotId, clickedButton, mode, playerIn); + container.slotClick(slotId, dragType, type, player); } } -/* - if(slotContainerMap.containsKey(slotId)) { - int actualId = slotId; - if(this.inventorySlots.get(slotId) instanceof SlotWrapper) { - actualId = ((SlotWrapper) this.inventorySlots.get(slotId)).parent.slotNumber; - } - return slotContainerMap.get(slotId).slotClick(actualId, clickedButton, mode, playerIn); - }*/ - return super.slotClick(slotId, clickedButton, mode, playerIn); + return super.slotClick(slotId, dragType, type, player); } // More sophisticated version of the one in BaseContainer // Takes submodules into account when shiftclicking! @Override public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - Slot slot = (Slot) this.inventorySlots.get(index); + Slot slot = this.inventorySlots.get(index); if(slot == null || !slot.getHasStack()) { return null; @@ -236,10 +229,7 @@ public class ContainerMultiModule extends Bas protected boolean moveToContainer(ItemStack itemstack, Container container) { Pair range = subContainerSlotRanges.get(container); - if(!this.mergeItemStack(itemstack, range.getLeft(), range.getRight(), false)) { - return true; - } - return false; + return !this.mergeItemStack(itemstack, range.getLeft(), range.getRight(), false); } @@ -259,10 +249,7 @@ public class ContainerMultiModule extends Bas protected boolean refillContainer(ItemStack itemstack, Container container) { Pair range = subContainerSlotRanges.get(container); - if(!this.mergeItemStackRefill(itemstack, range.getLeft(), range.getRight(), false)) { - return true; - } - return false; + return !this.mergeItemStackRefill(itemstack, range.getLeft(), range.getRight(), false); } /** Searches for a sidechest to display in the UI */ diff --git a/src/main/java/slimeknights/mantle/item/ItemBlockMeta.java b/src/main/java/slimeknights/mantle/item/ItemBlockMeta.java index 6e22a82..1d539e1 100644 --- a/src/main/java/slimeknights/mantle/item/ItemBlockMeta.java +++ b/src/main/java/slimeknights/mantle/item/ItemBlockMeta.java @@ -3,16 +3,15 @@ package slimeknights.mantle.item; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemColored; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.translation.I18n; import net.minecraftforge.client.model.ModelLoader; -import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.registry.GameData; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -33,7 +32,9 @@ public class ItemBlockMeta extends ItemColored { @Override public String getUnlocalizedName(ItemStack stack) { - if(mappingProperty == null) return super.getUnlocalizedName(stack); + if(mappingProperty == null) { + return super.getUnlocalizedName(stack); + } IBlockState state = block.getStateFromMeta(stack.getMetadata()); String name = state.getValue(mappingProperty).toString().toLowerCase(Locale.US); @@ -41,17 +42,18 @@ public class ItemBlockMeta extends ItemColored { } public static void setMappingProperty(Block block, IProperty property) { - ((ItemBlockMeta)Item.getItemFromBlock(block)).mappingProperty = property; + ((ItemBlockMeta) Item.getItemFromBlock(block)).mappingProperty = property; } @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { - if(StatCollector.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) { - tooltip.add(EnumChatFormatting.GRAY.toString() + + if(I18n.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) { + tooltip.add(TextFormatting.GRAY.toString() + LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip")); } - else if(StatCollector.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) { - tooltip.add(EnumChatFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")); + else if(I18n.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) { + tooltip.add( + TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")); } super.addInformation(stack, playerIn, tooltip, advanced); } @@ -59,14 +61,15 @@ public class ItemBlockMeta extends ItemColored { @SideOnly(Side.CLIENT) public void registerItemModels() { final Item item = this; - final ResourceLocation loc = (ResourceLocation) GameData.getBlockRegistry().getNameForObject(block); + final ResourceLocation loc = GameData.getBlockRegistry().getNameForObject(block); - for(Comparable o : (Collection)mappingProperty.getAllowedValues()) { + for(Comparable o : (Collection) mappingProperty.getAllowedValues()) { int meta = block.getMetaFromState(block.getDefaultState().withProperty(mappingProperty, o)); String name = mappingProperty.getName(o); - ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, mappingProperty.getName() + "=" + name)); + ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, mappingProperty + .getName() + "=" + name)); } } } diff --git a/src/main/java/slimeknights/mantle/item/ItemEdible.java b/src/main/java/slimeknights/mantle/item/ItemEdible.java index 34e0e14..eee7e4b 100644 --- a/src/main/java/slimeknights/mantle/item/ItemEdible.java +++ b/src/main/java/slimeknights/mantle/item/ItemEdible.java @@ -37,11 +37,12 @@ public class ItemEdible extends ItemFood { /** * Add a new food type! - * @param meta Metadata to use, has to be free - * @param food How much food it restores on eating - * @param saturation Saturation multiplier on the food - * @param name Unlocalized postfix - * @param effects PotionEffects that will be applied on eating. The PotionEffect passed will be directly applied + * + * @param meta Metadata to use, has to be free + * @param food How much food it restores on eating + * @param saturation Saturation multiplier on the food + * @param name Unlocalized postfix + * @param effects PotionEffects that will be applied on eating. The PotionEffect passed will be directly applied * @return Itemstack containing the registered item */ public ItemStack addFood(int meta, int food, float saturation, String name, PotionEffect... effects) { @@ -67,10 +68,10 @@ public class ItemEdible extends ItemFood { @Override protected void onFoodEaten(ItemStack stack, World worldIn, EntityPlayer player) { - if (!worldIn.isRemote) - { + if(!worldIn.isRemote) { for(PotionEffect potion : potionEffects.get(stack.getMetadata())) { - player.addPotionEffect(new PotionEffect(potion.getPotionID(), potion.getDuration(), potion.getAmplifier(), potion.getIsAmbient(), potion.getIsShowParticles())); + player.addPotionEffect(new PotionEffect(potion.getPotion(), potion.getDuration(), potion.getAmplifier(), potion + .getIsAmbient(), potion.doesShowParticles())); } } } diff --git a/src/main/java/slimeknights/mantle/item/ItemMetaDynamic.java b/src/main/java/slimeknights/mantle/item/ItemMetaDynamic.java index b288486..700b92a 100644 --- a/src/main/java/slimeknights/mantle/item/ItemMetaDynamic.java +++ b/src/main/java/slimeknights/mantle/item/ItemMetaDynamic.java @@ -3,14 +3,13 @@ package slimeknights.mantle.item; import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.procedure.TIntObjectProcedure; -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.ModelResourceLocation; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.StatCollector; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.translation.I18n; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.relauncher.Side; @@ -18,7 +17,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Arrays; import java.util.List; -import java.util.Locale; import slimeknights.mantle.util.LocUtils; @@ -43,20 +41,24 @@ public class ItemMetaDynamic extends Item { /** * Add a valid metadata. - * @param meta The metadata value - * @param name The name used for registering the itemmodel as well as the unlocalized name of the meta. The unlocalized name will be lowercased and stripped of whitespaces. + * + * @param meta The metadata value + * @param name The name used for registering the itemmodel as well as the unlocalized name of the meta. The unlocalized name will be lowercased and stripped of whitespaces. * @return An itemstack representing the Item-Meta combination. */ public ItemStack addMeta(int meta, String name) { if(meta > MAX) { - throw new IllegalArgumentException(String.format("Metadata for %s too high, highest supported value is %d. Meta was %d", name, MAX, meta)); + throw new IllegalArgumentException(String + .format("Metadata for %s too high, highest supported value is %d. Meta was %d", name, MAX, meta)); } else if(isValid(meta)) { - throw new IllegalArgumentException(String.format("Metadata for %s is already taken. Meta %d is %s", name, meta, names.get(meta))); + throw new IllegalArgumentException(String + .format("Metadata for %s is already taken. Meta %d is %s", name, meta, names + .get(meta))); } while(meta >= availabilityMask.length) { - availabilityMask = Arrays.copyOf(availabilityMask, availabilityMask.length*2); + availabilityMask = Arrays.copyOf(availabilityMask, availabilityMask.length * 2); } setValid(meta); names.put(meta, name); @@ -66,10 +68,12 @@ public class ItemMetaDynamic extends Item { @Override public String getUnlocalizedName(ItemStack stack) { int meta = stack.getMetadata(); // should call getMetadata below - if(isValid(meta)) + if(isValid(meta)) { return super.getUnlocalizedName(stack) + "." + LocUtils.makeLocString(names.get(meta)); - else + } + else { return super.getUnlocalizedName(stack); + } } @Override @@ -118,12 +122,13 @@ public class ItemMetaDynamic extends Item { @Override public void addInformation(ItemStack stack, EntityPlayer playerIn, List tooltip, boolean advanced) { - if(StatCollector.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) { - tooltip.add(EnumChatFormatting.GRAY.toString() + + if(I18n.canTranslate(this.getUnlocalizedName(stack) + ".tooltip")) { + tooltip.add(TextFormatting.GRAY.toString() + LocUtils.translateRecursive(this.getUnlocalizedName(stack) + ".tooltip")); } - else if(StatCollector.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) { - tooltip.add(EnumChatFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")); + else if(I18n.canTranslate(super.getUnlocalizedName(stack) + ".tooltip")) { + tooltip.add( + TextFormatting.GRAY.toString() + LocUtils.translateRecursive(super.getUnlocalizedName(stack) + ".tooltip")); } super.addInformation(stack, playerIn, tooltip, advanced); } diff --git a/src/main/java/slimeknights/mantle/multiblock/IMasterLogic.java b/src/main/java/slimeknights/mantle/multiblock/IMasterLogic.java index 1f66dfa..28a719b 100644 --- a/src/main/java/slimeknights/mantle/multiblock/IMasterLogic.java +++ b/src/main/java/slimeknights/mantle/multiblock/IMasterLogic.java @@ -1,12 +1,13 @@ package slimeknights.mantle.multiblock; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; -public interface IMasterLogic -{ - /** Called when servants change their state - * - * @param pos servant position - */ - public void notifyChange(IServantLogic servant, BlockPos pos); +public interface IMasterLogic { + + /** + * Called when servants change their state + * + * @param pos servant position + */ + void notifyChange(IServantLogic servant, BlockPos pos); } diff --git a/src/main/java/slimeknights/mantle/multiblock/IMasterNode.java b/src/main/java/slimeknights/mantle/multiblock/IMasterNode.java index 312c25d..af67c99 100644 --- a/src/main/java/slimeknights/mantle/multiblock/IMasterNode.java +++ b/src/main/java/slimeknights/mantle/multiblock/IMasterNode.java @@ -1,8 +1,8 @@ package slimeknights.mantle.multiblock; -public interface IMasterNode extends IMasterLogic, IServantLogic -{ - public boolean isCurrentlyMaster(); +public interface IMasterNode extends IMasterLogic, IServantLogic { - public boolean isEquivalentMaster(IMasterLogic master); + boolean isCurrentlyMaster(); + + boolean isEquivalentMaster(IMasterLogic master); } diff --git a/src/main/java/slimeknights/mantle/multiblock/IServantLogic.java b/src/main/java/slimeknights/mantle/multiblock/IServantLogic.java index 3319277..8277d21 100644 --- a/src/main/java/slimeknights/mantle/multiblock/IServantLogic.java +++ b/src/main/java/slimeknights/mantle/multiblock/IServantLogic.java @@ -1,41 +1,39 @@ package slimeknights.mantle.multiblock; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -public interface IServantLogic -{ - public BlockPos getMasterPosition(); +public interface IServantLogic { - /** The block should already have a valid master */ - public void notifyMasterOfChange(); + BlockPos getMasterPosition(); - /** Checks if this block can be tied to this master - * - * @param master - * @param world the world of master - * @param pos position of master - * @return whether the servant can be tied to this master - */ + /** The block should already have a valid master */ + void notifyMasterOfChange(); - public boolean setPotentialMaster(IMasterLogic master, World world, BlockPos pos); + /** + * Checks if this block can be tied to this master + * + * @param world the world of master + * @param pos position of master + * @return whether the servant can be tied to this master + */ - /** Used to set and verify that this is the block's master - * - * @param master - * @param world - * @param pos position of master - * @return Is this block tied to this master? - */ + boolean setPotentialMaster(IMasterLogic master, World world, BlockPos pos); - public boolean verifyMaster(IMasterLogic master, World world, BlockPos pos); + /** + * Used to set and verify that this is the block's master + * + * @param pos position of master + * @return Is this block tied to this master? + */ - /** Exactly what it says on the tin - * - * @param master - * @param world - * @param pos position of master - */ + boolean verifyMaster(IMasterLogic master, World world, BlockPos pos); - public void invalidateMaster(IMasterLogic master, World world, BlockPos pos); + /** + * Exactly what it says on the tin + * + * @param pos position of master + */ + + void invalidateMaster(IMasterLogic master, World world, BlockPos pos); } diff --git a/src/main/java/slimeknights/mantle/multiblock/MultiServantLogic.java b/src/main/java/slimeknights/mantle/multiblock/MultiServantLogic.java index c29b3c2..5df33ee 100644 --- a/src/main/java/slimeknights/mantle/multiblock/MultiServantLogic.java +++ b/src/main/java/slimeknights/mantle/multiblock/MultiServantLogic.java @@ -5,193 +5,169 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameData; -public class MultiServantLogic extends TileEntity implements IServantLogic -{ - boolean hasMaster; +public class MultiServantLogic extends TileEntity implements IServantLogic { - BlockPos master; + boolean hasMaster; - Block masterBlock; + BlockPos master; - IBlockState state; + Block masterBlock; - public boolean canUpdate() - { - return false; + IBlockState state; + + public boolean canUpdate() { + return false; + } + + public boolean getHasMaster() { + return this.hasMaster; + } + + public boolean hasValidMaster() { + if(!this.hasMaster) { + return false; } - public boolean getHasMaster() - { - return this.hasMaster; + if(this.worldObj.getBlockState(this.master).getBlock() == this.masterBlock && this.worldObj + .getBlockState(this.master) == this.state) { + return true; } - - public boolean hasValidMaster() - { - if (!this.hasMaster) - { - return false; - } - - if (this.worldObj.getBlockState(this.master).getBlock() == this.masterBlock && this.worldObj.getBlockState(this.master) == this.state) - { - return true; - } - else - { - this.hasMaster = false; - this.master = null; - return false; - } + else { + this.hasMaster = false; + this.master = null; + return false; } + } - @Override - public BlockPos getMasterPosition() - { - return this.master; - } + @Override + public BlockPos getMasterPosition() { + return this.master; + } - public void overrideMaster(BlockPos pos) - { - this.hasMaster = true; - this.master = pos; - this.state = this.worldObj.getBlockState(this.master); - this.masterBlock = this.state.getBlock(); - } + public void overrideMaster(BlockPos pos) { + this.hasMaster = true; + this.master = pos; + this.state = this.worldObj.getBlockState(this.master); + this.masterBlock = this.state.getBlock(); + } - public void removeMaster() - { - this.hasMaster = false; - this.master = null; - this.masterBlock = null; - this.state = null; - } + public void removeMaster() { + this.hasMaster = false; + this.master = null; + this.masterBlock = null; + this.state = null; + } - @Override - public boolean setPotentialMaster(IMasterLogic master, World w, BlockPos pos) - { - return !this.hasMaster; - } + @Override + public boolean setPotentialMaster(IMasterLogic master, World w, BlockPos pos) { + return !this.hasMaster; + } - @Deprecated - public boolean verifyMaster(IMasterLogic logic, BlockPos pos) - { - return this.master.equals(pos) && this.worldObj.getBlockState(pos) == this.state && this.worldObj.getBlockState(pos).getBlock() == this.masterBlock; - } + @Deprecated + public boolean verifyMaster(IMasterLogic logic, BlockPos pos) { + return this.master.equals(pos) && this.worldObj.getBlockState(pos) == this.state && this.worldObj.getBlockState(pos) + .getBlock() == this.masterBlock; + } - @Override - public boolean verifyMaster(IMasterLogic logic, World world, BlockPos pos) - { - if (this.hasMaster) - { - return this.hasValidMaster(); - } - else - { - this.overrideMaster(pos); - return true; - } + @Override + public boolean verifyMaster(IMasterLogic logic, World world, BlockPos pos) { + if(this.hasMaster) { + return this.hasValidMaster(); } + else { + this.overrideMaster(pos); + return true; + } + } - @Override - public void invalidateMaster(IMasterLogic master, World w, BlockPos pos) - { - this.hasMaster = false; - master = null; - } + @Override + public void invalidateMaster(IMasterLogic master, World w, BlockPos pos) { + this.hasMaster = false; + master = null; + } - @Override - public void notifyMasterOfChange() - { - if (this.hasValidMaster()) - { - IMasterLogic logic = (IMasterLogic) this.worldObj.getTileEntity(this.master); - logic.notifyChange(this, this.pos); - } + @Override + public void notifyMasterOfChange() { + if(this.hasValidMaster()) { + IMasterLogic logic = (IMasterLogic) this.worldObj.getTileEntity(this.master); + logic.notifyChange(this, this.pos); } + } - public void readCustomNBT(NBTTagCompound tags) - { - this.hasMaster = tags.getBoolean("hasMaster"); - if (this.hasMaster) - { - int xCenter = tags.getInteger("xCenter"); - int yCenter = tags.getInteger("yCenter"); - int zCenter = tags.getInteger("zCenter"); - this.master = new BlockPos(xCenter, yCenter, zCenter); - this.masterBlock = GameData.getBlockRegistry().getObject(new ResourceLocation(tags.getString("MasterBlockName"))); - this.state = Block.getStateById(tags.getInteger("masterState")); - } + public void readCustomNBT(NBTTagCompound tags) { + this.hasMaster = tags.getBoolean("hasMaster"); + if(this.hasMaster) { + int xCenter = tags.getInteger("xCenter"); + int yCenter = tags.getInteger("yCenter"); + int zCenter = tags.getInteger("zCenter"); + this.master = new BlockPos(xCenter, yCenter, zCenter); + this.masterBlock = GameData.getBlockRegistry().getObject(new ResourceLocation(tags.getString("MasterBlockName"))); + this.state = Block.getStateById(tags.getInteger("masterState")); } + } - public void writeCustomNBT(NBTTagCompound tags) - { - tags.setBoolean("hasMaster", this.hasMaster); - if (this.hasMaster) - { - tags.setInteger("xCenter", this.master.getX()); - tags.setInteger("yCenter", this.master.getY()); - tags.setInteger("zCenter", this.master.getZ()); - tags.setString("MasterBlockName", GameData.getBlockRegistry().getNameForObject(this.masterBlock).toString()); - tags.setInteger("masterState", Block.getStateId(this.state)); - } + public void writeCustomNBT(NBTTagCompound tags) { + tags.setBoolean("hasMaster", this.hasMaster); + if(this.hasMaster) { + tags.setInteger("xCenter", this.master.getX()); + tags.setInteger("yCenter", this.master.getY()); + tags.setInteger("zCenter", this.master.getZ()); + tags.setString("MasterBlockName", GameData.getBlockRegistry().getNameForObject(this.masterBlock).toString()); + tags.setInteger("masterState", Block.getStateId(this.state)); } + } - @Override - public void readFromNBT(NBTTagCompound tags) - { - super.readFromNBT(tags); - this.readCustomNBT(tags); - } + @Override + public void readFromNBT(NBTTagCompound tags) { + super.readFromNBT(tags); + this.readCustomNBT(tags); + } - @Override - public void writeToNBT(NBTTagCompound tags) - { - super.writeToNBT(tags); - this.writeCustomNBT(tags); - } + @Override + public void writeToNBT(NBTTagCompound tags) { + super.writeToNBT(tags); + this.writeCustomNBT(tags); + } - /* Packets */ - @Override - public Packet getDescriptionPacket() - { - NBTTagCompound tag = new NBTTagCompound(); - this.writeCustomNBT(tag); - return new S35PacketUpdateTileEntity(this.pos, 1, tag); - } + /* Packets */ + @Override + public Packet getDescriptionPacket() { + NBTTagCompound tag = new NBTTagCompound(); + this.writeCustomNBT(tag); + return new SPacketUpdateTileEntity(this.pos, 1, tag); + } - @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) - { - this.readCustomNBT(packet.getNbtCompound()); - this.worldObj.notifyLightSet(this.pos); - this.worldObj.markBlockForUpdate(this.pos); - } + @Override + public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { + this.readCustomNBT(packet.getNbtCompound()); + this.worldObj.notifyLightSet(this.pos); + IBlockState state = worldObj.getBlockState(this.pos); + this.worldObj.notifyBlockUpdate(this.pos, state, state, 3); + } - @Override - public World getWorld() - { - return this.worldObj; - } + @Override + public World getWorld() { + return this.worldObj; + } - @Deprecated - public boolean setMaster(BlockPos pos) - { - if (!this.hasMaster || this.worldObj.getBlockState(this.master) != this.state || (this.worldObj.getBlockState(this.master).getBlock() != this.masterBlock)) - { - this.overrideMaster(pos); - return true; - } - else - { - return false; - } + @Deprecated + public boolean setMaster(BlockPos pos) { + if(!this.hasMaster || this.worldObj.getBlockState(this.master) != this.state || (this.worldObj + .getBlockState(this.master) + .getBlock() != this.masterBlock)) { + this.overrideMaster(pos); + return true; } + else { + return false; + } + } } diff --git a/src/main/java/slimeknights/mantle/network/AbstractPacket.java b/src/main/java/slimeknights/mantle/network/AbstractPacket.java index 2ef620b..04d270d 100644 --- a/src/main/java/slimeknights/mantle/network/AbstractPacket.java +++ b/src/main/java/slimeknights/mantle/network/AbstractPacket.java @@ -2,11 +2,8 @@ package slimeknights.mantle.network; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.NetHandlerPlayServer; -import net.minecraft.util.BlockPos; +import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; -import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; -import net.minecraftforge.fml.relauncher.Side; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/slimeknights/mantle/network/AbstractPacketThreadsafe.java b/src/main/java/slimeknights/mantle/network/AbstractPacketThreadsafe.java index 8e9a563..08c0c4e 100644 --- a/src/main/java/slimeknights/mantle/network/AbstractPacketThreadsafe.java +++ b/src/main/java/slimeknights/mantle/network/AbstractPacketThreadsafe.java @@ -3,8 +3,6 @@ package slimeknights.mantle.network; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.NetHandlerPlayServer; -import net.minecraft.server.MinecraftServer; -import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; /** @@ -27,7 +25,7 @@ public abstract class AbstractPacketThreadsafe extends AbstractPacket { @Override public final IMessage handleServer(final NetHandlerPlayServer netHandler) { - MinecraftServer.getServer().addScheduledTask(new Runnable() { + Minecraft.getMinecraft().addScheduledTask(new Runnable() { @Override public void run() { handleServerSafe(netHandler); diff --git a/src/main/java/slimeknights/mantle/network/NetworkWrapper.java b/src/main/java/slimeknights/mantle/network/NetworkWrapper.java index cfa3ea3..de0ff96 100644 --- a/src/main/java/slimeknights/mantle/network/NetworkWrapper.java +++ b/src/main/java/slimeknights/mantle/network/NetworkWrapper.java @@ -23,7 +23,7 @@ public class NetworkWrapper { } /** - * Packet will be received on both cliend and server side. + * Packet will be received on both client and server side. */ public void registerPacket(Class packetClazz) { registerPacketClient(packetClazz); @@ -49,6 +49,7 @@ public class NetworkWrapper { } public static class AbstactPacketHandler implements IMessageHandler { + @Override public IMessage onMessage(AbstractPacket packet, MessageContext ctx) { if(ctx.side == Side.SERVER) { diff --git a/src/main/java/slimeknights/mantle/network/book/PacketUpdateSavedPage.java b/src/main/java/slimeknights/mantle/network/book/PacketUpdateSavedPage.java new file mode 100644 index 0000000..163df09 --- /dev/null +++ b/src/main/java/slimeknights/mantle/network/book/PacketUpdateSavedPage.java @@ -0,0 +1,53 @@ +package slimeknights.mantle.network.book; + +import io.netty.buffer.ByteBuf; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.network.NetHandlerPlayServer; +import net.minecraft.util.EnumHand; +import net.minecraftforge.fml.common.network.ByteBufUtils; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import slimeknights.mantle.client.book.BookHelper; +import slimeknights.mantle.network.AbstractPacket; + +public class PacketUpdateSavedPage extends AbstractPacket { + + private String pageName; + + public PacketUpdateSavedPage() { + + } + + public PacketUpdateSavedPage(String pageName) { + this.pageName = pageName; + } + + @Override + public IMessage handleClient(NetHandlerPlayClient netHandler) { + return null; + } + + @Override + public IMessage handleServer(NetHandlerPlayServer netHandler) { + if (netHandler.playerEntity != null && pageName != null) { + EntityPlayer player = netHandler.playerEntity; + + ItemStack is = player.getHeldItem(EnumHand.MAIN_HAND); + + BookHelper.writeSavedPage(is, pageName); + } + + return null; + } + + @Override + public void fromBytes(ByteBuf buf) { + pageName = ByteBufUtils.readUTF8String(buf); + } + + @Override + public void toBytes(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, pageName); + } +} diff --git a/src/main/java/slimeknights/mantle/pulsar/config/IConfiguration.java b/src/main/java/slimeknights/mantle/pulsar/config/IConfiguration.java index 9f40530..8da94cb 100644 --- a/src/main/java/slimeknights/mantle/pulsar/config/IConfiguration.java +++ b/src/main/java/slimeknights/mantle/pulsar/config/IConfiguration.java @@ -15,7 +15,7 @@ public interface IConfiguration { /** * Perform any configuration loading required. */ - public void load(); + void load(); /** * Gets whether the given module is enabled in the config. @@ -23,11 +23,11 @@ public interface IConfiguration { * @param meta The pulse metadata. * @return Whether the module is enabled. */ - public boolean isModuleEnabled(PulseMeta meta); + boolean isModuleEnabled(PulseMeta meta); /** * Flush configuration to disk/database/whatever. */ - public void flush(); + void flush(); } diff --git a/src/main/java/slimeknights/mantle/pulsar/control/PulseManager.java b/src/main/java/slimeknights/mantle/pulsar/control/PulseManager.java index 67409e8..97f3623 100644 --- a/src/main/java/slimeknights/mantle/pulsar/control/PulseManager.java +++ b/src/main/java/slimeknights/mantle/pulsar/control/PulseManager.java @@ -210,7 +210,7 @@ public class PulseManager { } private void preInit(FMLPreInitializationEvent evt) { - if (!blockNewRegistrations) conf.flush(); // First preInit call, so flush config + if (!blockNewRegistrations) conf.flush(); // First init call, so flush config blockNewRegistrations = true; } diff --git a/src/main/java/slimeknights/mantle/pulsar/pulse/Pulse.java b/src/main/java/slimeknights/mantle/pulsar/pulse/Pulse.java index f8317b4..cafd0c4 100644 --- a/src/main/java/slimeknights/mantle/pulsar/pulse/Pulse.java +++ b/src/main/java/slimeknights/mantle/pulsar/pulse/Pulse.java @@ -18,31 +18,31 @@ public @interface Pulse { /** * @return This Pulses UID - Much like FML mods have mod IDs. */ - public String id(); + String id(); /** * @return This Pulses description, human-readable for config files. Can be blank. */ - public String description() default ""; + String description() default ""; /** * @return Dependant mod IDs, seperated by ; as in FML. Skips checks when undefined. */ - public String modsRequired() default ""; + String modsRequired() default ""; /** * @return Dependeant Pulse IDs, seperated by ; . Skips checks when undefined. */ - public String pulsesRequired() default ""; + String pulsesRequired() default ""; /** * @return Whether this Pulse is mandatory or not (true -> mandatory). */ - public boolean forced() default false; + boolean forced() default false; /** * @return Whether a configurable Pulse should be enabled by default. Ignored where forced = true. */ - public boolean defaultEnable() default true; + boolean defaultEnable() default true; } diff --git a/src/main/java/slimeknights/mantle/tileentity/TileInventory.java b/src/main/java/slimeknights/mantle/tileentity/TileInventory.java index f64df61..1caab1e 100644 --- a/src/main/java/slimeknights/mantle/tileentity/TileInventory.java +++ b/src/main/java/slimeknights/mantle/tileentity/TileInventory.java @@ -7,9 +7,9 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.ChatComponentTranslation; -import net.minecraft.util.IChatComponent; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextComponentTranslation; import java.util.Arrays; @@ -145,12 +145,12 @@ public class TileInventory extends TileEntity implements IInventory { } @Override - public IChatComponent getDisplayName() { + public ITextComponent getDisplayName() { if(hasCustomName()) { - return new ChatComponentText(getName()); + return new TextComponentString(getName()); } - return new ChatComponentTranslation(getName()); + return new TextComponentTranslation(getName()); } diff --git a/src/main/java/slimeknights/mantle/util/ImmutableConcatList.java b/src/main/java/slimeknights/mantle/util/ImmutableConcatList.java new file mode 100644 index 0000000..1b74a98 --- /dev/null +++ b/src/main/java/slimeknights/mantle/util/ImmutableConcatList.java @@ -0,0 +1,215 @@ +package slimeknights.mantle.util; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Iterables; +import com.google.common.collect.UnmodifiableListIterator; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.NoSuchElementException; + +import static com.google.common.base.Preconditions.checkPositionIndex; + +public class ImmutableConcatList implements List { + + protected final FluentIterable iterable; + + public ImmutableConcatList(List... lists) { + iterable = FluentIterable.from(Iterables.concat(lists)); + } + + public ImmutableConcatList(List> lists) { + iterable = FluentIterable.from(Iterables.concat(lists)); + } + + @Override + public int size() { + return iterable.size(); + } + + @Override + public boolean isEmpty() { + return iterable.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return iterable.contains(o); + } + + @Override + public Iterator iterator() { + return iterable.iterator(); + } + + @Override + public Object[] toArray() { + return iterable.toList().toArray(); + } + + @Override + public T[] toArray(T[] a) { + return iterable.toList().toArray(a); + } + + @Override + public boolean add(E e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection c) { + for (Object e : c) + if (!contains(e)) + return false; + return true; + } + + @Override + public boolean addAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int index, Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + @Override + public E get(int index) { + return iterable.get(index); + } + + @Override + public E set(int index, E element) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(int index, E element) { + throw new UnsupportedOperationException(); + } + + @Override + public E remove(int index) { + throw new UnsupportedOperationException(); + } + + @Override + public int indexOf(final Object o) { + Iterator iterator = iterable.iterator(); + for (int i = 0; iterator.hasNext(); i++) { + if(o == iterator.next()) { + return i; + } + } + + return -1; + } + + @Override + public int lastIndexOf(Object o) { + Iterator iterator = iterable.iterator(); + int j = -1; + for (int i = 0; iterator.hasNext(); i++) { + if(o == iterator.next()) { + j = i; + } + } + + return j; + } + + @Override + public ListIterator listIterator() { + return listIterator(0); + } + + @Override + public ListIterator listIterator(int index) { + return new ListItr(this.size(), index) { + @Override + protected E get(int index) { + return ImmutableConcatList.this.get(index); + } + }; + } + + @Override + public List subList(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + // basically a copy of AbstractIndexedListIterator + private abstract static class ListItr extends UnmodifiableListIterator { + + private final int size; + private int position; + + public ListItr(int size, int position) { + checkPositionIndex(position, size); + this.size = size; + this.position = position; + } + + protected abstract E get(int index); + + @Override + public final boolean hasNext() { + return position < size; + } + + @Override + public final E next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + return get(position++); + } + + @Override + public final int nextIndex() { + return position; + } + + @Override + public final boolean hasPrevious() { + return position > 0; + } + + @Override + public final E previous() { + if (!hasPrevious()) { + throw new NoSuchElementException(); + } + return get(--position); + } + + @Override + public final int previousIndex() { + return position - 1; + } + } +} diff --git a/src/main/java/slimeknights/mantle/util/JeiPlugin.java b/src/main/java/slimeknights/mantle/util/JeiPlugin.java index 889eb71..276b122 100644 --- a/src/main/java/slimeknights/mantle/util/JeiPlugin.java +++ b/src/main/java/slimeknights/mantle/util/JeiPlugin.java @@ -1,27 +1,20 @@ package slimeknights.mantle.util; +import java.awt.*; +import java.util.List; + import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.awt.Rectangle; -import java.util.List; -import mezz.jei.api.IItemRegistry; -import mezz.jei.api.IJeiHelpers; import mezz.jei.api.IJeiRuntime; import mezz.jei.api.IModPlugin; import mezz.jei.api.IModRegistry; -import mezz.jei.api.IRecipeRegistry; import mezz.jei.api.JEIPlugin; import mezz.jei.api.gui.IAdvancedGuiHandler; import slimeknights.mantle.client.gui.GuiMultiModule; @JEIPlugin public class JeiPlugin implements IModPlugin { - @Override - public void onJeiHelpersAvailable(IJeiHelpers jeiHelpers) {} - - @Override - public void onItemRegistryAvailable(IItemRegistry itemRegistry) {} @Override public void register(IModRegistry registry) { @@ -41,8 +34,6 @@ public class JeiPlugin implements IModPlugin { } @Override - public void onRecipeRegistryAvailable(IRecipeRegistry recipeRegistry) {} - - @Override - public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {} + public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { + } } diff --git a/src/main/java/slimeknights/mantle/util/LocUtils.java b/src/main/java/slimeknights/mantle/util/LocUtils.java index 42f55a6..2049011 100644 --- a/src/main/java/slimeknights/mantle/util/LocUtils.java +++ b/src/main/java/slimeknights/mantle/util/LocUtils.java @@ -1,12 +1,14 @@ package slimeknights.mantle.util; -import net.minecraft.util.StatCollector; +import net.minecraft.util.text.translation.I18n; import java.util.Locale; // localization utils public abstract class LocUtils { - private LocUtils() {} + + private LocUtils() { + } /** * Removes all whitespaces from the string and makes it lowercase. @@ -16,6 +18,6 @@ public abstract class LocUtils { } public static String translateRecursive(String key, Object... params) { - return StatCollector.translateToLocal(StatCollector.translateToLocalFormatted(key, params)); + return I18n.translateToLocal(I18n.translateToLocalFormatted(key, params)); } } diff --git a/src/main/java/slimeknights/mantle/util/RecipeMatch.java b/src/main/java/slimeknights/mantle/util/RecipeMatch.java index f6651ba..5b9e5e2 100644 --- a/src/main/java/slimeknights/mantle/util/RecipeMatch.java +++ b/src/main/java/slimeknights/mantle/util/RecipeMatch.java @@ -5,7 +5,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import net.minecraft.block.Block; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; diff --git a/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java b/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java index 701840e..b5dd7ce 100644 --- a/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java +++ b/src/main/java/slimeknights/mantle/util/RecipeMatchRegistry.java @@ -1,7 +1,6 @@ package slimeknights.mantle.util; import com.google.common.collect.Lists; -import com.google.common.collect.Queues; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -137,7 +136,8 @@ public class RecipeMatchRegistry { public static RecipeComparator INSTANCE = new RecipeComparator(); - private RecipeComparator() {} + private RecipeComparator() { + } @Override public int compare(RecipeMatch o1, RecipeMatch o2) { diff --git a/src/main/java/slimeknights/mantle/util/RecipeRemover.java b/src/main/java/slimeknights/mantle/util/RecipeRemover.java index c681589..d36172e 100644 --- a/src/main/java/slimeknights/mantle/util/RecipeRemover.java +++ b/src/main/java/slimeknights/mantle/util/RecipeRemover.java @@ -1,8 +1,5 @@ package slimeknights.mantle.util; -import java.util.List; -import java.util.Map; - import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; @@ -10,87 +7,74 @@ import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; -import net.minecraftforge.common.ChestGenHooks; + +import java.util.List; +import java.util.Map; @SuppressWarnings("unchecked") -public class RecipeRemover -{ - public static void removeShapedRecipes(List removelist) - { - for (ItemStack stack : removelist) - { - removeShapedRecipe(stack); +public class RecipeRemover { + + public static void removeShapedRecipes(List removelist) { + for(ItemStack stack : removelist) { + removeShapedRecipe(stack); + } + } + + public static void removeAnyRecipe(ItemStack resultItem) { + List recipes = CraftingManager.getInstance().getRecipeList(); + for(int i = 0; i < recipes.size(); i++) { + IRecipe tmpRecipe = recipes.get(i); + ItemStack recipeResult = tmpRecipe.getRecipeOutput(); + if(ItemStack.areItemStacksEqual(resultItem, recipeResult)) { + recipes.remove(i--); + } + } + } + + public static void removeShapedRecipe(ItemStack resultItem) { + List recipes = CraftingManager.getInstance().getRecipeList(); + for(int i = 0; i < recipes.size(); i++) { + IRecipe tmpRecipe = recipes.get(i); + if(tmpRecipe instanceof ShapedRecipes) { + ShapedRecipes recipe = (ShapedRecipes) tmpRecipe; + ItemStack recipeResult = recipe.getRecipeOutput(); + + if(ItemStack.areItemStacksEqual(resultItem, recipeResult)) { + recipes.remove(i--); } + } } + } - public static void removeAnyRecipe(ItemStack resultItem) - { - List recipes = CraftingManager.getInstance().getRecipeList(); - for (int i = 0; i < recipes.size(); i++) - { - IRecipe tmpRecipe = recipes.get(i); - ItemStack recipeResult = tmpRecipe.getRecipeOutput(); - if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) - { - recipes.remove(i--); - } + public static void removeShapelessRecipe(ItemStack resultItem) { + List recipes = CraftingManager.getInstance().getRecipeList(); + for(int i = 0; i < recipes.size(); i++) { + IRecipe tmpRecipe = recipes.get(i); + if(tmpRecipe instanceof ShapelessRecipes) { + ShapelessRecipes recipe = (ShapelessRecipes) tmpRecipe; + ItemStack recipeResult = recipe.getRecipeOutput(); + + if(ItemStack.areItemStacksEqual(resultItem, recipeResult)) { + recipes.remove(i--); } + } } + } - public static void removeShapedRecipe(ItemStack resultItem) - { - List recipes = CraftingManager.getInstance().getRecipeList(); - for (int i = 0; i < recipes.size(); i++) - { - IRecipe tmpRecipe = recipes.get(i); - if (tmpRecipe instanceof ShapedRecipes) - { - ShapedRecipes recipe = (ShapedRecipes) tmpRecipe; - ItemStack recipeResult = recipe.getRecipeOutput(); + public static void removeFurnaceRecipe(ItemStack resultItem) { + Map recipes = FurnaceRecipes.instance().getSmeltingList(); + recipes.remove(resultItem); + } - if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) - { - recipes.remove(i--); - } - } - } - } - - public static void removeShapelessRecipe(ItemStack resultItem) - { - List recipes = CraftingManager.getInstance().getRecipeList(); - for (int i = 0; i < recipes.size(); i++) - { - IRecipe tmpRecipe = recipes.get(i); - if (tmpRecipe instanceof ShapelessRecipes) - { - ShapelessRecipes recipe = (ShapelessRecipes) tmpRecipe; - ItemStack recipeResult = recipe.getRecipeOutput(); - - if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) - { - recipes.remove(i--); - } - } - } - } - - public static void removeFurnaceRecipe(ItemStack resultItem) - { - Map recipes = FurnaceRecipes.instance().getSmeltingList(); - recipes.remove(resultItem); - } - - public static void removeFurnaceRecipe(Item i, int metadata) - { - removeFurnaceRecipe(new ItemStack(i, 1, metadata)); - } - - public static void removeFurnaceRecipe(Item i) - { - removeFurnaceRecipe(new ItemStack(i, 1, 32767)); - } + public static void removeFurnaceRecipe(Item i, int metadata) { + removeFurnaceRecipe(new ItemStack(i, 1, metadata)); + } + public static void removeFurnaceRecipe(Item i) { + removeFurnaceRecipe(new ItemStack(i, 1, 32767)); + } +/* + // todo: 1.9 //removes from all vanilla worldgen chests :D public static void removeFromChests(ItemStack resultItem) { @@ -105,5 +89,5 @@ public class RecipeRemover ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_CROSSING).removeItem(resultItem); ChestGenHooks.getInfo(ChestGenHooks.STRONGHOLD_LIBRARY).removeItem(resultItem); - } + }*/ } diff --git a/src/main/java/slimeknights/mantle/util/TagHelper.java b/src/main/java/slimeknights/mantle/util/TagHelper.java index 3151e53..a4ed21e 100644 --- a/src/main/java/slimeknights/mantle/util/TagHelper.java +++ b/src/main/java/slimeknights/mantle/util/TagHelper.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; public class TagHelper { + public static int TAG_TYPE_STRING = (new NBTTagString()).getId(); public static int TAG_TYPE_COMPOUND = (new NBTTagCompound()).getId(); diff --git a/src/main/resources/assets/mantle/books/TestBook/appearance.json b/src/main/resources/assets/mantle/books/TestBook/appearance.json new file mode 100644 index 0000000..0e2bdb5 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/appearance.json @@ -0,0 +1,10 @@ +{ + //"coverColor": "0x8B4631", + //"arrowColor": "0xFFFFD3", + //"arrowColorHover": "0xFF541C", + //"indexBookmark": true, + //"lockedSectionColor": "0xFFFFFF", + "title": "Materials and You", + "subtitle": "By Skyla", + "drawPageNumbers": true +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/language.lang b/src/main/resources/assets/mantle/books/TestBook/en_US/language.lang new file mode 100644 index 0000000..7644376 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/language.lang @@ -0,0 +1,11 @@ +// Sections +test section=Test Section +section 2=Locked Section +section 3=Hidden Section +// Test Section Pages +test section.page1=Blank Page +test section.pagecrafter=Crafting Page +test section.pagesmallcrafting=Small Crafting Page +test section.pagesmelting=Smelting Page +test section.pageblockinteraction=Block Interaction Page +test section.pagestructure=3D Model Page \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page2.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page2.json new file mode 100644 index 0000000..1bf7373 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page2.json @@ -0,0 +1,34 @@ +{ + "text": [ + { + "text": "Long ago in a galaxy far ", + "color": "gold" + }, + { + "text": "far", + "underlined": true, + "tooltip": [ + "You missed the joke", + "By Skyla" + ], + "action": "go-to-page:Test Section.Page5", + "color": "gold" + }, + { + "text": " away. ", + "action": "go-to-page:Test Section.Page4", + "color": "gold" + }, + { + "text": "Use the force, " + }, + { + "text": "Harry!", + "scale": 2 + }, + { + "text": "For I am the wizard that you seek!", + "paragraph": true + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page3.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page3.json new file mode 100644 index 0000000..762a4c6 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page3.json @@ -0,0 +1,5 @@ +{ + "image": { + "file": "images/test.png" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page4_5.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page4_5.json new file mode 100644 index 0000000..215eb99 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page4_5.json @@ -0,0 +1,10 @@ +{ + "text": [ + { + "text": "Test of mississipi" + } + ], + "image": { + "file": "images/test.png" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page6_7.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page6_7.json new file mode 100644 index 0000000..e151556 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/page6_7.json @@ -0,0 +1,15 @@ +{ + "text1": [ + { + "text": "Test of mississipi" + } + ], + "text2": [ + { + "text": "Test of mississipi" + } + ], + "image": { + "file": "images/test.png" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pageblkinteraction.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pageblkinteraction.json new file mode 100644 index 0000000..c4ff182 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pageblkinteraction.json @@ -0,0 +1,14 @@ +{ + "title": "Interacting with Blocks", + "input": { + "itemList": "items/records.json" + }, + "block": { + "id": "minecraft:jukebox" + }, + "description": [ + { + "text": "That's my jam!" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecrafting.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecrafting.json new file mode 100644 index 0000000..e3fc391 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecrafting.json @@ -0,0 +1,46 @@ +{ + "title": "Crafting a Thing", + "grid_size": "large", + "grid": [ + [ + {}, + { + "id": "minecraft:redstone_torch" + } + ], + [ + { + "id": "minecraft:redstone_torch" + }, + { + "id": "minecraft:quartz" + }, + { + "id": "minecraft:redstone_torch" + } + ], + [ + { + "id": "minecraft:stone" + }, + { + "id": "minecraft:stone" + }, + { + "id": "minecraft:stone" + } + ] + ], + "result": { + "id": "minecraft:comparator" + }, + "description": [ + { + "text": "This item does stuff and, of course, " + }, + { + "text": "things.", + "underlined": true + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecraftingsmall.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecraftingsmall.json new file mode 100644 index 0000000..648a90c --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagecraftingsmall.json @@ -0,0 +1,34 @@ +{ + "title": "Crafting a Thing", + "grid_size": "small", + "grid": [ + [ + { + "id": "minecraft:stick" + }, + { + "id": "minecraft:planks" + } + ], + [ + { + "id": "minecraft:planks" + }, + { + "id": "minecraft:stick" + } + ] + ], + "result": { + "id": "tconstruct:stencil" + }, + "description": [ + { + "text": "This item does stuff and, of course, " + }, + { + "text": "things.", + "underlined": true + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmelting.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmelting.json new file mode 100644 index 0000000..c8b7d86 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmelting.json @@ -0,0 +1,14 @@ +{ + "title": "Smelting a Thing", + "input": { + "id": "minecraft:iron_ore" + }, + "result": { + "id": "minecraft:iron_ingot" + }, + "description": [ + { + "text": "Very delicious iron." + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmithing.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmithing.json new file mode 100644 index 0000000..a6795a0 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagesmithing.json @@ -0,0 +1,33 @@ +{ + "title": "Smithing a Thing", + "input": { + "id": "minecraft:diamond_sword" + }, + "modifier": { + "id": "minecraft:enchanted_book", + "nbt": { + "ench": [ + { + "id": 16, + "lvl": 5 + } + ] + } + }, + "result": { + "id": "minecraft:diamond_sword", + "nbt": { + "ench": [ + { + "id": 16, + "lvl": 5 + } + ] + } + }, + "description": [ + { + "text": "Ow, that's sharp." + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagestructure.json b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagestructure.json new file mode 100644 index 0000000..12a2159 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/en_US/section1/pagestructure.json @@ -0,0 +1,3 @@ +{ + "data": "structures/netherportal.json" +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/images/test.png b/src/main/resources/assets/mantle/books/TestBook/images/test.png new file mode 100644 index 0000000..1ece863 Binary files /dev/null and b/src/main/resources/assets/mantle/books/TestBook/images/test.png differ diff --git a/src/main/resources/assets/mantle/books/TestBook/index.json b/src/main/resources/assets/mantle/books/TestBook/index.json new file mode 100644 index 0000000..863cd00 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/index.json @@ -0,0 +1,32 @@ +[ + { + "name": "test section", + "icon": { + "file": "images/test.png" + }, + "data": "sections/section1.json" + }, + { + "name": "section 2", + "icon": { + "file": "images/test.png" + }, + "data": "sections/section1.json", + "requirements": [ + "achievement.buildHoe", + "achievement.makeBread" + ] + }, + { + "name": "section 3", + "title": "Hidden Section", + "icon": { + "file": "images/test.png" + }, + "data": "sections/section1.json", + "requirements": [ + "achievement.mineWood" + ], + "hideWhenLocked": true + } +] \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/items.json b/src/main/resources/assets/mantle/books/TestBook/items.json new file mode 100644 index 0000000..c1845d2 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/items.json @@ -0,0 +1,10 @@ +[ + { + "item": { + "id": "minecraft:golden_apple", + "damage": 1 + }, + "damageSensitive": true, + "action": "go-to-page-rtn:test section.page5" + } +] \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/items/records.json b/src/main/resources/assets/mantle/books/TestBook/items/records.json new file mode 100644 index 0000000..df667bf --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/items/records.json @@ -0,0 +1,41 @@ +{ + "items": [ + { + "id": "record_13" + }, + { + "id": "record_cat" + }, + { + "id": "record_blocks" + }, + { + "id": "record_chirp" + }, + { + "id": "record_far" + }, + { + "id": "record_mall" + }, + { + "id": "record_mellohi" + }, + { + "id": "record_stal" + }, + { + "id": "record_strad" + }, + { + "id": "record_ward" + }, + { + "id": "record_11" + }, + { + "id": "record_wait" + } + ], + "action": "go-to-page-rtn:test section.page5" +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/sections/section1.json b/src/main/resources/assets/mantle/books/TestBook/sections/section1.json new file mode 100644 index 0000000..2b4cc49 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/sections/section1.json @@ -0,0 +1,66 @@ +[ + { + "name": "Page1", + "type": "blank" + }, + { + "name": "PageCrafter", + "type": "crafting", + "data": "section1/pagecrafting.json" + }, + { + "name": "PageSmallCrafter", + "type": "crafting", + "data": "section1/pagecraftingsmall.json" + }, + { + "name": "PageSmelting", + "type": "smelting", + "data": "section1/pagesmelting.json" + }, + { + "name": "PageSmithing", + "type": "smithing", + "data": "section1/pagesmithing.json" + }, + { + "name": "PageBlockInteraction", + "type": "block interaction", + "data": "section1/pageblkinteraction.json" + }, + { + "name": "PageStructure", + "type": "structure", + "data": "section1/pagestructure.json" + }, + { + "name": "Page2", + "type": "text", + "data": "section1/page2.json" + }, + { + "name": "Page3", + "type": "image", + "data": "section1/page3.json" + }, + { + "name": "Page4", + "type": "image with text below", + "data": "section1/page4_5.json" + }, + { + "name": "Page5", + "type": "text with image below", + "data": "section1/page4_5.json" + }, + { + "name": "Page6", + "type": "text with left image etch", + "data": "section1/page6_7.json" + }, + { + "name": "Page7", + "type": "text with right image etch", + "data": "section1/page6_7.json" + } +] \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/structures/netherportal.json b/src/main/resources/assets/mantle/books/TestBook/structures/netherportal.json new file mode 100644 index 0000000..60f2b69 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/structures/netherportal.json @@ -0,0 +1,31 @@ +{ + "size": [4, 5, 1], + "structure": [ + { + "pos": [0, 0, 0], + "endPos": [3, 0, 0], + "block": "minecraft:obsidian" + }, + { + "pos": [0, 0, 0], + "endPos": [0, 4, 0], + "block": "minecraft:obsidian" + }, + { + "pos": [3, 0, 0], + "endPos": [3, 4, 0], + "block": "minecraft:obsidian" + }, + { + "pos": [0, 4, 0], + "endPos": [3, 4, 0], + "block": "minecraft:obsidian" + }, + { + "pos": [1, 1, 0], + "endPos": [2, 3, 0], + "block": "minecraft:portal", + "meta": 2 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/books/TestBook/structures/stonesmeltery.json b/src/main/resources/assets/mantle/books/TestBook/structures/stonesmeltery.json new file mode 100644 index 0000000..44e7727 --- /dev/null +++ b/src/main/resources/assets/mantle/books/TestBook/structures/stonesmeltery.json @@ -0,0 +1,40 @@ +{ + "size": [5, 3, 5], + "structure": [ + { + "pos": [1, 0, 1], + "endPos": [3, 0, 3], + "block": "minecraft:stone" + }, + { + "pos": [1, 1, 4], + "endPos": [4, 2, 4], + "block": "minecraft:stone" + }, + { + "pos": [0, 1, 1], + "endPos": [0, 2, 4], + "block": "minecraft:stone" + }, + { + "pos": [4, 1, 1], + "endPos": [4, 2, 4], + "block": "minecraft:stone" + }, + { + "pos": [1, 1, 0], + "endPos": [4, 2, 0], + "block": "minecraft:stone" + }, + { + "pos": [0, 2, 0], + "block": "minecraft:stone", + "meta": 6 + }, + { + "pos": [0, 3, 0], + "block": "minecraft:stone", + "meta": 4 + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/mantle/manuals/test.xml b/src/main/resources/assets/mantle/manuals/test.xml deleted file mode 100644 index 639fadb..0000000 --- a/src/main/resources/assets/mantle/manuals/test.xml +++ /dev/null @@ -1,165 +0,0 @@ - - - - -Tinker's Log #1: - -Today is a new day. I finally left home and decided to wander around in the wilderness until I find a good place to call my home. - -Tinker's Log #2: - -I've decided to keep a log of my creations and machinations, as well as some insights into what I'm doing. I haven't actually built anything yet. There is a small cave I can board up for the night. I created a stone pickaxe affectionately called "Betsy". - - - -Tinker's Log #3: - -The night is scary. Creepers are everywhere, the zombies are banging on my door, bats block out the sky... it is not fun being alone out here. I want to hide in the corner and cry until they leave. This log doesn't help take my mind off of anything. - -Tinker's Log #4: - -Betsy didn't last long. She just crumpled into dust suddenly and the handle shattered. My parents told me this would happen and this was normal, but it still seems so wrong. If I could make the pickaxe a little better perhaps, maybe I could repair it. - - - -Tinker's Log #5: - -I've spent the past three days looking for paper and ink. Squids were easy enough to find, but the sugar cane was buried deep in a ravine next to a creeper nest. Eventually I dropped rocks on the creepers and watched them explode out of surprise. My eyebrow will grow back in time. - -Tinker's Log #6: - -Waiting on sugar cane to grow. Not much else today. - - - -Tinker's Log #7: - -I've sketched out plans for a new workbench. It's a little strange. The center of the workbench is missing, but sturdy, and there are grooves in the top for supplies. I think I will call it a "table". - -Tinker's Log #8: - -I made a few more tables with different patterns in them. They look useful for different things, so I put different materials and tools by each one. Perhaps I will come up with a use for them in time. - - - -Tinker's Log #9: - -To make tools, you need to know what you're making. The pickaxe and shovel are easy enough to make with practice, the best crafters in my village told me, but I can't seem to make any good ones. Out of frustration I punched a hole in a wooden board. And another. And a few more. By the end I had something that resembled an axe, and that gave me a few ideas... - - - -Tinker's Log #10: - -I punched holes in a few boards carefully in different shapes. I spent a lot of time making them, so they look really good. They all resemble the parts of tools that I can remember: heads, handles, bindings, pieces, and some others. They look really useful, so I placed them by a table for later. - - - -Tinker's Log #11: - -I grabbed a few of the boards and started to make tool parts using them as an outline. The parts themselves feel sturdy, and when I put them together the end result felt a lot better than Betsy did. They're made completely out of stone, something even the finest crafters could never manage. This feels like a great accomplishment. - -Tinker's Log #12: - -Perhaps making a tool completely out of stone wasn't the best idea. It didn't last very long. On the upside, instead of shattering into dust only the tip scratched off. I glued a new tip on the head and it seemed good as new. - - - -Tinker's Log #13: - -I wanted to make a few more tools, but the boards with tool shapes in them went everywhere! I ended up breaking a few out of frustration. They don't fit very well in my chest either. I took a few of them, added a few slots to the bottom of the chest, placed it by my table and called it good. - -I also named them "Patterns", the chest a "Pattern Chest". I'm still angry at them, and it took so long to make new ones... - - - -Tinker's Log #14 - -Today I learned just how hard it was to shape iron. First you have to dig it out of the earth. A wooden pickaxe will shatter the ore; this I found out the hard way. Once you do get that ore there isn't much to do with it besides throw it in the furnace. Melting the iron and the stone seems inefficient, but I do need the metal more than I care about the waste. - -I shaped a few of the bars into tools, and they felt strong. Much stronger, in fact, than the ones back at the village. I've named the pickaxe "Krug" after some of the stories Nana used to tell me at night. How I miss her... - - - -Tinker's Log #15: - -This place holds little for me now. I've packed up my things, grabbed what resources I can carry, and set off. The tables and patterns will have to stay behind. I can't possibly carry them with all the food I have. - -Tinker's Log #16: - -A week later and I've finally found some others to visit. Some of them seem nice, most don't look like me. A few of them have things I never could have dreamed of. They've pointed me at a patch of land that was quiet and secluded. There I should be able to work, for I have ideas from the journey. - - - -Tinker's Log #17: - -After three days and nights of fending off zombies, I've finally created a house. It has a few rooms, a basement, but most importantly a workshop. All of the tables and patterns I had before are here, as well as a few others I wanted to try out from the trip. - -There's a round one I can cook food with and one that's just as good as any hoe, but can chop trees or actually dig the ground up. The villagers tell me these are named "Frying Pan" and "Mattock". The Frying Pan seems heavy enough to smack creepers with. I have a sword named "Shimmer" that I want to alter somehow. - - - -Tinker's Log #18: - -One of the villagers was kind enough to give me some random things. Each one looks useful in their own right. I was lucky enough to find a few diamonds earlier, and I have a few more tools in storage. This should be fun. - - - -Tinker's Log #19: - -After some heavy experimentation, I've ended up with some things that look amazing and others that look less useful than they actually are. A diamond tip on a pickaxe makes for a wondefully hard mining tool, and an emerald on a sword hilt somehow makes it stay together longer, but some things don't do anything. - -Adding flowers to a tool does nothing; they don't even stay on the thing. Mushrooms have a similar effect, and adding more material to a tool just makes it heavier. You wouldn't think redstone would do anything. I've coated a shovel so much that it looks deep red. However, it slides through dirt as if the dirt wasn't there. - - - -Moss is also a strange one. Somehow it seems to be healing the tool, even to the point where it looks like new. - -Tinker's Log #20: - -I tried to make some tools out of gold, like the crafters in my village used to, but instead it broke the table. Some of the villages laughed at me for such an idea... if only they knew. - - - -Tinker's Log #21: - -Some of these tools are more useful than I thought. Adding blaze powder to a weapon seems to give it some kind of burning effect. Lapis has this strange quality of being able to find more materials in the same area, even if I know exactly what I'm looking at. - -Tinker's Log #22: - -I have some ideas for creating tools, but for that I need a large place to create them. The furnace is inadequate, and I need a lot of stone. Combining lava with coal and netherrack seems to instantly cook stone as I mine it, up to the point where I can bypass the furnace entirely. - - - -Tinker's Log #23: - -Today I made something strange. It's round, wooden, and doesn't look like anything I've ever seen. Someone came by and said it was a "wheel" and that they were great fun to roll around. I wonder what else it could be used for? - -Tinker's Log #24: - -I made a few more of the wheels to get some practice in. I had some fun rolling them around, rolling them in pairs, and then one ended up beside my boat. It just looked so natural I had to start putting them together. - - - -Tinker's Log #25: - -I think I'm on to something here. Combining the boat with the wheel made it work something like a minecart, only I can pull it around places. It feels a little small though. - -Tinker's Log #26: - -I have all these tools laying around with little notes on what each one does. Instead of leaving them scattered about, I think I will create one place to store them. - - -Tinker's Log #27: - -I went exploring and found some new ores today. They're colors I've never seen before, and they don't shatter on impact like iron does. I wonder what I can do with these? - -Tinker's Log #28: - -The normal furnace is nice for keeping warm, but it leaves something to be desired for processing metal. I've dug a pit and lined it with some clay, gathered lava nearby, and put ore in the center in an attempt to improve on the design. The results were quite interesting. - - -The more lava I fed into the pit the hotter the material became. Eventually the whole thing liquified. I broke open the side of the pit with a cauldron in an attempt to catch the material, but it went everywhere. There were some remnants left in the pit as well. - -Raw ore still has parts of stone in it. There must be a way to remove the excess. - - \ No newline at end of file diff --git a/src/main/resources/assets/mantle/textures/gui/book.png b/src/main/resources/assets/mantle/textures/gui/book.png deleted file mode 100644 index c9007bd..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/book.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/book/book.png b/src/main/resources/assets/mantle/textures/gui/book/book.png new file mode 100644 index 0000000..f1a414f Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/book/book.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/book/bookfront.png b/src/main/resources/assets/mantle/textures/gui/book/bookfront.png new file mode 100644 index 0000000..6e68fda Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/book/bookfront.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/book/crafting.png b/src/main/resources/assets/mantle/textures/gui/book/crafting.png new file mode 100644 index 0000000..cd1478d Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/book/crafting.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/book/misc.png b/src/main/resources/assets/mantle/textures/gui/book/misc.png new file mode 100644 index 0000000..f4e5876 Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/book/misc.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/book/smelting.png b/src/main/resources/assets/mantle/textures/gui/book/smelting.png new file mode 100644 index 0000000..8c3600f Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/book/smelting.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/bookcrafting.png b/src/main/resources/assets/mantle/textures/gui/bookcrafting.png deleted file mode 100644 index e9ee759..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/bookcrafting.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/bookfurnace.png b/src/main/resources/assets/mantle/textures/gui/bookfurnace.png deleted file mode 100644 index cda94fb..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/bookfurnace.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/bookleft.png b/src/main/resources/assets/mantle/textures/gui/bookleft.png deleted file mode 100644 index 08b462d..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/bookleft.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/bookright.png b/src/main/resources/assets/mantle/textures/gui/bookright.png deleted file mode 100644 index 8c255a7..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/bookright.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/box.png b/src/main/resources/assets/mantle/textures/gui/box.png new file mode 100644 index 0000000..aeae336 Binary files /dev/null and b/src/main/resources/assets/mantle/textures/gui/box.png differ diff --git a/src/main/resources/assets/mantle/textures/gui/tinkerbook_blue.png b/src/main/resources/assets/mantle/textures/gui/tinkerbook_blue.png deleted file mode 100644 index 8a1fe83..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/tinkerbook_blue.png and /dev/null differ diff --git a/src/main/resources/assets/mantle/textures/gui/tinkerbook_green.png b/src/main/resources/assets/mantle/textures/gui/tinkerbook_green.png deleted file mode 100644 index e73dd2b..0000000 Binary files a/src/main/resources/assets/mantle/textures/gui/tinkerbook_green.png and /dev/null differ