diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookScreen.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookScreen.java index 945171a..57a3523 100644 --- a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookScreen.java +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookScreen.java @@ -1,5 +1,6 @@ package cassunshine.thework.client.gui.ingame.notebook; +import cassunshine.thework.client.gui.ingame.notebook.pages.AlchemistNotebookPage; import cassunshine.thework.client.networking.TheWorkClientNetworking; import cassunshine.thework.rendering.items.AlchemistNotebookRenderer; import net.minecraft.client.gui.DrawContext; @@ -36,7 +37,7 @@ public void nextPage() { var nbt = stack.getOrCreateNbt(); var page = nbt.getInt("current_page"); - page = MathHelper.clamp(page + 1, 0, (pages.size() / 2)); + page = MathHelper.clamp(page + 1, 0, MathHelper.ceil(pages.size() / 2.0f) - 1); nbt.putInt("current_page", page); syncNbt(); @@ -82,8 +83,8 @@ protected void init() { int centerX = MathHelper.floor(width / 2.0f); int centerY = MathHelper.floor(height / 2.0f); - int pageHeight = MathHelper.floor(height * 0.9f); - int pageWidth = MathHelper.floor(pageHeight * 0.5f); + int pageHeight = 64 * MathHelper.floor((height - 50) / 64.0f); + int pageWidth = MathHelper.floor(pageHeight * 0.75f); int heightDifference = MathHelper.floor(height - pageHeight); @@ -121,8 +122,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { int centerX = MathHelper.floor(width / 2.0f); int centerY = MathHelper.floor(height / 2.0f); - int pageHeight = MathHelper.floor(height * 0.9f); - int pageWidth = MathHelper.floor(pageHeight * 0.5f); + int pageHeight = 64 * MathHelper.floor((height - 50) / 64.0f); + int pageWidth = MathHelper.floor(pageHeight * 0.75f); int heightDifference = MathHelper.floor(height - pageHeight); @@ -131,15 +132,16 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { AlchemistNotebookPage pageLeft = pages.get(currentPage); AlchemistNotebookPage pageRight = currentPage + 1 >= pages.size() ? null : pages.get(currentPage + 1); - context.drawTexture(AlchemistNotebookRenderer.BOOK_TEXTURE, centerX - pageWidth, heightDifference / 2, pageWidth, pageHeight, 8, 16, 8, 16, 32, 32); - context.drawTexture(AlchemistNotebookRenderer.BOOK_TEXTURE, centerX, heightDifference / 2, pageWidth, pageHeight, 8, 16, 8, 16, 32, 32); + context.drawTexture(AlchemistNotebookRenderer.BOOK_TEXTURE, centerX - pageWidth, heightDifference / 2, pageWidth, pageHeight, 0, 0, 48, 64, 144, 64); + context.drawTexture(AlchemistNotebookRenderer.BOOK_TEXTURE, centerX, heightDifference / 2, pageWidth, pageHeight, 0, 0, 48, 64, 144, 64); + if (pageLeft != null && pageLeft.drawing != null) { - context.drawTexture(pageLeft.drawing, centerX - pageWidth, heightDifference / 2, pageWidth, pageHeight, 0, 0, 128, 256, 128, 256); + context.drawTexture(pageLeft.drawing, centerX - pageWidth, heightDifference / 2, pageWidth, pageHeight, 0, 0, 192, 256, 192, 256); } if (pageRight != null && pageRight.drawing != null) { - context.drawTexture(pageRight.drawing, centerX, heightDifference / 2, pageWidth, pageHeight, 0, 0, 128, 256, 128, 256); + context.drawTexture(pageRight.drawing, centerX, heightDifference / 2, pageWidth, pageHeight, 0, 0, 192, 256, 192, 256); } if (pageLeft != null) @@ -147,7 +149,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { if (pageRight != null) pageRight.render(this, context, mouseX, mouseY, delta); - super.render(context, mouseX, mouseY, delta); } diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/ItemDisplay.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/ItemDisplay.java new file mode 100644 index 0000000..e8a1827 --- /dev/null +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/ItemDisplay.java @@ -0,0 +1,54 @@ +package cassunshine.thework.client.gui.ingame.notebook.drawables; + +import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.render.DiffuseLighting; +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.item.ItemStack; +import org.joml.Matrix4f; + +public class ItemDisplay implements Drawable { + public int x; + public int y; + + public ItemStack stack = ItemStack.EMPTY; + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + + if (stack.isEmpty()) + return; + + var matrices = context.getMatrices(); + var client = MinecraftClient.getInstance(); + + BakedModel bakedModel = client.getItemRenderer().getModel(stack, client.world, client.player, 0); + matrices.push(); + matrices.translate((float) (x), (float) (y), (float) (150)); + + try { + matrices.multiplyPositionMatrix((new Matrix4f()).scaling(1.0F, -1.0F, 1.0F)); + matrices.scale( 48 / (float) client.getWindow().getScaleFactor(), 48 / (float) client.getWindow().getScaleFactor(), 48 / (float) client.getWindow().getScaleFactor()); + boolean bl = !bakedModel.isSideLit(); + if (bl) { + DiffuseLighting.disableGuiDepthLighting(); + } + + client.getItemRenderer().renderItem(stack, ModelTransformationMode.GUI, false, matrices, context.getVertexConsumers(), 15728880, OverlayTexture.DEFAULT_UV, bakedModel); + RenderSystem.disableDepthTest(); + context.getVertexConsumers().draw(); + RenderSystem.enableDepthTest(); + if (bl) { + DiffuseLighting.enableGuiDepthLighting(); + } + } catch (Throwable var12) { + //Ignore. + } + + matrices.pop(); + } +} diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/RandomItemDisplay.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/RandomItemDisplay.java new file mode 100644 index 0000000..9c64be2 --- /dev/null +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/drawables/RandomItemDisplay.java @@ -0,0 +1,27 @@ +package cassunshine.thework.client.gui.ingame.notebook.drawables; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.item.ItemStack; +import net.minecraft.registry.Registries; + +import java.util.Random; + +public class RandomItemDisplay extends ItemDisplay { + + private static final Random random = new Random(); + private float changeCooldown = 0f; + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + changeCooldown -= delta; + + if (changeCooldown <= 0) { + var randomItem = Registries.ITEM.get(random.nextInt(Registries.ITEM.size())); + stack = new ItemStack(randomItem); + + changeCooldown = 10f; + } + + super.render(context, mouseX, mouseY, delta); + } +} diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookNodePage.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookNodePage.java similarity index 95% rename from src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookNodePage.java rename to src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookNodePage.java index bb037bc..80aa5da 100644 --- a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookNodePage.java +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookNodePage.java @@ -1,26 +1,23 @@ -package cassunshine.thework.client.gui.ingame.notebook; +package cassunshine.thework.client.gui.ingame.notebook.pages; import cassunshine.thework.TheWorkMod; import cassunshine.thework.alchemy.runes.TheWorkRunes; +import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookScreen; import cassunshine.thework.client.gui.ingame.notebook.drawables.NodeDrawer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ButtonTextures; -import net.minecraft.client.gui.screen.GameModeSelectionScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TextWidget; import net.minecraft.client.gui.widget.TexturedButtonWidget; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.text.OrderedText; -import net.minecraft.text.StringVisitable; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import java.util.Objects; - public class AlchemistNotebookNodePage extends AlchemistNotebookPage { public static final Identifier IDENTIFIER = new Identifier(TheWorkMod.ModID, "node_page"); @@ -45,7 +42,7 @@ public AlchemistNotebookNodePage() { } @Override - protected void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { + public void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { super.init(screen, x, y, width, height); var nbt = screen.stack.getOrCreateNbt(); @@ -123,7 +120,8 @@ protected void init(AlchemistNotebookScreen screen, int x, int y, int width, int drawnNode.size = MathHelper.floor(width * 0.6f); drawnNode.x = x + width / 2; - drawnNode.y = y + 100; + drawnNode.y = y + height / 3; + circleSidesLeftButton.setX(drawnNode.x - circleSidesLeftButton.getWidth()); circleSidesLeftButton.setY(drawnNode.y + drawnNode.size / 2 + 5); diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookPage.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookPage.java similarity index 54% rename from src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookPage.java rename to src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookPage.java index 17a9072..fb3888e 100644 --- a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/AlchemistNotebookPage.java +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/AlchemistNotebookPage.java @@ -1,7 +1,7 @@ -package cassunshine.thework.client.gui.ingame.notebook; +package cassunshine.thework.client.gui.ingame.notebook.pages; import cassunshine.thework.TheWorkMod; -import cassunshine.thework.client.networking.TheWorkClientNetworking; +import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookScreen; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.item.ItemStack; @@ -13,15 +13,27 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.function.Function; +import java.util.function.Supplier; public class AlchemistNotebookPage extends Screen { public static final Identifier IDENTIFIER = new Identifier(TheWorkMod.ModID, "basic"); - private static final HashMap> GENERATORS = new HashMap<>() {{ + private static final HashMap> NBT_GENERATORS = new HashMap<>() {{ put(IDENTIFIER, AlchemistNotebookPage::new); + }}; + + private static final HashMap> GENERATORS = new HashMap<>() {{ put(AlchemistNotebookNodePage.IDENTIFIER, AlchemistNotebookNodePage::new); + put(LegendNotebookPage.IDENTIFIER, LegendNotebookPage::new); + put(DeconstructTutorialPage.IDENTIFIER, DeconstructTutorialPage::new); }}; + public static final Identifier[] DEFAULT_PAGES = new Identifier[]{ + AlchemistNotebookNodePage.IDENTIFIER, + LegendNotebookPage.IDENTIFIER, + DeconstructTutorialPage.IDENTIFIER + }; + public Identifier typeId; public Identifier drawing; @@ -37,7 +49,7 @@ public AlchemistNotebookPage(Identifier id, Identifier drawing) { this.drawing = drawing; } - protected void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { + public void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { } @@ -61,46 +73,38 @@ public void readNbt(NbtCompound nbt) { } public static ArrayList getPages(ItemStack stack) { + var nbt = stack.getOrCreateNbt(); - if (!stack.hasNbt()) { - var nbt = stack.getOrCreateNbt(); - - nbt.putInt("current_page", 0); - - var list = new ArrayList() {{ - add(new AlchemistNotebookNodePage()); - add(new AlchemistNotebookPage(IDENTIFIER, new Identifier(TheWorkMod.ModID, "textures/pages/page-basics.png"))); - add(new AlchemistNotebookPage(IDENTIFIER, new Identifier(TheWorkMod.ModID, "textures/pages/page-runes.png"))); - }}; - - nbt.put("pages", pagesToNbt(list)); - - TheWorkClientNetworking.updateBook(nbt); - return list; - } else { - var nbt = stack.getOrCreateNbt(); + var nbtList = nbt.getList("pages", NbtElement.COMPOUND_TYPE); + var list = new ArrayList(); - var nbtList = nbt.getList("pages", NbtElement.COMPOUND_TYPE); - var list = new ArrayList(); - - for (int i = 0; i < nbtList.size(); i++) { - var compound = nbtList.getCompound(i); - var type = new Identifier(compound.getString("type")); + for (Identifier page : DEFAULT_PAGES) { + var factoryResult = GENERATORS.get(page).get(); + list.add(factoryResult); + } - var factoryResult = GENERATORS.get(type).apply(compound); - list.add(factoryResult); - } + for (int i = 0; i < nbtList.size(); i++) { + var compound = nbtList.getCompound(i); + var type = new Identifier(compound.getString("type")); - return list; + var factoryResult = NBT_GENERATORS.get(type).apply(compound); + list.add(factoryResult); } + + return list; } public static NbtList pagesToNbt(ArrayList pages) { var list = new NbtList(); - for (AlchemistNotebookPage page : pages) + for (int i = 0; i < pages.size(); i++) { + if (i < DEFAULT_PAGES.length) + continue; + + AlchemistNotebookPage page = pages.get(i); list.add(page.writeNbt(new NbtCompound())); + } return list; } diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/DeconstructTutorialPage.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/DeconstructTutorialPage.java new file mode 100644 index 0000000..679f442 --- /dev/null +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/DeconstructTutorialPage.java @@ -0,0 +1,43 @@ +package cassunshine.thework.client.gui.ingame.notebook.pages; + +import cassunshine.thework.TheWorkMod; +import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookScreen; +import cassunshine.thework.client.gui.ingame.notebook.drawables.ItemDisplay; +import net.minecraft.block.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; + +public class DeconstructTutorialPage extends AlchemistNotebookPage { + + public static final Identifier IDENTIFIER = new Identifier(TheWorkMod.ModID, "deconstruct_tutorial"); + public static final Identifier PAGE_TEXTURE = new Identifier(TheWorkMod.ModID, "textures/pages/deconstruct_tutorial.png"); + + public DeconstructTutorialPage(NbtCompound compound) { + super(compound); + } + + public DeconstructTutorialPage() { + super(IDENTIFIER, PAGE_TEXTURE); + } + + @Override + public void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { + super.init(screen, x, y, width, height); + + var itemDisplay = new ItemDisplay(); + itemDisplay.x = x + MathHelper.floor(width * (14.5f / 96.0f)); + itemDisplay.y = y + MathHelper.floor(height * (38.5f / 128.0f)); + itemDisplay.stack = new ItemStack(Blocks.DIRT.asItem()); + + screen.addDrawable(itemDisplay); + + itemDisplay = new ItemDisplay(); + itemDisplay.x = x + MathHelper.floor(width * (14.5f / 96.0f)); + itemDisplay.y = y + MathHelper.floor(height * (54.5f / 128.0f)); + itemDisplay.stack = new ItemStack(Blocks.STONE.asItem()); + + screen.addDrawable(itemDisplay); + } +} \ No newline at end of file diff --git a/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/LegendNotebookPage.java b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/LegendNotebookPage.java new file mode 100644 index 0000000..cbbdfb4 --- /dev/null +++ b/src/client/java/cassunshine/thework/client/gui/ingame/notebook/pages/LegendNotebookPage.java @@ -0,0 +1,33 @@ +package cassunshine.thework.client.gui.ingame.notebook.pages; + +import cassunshine.thework.TheWorkMod; +import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookScreen; +import cassunshine.thework.client.gui.ingame.notebook.drawables.RandomItemDisplay; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; + +public class LegendNotebookPage extends AlchemistNotebookPage { + + public static final Identifier IDENTIFIER = new Identifier(TheWorkMod.ModID, "legend"); + public static final Identifier PAGE_TEXTURE = new Identifier(TheWorkMod.ModID, "textures/pages/legend.png"); + + public LegendNotebookPage(NbtCompound compound) { + super(compound); + } + + public LegendNotebookPage() { + super(IDENTIFIER, PAGE_TEXTURE); + } + + @Override + public void init(AlchemistNotebookScreen screen, int x, int y, int width, int height) { + super.init(screen, x, y, width, height); + + var randomItemDisplay = new RandomItemDisplay(); + randomItemDisplay.x = x + MathHelper.floor(width * 0.61); + randomItemDisplay.y = y + MathHelper.floor(height * 0.61); + + screen.addDrawable(randomItemDisplay); + } +} diff --git a/src/client/java/cassunshine/thework/rendering/blockentities/alchemy_block/AlchemyCircleBlockEntityRenderer.java b/src/client/java/cassunshine/thework/rendering/blockentities/alchemy_block/AlchemyCircleBlockEntityRenderer.java index 91f865f..746b4a1 100644 --- a/src/client/java/cassunshine/thework/rendering/blockentities/alchemy_block/AlchemyCircleBlockEntityRenderer.java +++ b/src/client/java/cassunshine/thework/rendering/blockentities/alchemy_block/AlchemyCircleBlockEntityRenderer.java @@ -85,6 +85,7 @@ public void render(AlchemyCircleBlockEntity entity, float tickDelta, MatrixStack TheWorkMod.LOGGER.error(e.toString()); } + RenderingUtilities.setupWobble(0); RenderingUtilities.popMat(); } } diff --git a/src/client/java/cassunshine/thework/rendering/items/AlchemistNotebookRenderer.java b/src/client/java/cassunshine/thework/rendering/items/AlchemistNotebookRenderer.java index 885c588..b9818ea 100644 --- a/src/client/java/cassunshine/thework/rendering/items/AlchemistNotebookRenderer.java +++ b/src/client/java/cassunshine/thework/rendering/items/AlchemistNotebookRenderer.java @@ -1,7 +1,7 @@ package cassunshine.thework.rendering.items; import cassunshine.thework.TheWorkMod; -import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookPage; +import cassunshine.thework.client.gui.ingame.notebook.pages.AlchemistNotebookPage; import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookScreen; import cassunshine.thework.rendering.util.RenderingUtilities; import cassunshine.thework.utils.TheWorkUtils; @@ -71,7 +71,7 @@ public static void renderItem(ItemStack stack, ModelTransformationMode modelTran bookAngle = 0.9f; RenderingUtilities.translateMatrix(0.5f, 0.48f, 0.55f); - RenderingUtilities.scaleMatrix(0.6f, 0.6f, 0.6f); + RenderingUtilities.scaleMatrix(0.5f, 0.5f, 0.5f); break; } @@ -82,9 +82,9 @@ public static void renderItem(ItemStack stack, ModelTransformationMode modelTran RenderingUtilities.setupNormal(0, 1, 0); - RenderingUtilities.scaleMatrix(0.8f, 0.8f, 0.8f); + RenderingUtilities.scaleMatrix(0.7f, 0.7f, 0.7f); - RenderingUtilities.translateMatrix(0.7f, 0.05f, 0); + RenderingUtilities.translateMatrix(0.6f, 0.2f, 0); RenderingUtilities.rotateMatrix(0, MathHelper.HALF_PI, 0); RenderingUtilities.setupLightOverlay(LightmapTextureManager.MAX_BLOCK_LIGHT_COORDINATE, overlay); @@ -129,18 +129,18 @@ public static void renderBook(float bookAngle, boolean useNormals, boolean drawP if (useNormals) RenderingUtilities.setupNormal(1, 0, 0); - RenderingUtilities.saneVertex(0, 1, 0, 0 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0.5f, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 0, 0.5f, 8 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 0, 0, 0 / TEXTURE_SIZE, 0); + RenderingUtilities.saneVertex(0, 1, 0, 1 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 1, 0.75f, 2 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 0, 0.75f, 2 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 0, 0, 1 / 3.0f, 1); if (useNormals) RenderingUtilities.setupNormal(-1, 0, 0); - RenderingUtilities.saneVertex(0, 0, 0, 0 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 0, 0.5f, 8 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 1, 0.5f, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0, 0 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); + RenderingUtilities.saneVertex(0, 0, 0, 3 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 0, 0.75f, 2 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 1, 0.75f, 2 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 1, 0, 1 / 3.0f, 0); RenderingUtilities.popMat(); } @@ -152,18 +152,18 @@ public static void renderBook(float bookAngle, boolean useNormals, boolean drawP if (useNormals) RenderingUtilities.setupNormal(-1, 0, 0); - RenderingUtilities.saneVertex(0, 0, 0, 8 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 0, 0.5f, 16 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 1, 0.5f, 16 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); + RenderingUtilities.saneVertex(0, 0, 0, 2 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 0, 0.75f, 3 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 1, 0.75f, 3 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 1, 0, 2 / 3.0f, 0); if (useNormals) RenderingUtilities.setupNormal(1, 0, 0); - RenderingUtilities.saneVertex(0, 1, 0, 0 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0.5f, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 0, 0.5f, 8 / TEXTURE_SIZE, 0); - RenderingUtilities.saneVertex(0, 0, 0, 0 / TEXTURE_SIZE, 0); + RenderingUtilities.saneVertex(0, 1, 0, 1 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 1, 0.75f, 2 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 0, 0.75f, 2 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 0, 0, 1 / 3.0f, 0); RenderingUtilities.popMat(); } @@ -230,17 +230,17 @@ private static void drawPage(boolean useNormals, float leftAngle, float rightAng RenderingUtilities.rotateMatrix(0, leftAngle, 0); RenderingUtilities.setupRenderLayer(RenderLayer.getEntityCutout(BOOK_TEXTURE)); - RenderingUtilities.saneVertex(0, 1, 0, 8 / TEXTURE_SIZE, 32 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0.5f, 16 / TEXTURE_SIZE, 32 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 0, 0.5f, 16 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 0, 0, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); + RenderingUtilities.saneVertex(0, 1, 0, 0, 1); + RenderingUtilities.saneVertex(0, 1, 0.75f, 1 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 0, 0.75f, 1 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 0, 0, 0, 0); if (left != null && left.drawing != null) { RenderingUtilities.setupRenderLayer(RenderLayer.getEntityCutout(left.drawing)); RenderingUtilities.saneVertex(0.001f, 1, 0, 1, 0); - RenderingUtilities.saneVertex(0.001f, 1, 0.5f, 0, 0); - RenderingUtilities.saneVertex(0.001f, 0, 0.5f, 0, 1); + RenderingUtilities.saneVertex(0.001f, 1, 0.75f, 0, 0); + RenderingUtilities.saneVertex(0.001f, 0, 0.75f, 0, 1); RenderingUtilities.saneVertex(0.001f, 0, 0, 1, 1); } @@ -257,18 +257,18 @@ private static void drawPage(boolean useNormals, float leftAngle, float rightAng RenderingUtilities.rotateMatrix(0, rightAngle, 0); RenderingUtilities.setupRenderLayer(RenderLayer.getEntityCutout(BOOK_TEXTURE)); - RenderingUtilities.saneVertex(0, 0, 0, 8 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 0, 0.5f, 16 / TEXTURE_SIZE, 16 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0.5f, 16 / TEXTURE_SIZE, 32 / TEXTURE_SIZE); - RenderingUtilities.saneVertex(0, 1, 0, 8 / TEXTURE_SIZE, 32 / TEXTURE_SIZE); + RenderingUtilities.saneVertex(0, 0, 0, 0, 0); + RenderingUtilities.saneVertex(0, 0, 0.75f, 1 / 3.0f, 0); + RenderingUtilities.saneVertex(0, 1, 0.75f, 1 / 3.0f, 1); + RenderingUtilities.saneVertex(0, 1, 0, 0, 1); if (right != null && right.drawing != null) { RenderingUtilities.setupRenderLayer(RenderLayer.getEntityCutout(right.drawing)); RenderingUtilities.saneVertex(-0.001f, 0, 0, 0, 1); - RenderingUtilities.saneVertex(-0.001f, 0, 0.5f, 1, 1); - RenderingUtilities.saneVertex(-0.001f, 1, 0.5f, 1, 0); + RenderingUtilities.saneVertex(-0.001f, 0, 0.75f, 1, 1); + RenderingUtilities.saneVertex(-0.001f, 1, 0.75f, 1, 0); RenderingUtilities.saneVertex(-0.001f, 1, 0, 0, 0); } diff --git a/src/client/resources/assets/thework/textures/item/alchemist_notebook.png b/src/client/resources/assets/thework/textures/item/alchemist_notebook.png index 4743526..3739885 100644 Binary files a/src/client/resources/assets/thework/textures/item/alchemist_notebook.png and b/src/client/resources/assets/thework/textures/item/alchemist_notebook.png differ diff --git a/src/client/resources/assets/thework/textures/pages/deconstruct_tutorial.png b/src/client/resources/assets/thework/textures/pages/deconstruct_tutorial.png new file mode 100644 index 0000000..7721c42 Binary files /dev/null and b/src/client/resources/assets/thework/textures/pages/deconstruct_tutorial.png differ diff --git a/src/client/resources/assets/thework/textures/pages/legend.png b/src/client/resources/assets/thework/textures/pages/legend.png new file mode 100644 index 0000000..be873ba Binary files /dev/null and b/src/client/resources/assets/thework/textures/pages/legend.png differ diff --git a/src/client/resources/assets/thework/textures/pages/page-basics.png b/src/client/resources/assets/thework/textures/pages/page-basics.png deleted file mode 100644 index b753a0b..0000000 Binary files a/src/client/resources/assets/thework/textures/pages/page-basics.png and /dev/null differ diff --git a/src/client/resources/assets/thework/textures/pages/page-runes.png b/src/client/resources/assets/thework/textures/pages/page-runes.png deleted file mode 100644 index 7b256f3..0000000 Binary files a/src/client/resources/assets/thework/textures/pages/page-runes.png and /dev/null differ diff --git a/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircle.java b/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircle.java index fb9ea67..4e07aed 100644 --- a/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircle.java +++ b/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircle.java @@ -1,11 +1,11 @@ package cassunshine.thework.alchemy.circle; -import cassunshine.thework.TheWorkMod; import cassunshine.thework.alchemy.balance.BalanceUtils; import cassunshine.thework.alchemy.circle.events.circle.ActivateToggleEvent; import cassunshine.thework.alchemy.circle.events.circle.AddRingEvent; import cassunshine.thework.alchemy.circle.events.circle.AlchemyCircleSetColorEvent; -import cassunshine.thework.alchemy.circle.events.node.AlchemyNodeSetColorEvent; +import cassunshine.thework.alchemy.circle.layout.AlchemyCircleConstructLayout; +import cassunshine.thework.alchemy.circle.layout.AlchemyCircleResearchLayout; import cassunshine.thework.alchemy.circle.node.AlchemyNode; import cassunshine.thework.alchemy.circle.path.AlchemyLink; import cassunshine.thework.alchemy.circle.ring.AlchemyRing; @@ -44,6 +44,7 @@ public class AlchemyCircle implements AlchemyCircleComponent { public final ArrayList links = new ArrayList<>(); public AlchemyCircleConstructLayout constructNodeLayout; + public AlchemyCircleResearchLayout researchLayout; /** * Holds all the elements added by the circle's components when de-activating. Will spawn backfire entities to empty this. @@ -68,7 +69,7 @@ public AlchemyCircle(AlchemyCircleBlockEntity blockEntity) { public void regenerateLayouts() { constructNodeLayout = new AlchemyCircleConstructLayout(this); - + researchLayout = new AlchemyCircleResearchLayout(this); circleChaos = BalanceUtils.calculateCircleChaos(this); circleChaosSquare = circleChaos * circleChaos; @@ -229,6 +230,8 @@ public void activate() { ring.activate(); backfireCooldown = 20; + + researchLayout.activate(); } @Override diff --git a/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircleConstructLayout.java b/src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleConstructLayout.java similarity index 95% rename from src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircleConstructLayout.java rename to src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleConstructLayout.java index e27796a..ba962f4 100644 --- a/src/main/java/cassunshine/thework/alchemy/circle/AlchemyCircleConstructLayout.java +++ b/src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleConstructLayout.java @@ -1,5 +1,6 @@ -package cassunshine.thework.alchemy.circle; +package cassunshine.thework.alchemy.circle.layout; +import cassunshine.thework.alchemy.circle.AlchemyCircle; import cassunshine.thework.alchemy.circle.layout.AlchemyCircleLayout; import cassunshine.thework.alchemy.circle.node.type.AlchemyNodeTypes; import cassunshine.thework.recipes.ConstructionRecipe; diff --git a/src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleResearchLayout.java b/src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleResearchLayout.java new file mode 100644 index 0000000..c7fb7b8 --- /dev/null +++ b/src/main/java/cassunshine/thework/alchemy/circle/layout/AlchemyCircleResearchLayout.java @@ -0,0 +1,72 @@ +package cassunshine.thework.alchemy.circle.layout; + +import cassunshine.thework.alchemy.circle.AlchemyCircle; +import cassunshine.thework.alchemy.circle.node.AlchemyNode; +import cassunshine.thework.alchemy.circle.node.type.AlchemyNodeTypes; +import cassunshine.thework.alchemy.elements.ElementPacket; +import cassunshine.thework.alchemy.elements.Elements; +import cassunshine.thework.recipes.TheWorkRecipes; +import net.minecraft.entity.ItemEntity; +import net.minecraft.util.math.Box; + +import java.util.ArrayList; +import java.util.Collections; + +public class AlchemyCircleResearchLayout extends AlchemyCircleLayout { + + public AlchemyCircleResearchLayout(AlchemyCircle circle) { + super(circle, p -> p.nodeType == AlchemyNodeTypes.RESEARCH); + } + + + public void activate() { + var world = circle.blockEntity.getWorld(); + var be = circle.blockEntity; + + var entityList = world.getEntitiesByClass(ItemEntity.class, new Box(circle.blockEntity.getPos()), p -> true); + + if (entityList == null) + return; + + //Pick random item entity. + var itemEntity = entityList.get(world.random.nextInt(entityList.size())); + var stack = itemEntity.getStack(); + + //Try to get the recipe that's used to construct the given item. + var constructRecipe = TheWorkRecipes.getConstruction(stack.getItem()); + if (constructRecipe == null) + return; + + //Remove 1 item from the stack. + stack.decrement(1); + + ArrayList packets = new ArrayList<>(); + for (int i = 0; i < constructRecipe.inputRings.length; i++) { + var ringRecipe = constructRecipe.inputRings[i]; + var ringLayout = rings.get(i); + + //Add all the packets from this ring into a list. + Collections.addAll(packets, ringRecipe); + + //Iterate over each research node + for (AlchemyNode node : ringLayout.nodes) { + //Get the element of this node, and the current packet. + var element = Elements.getElement(node.rune); + var currentPacket = packets.get(0); + + //If the element of this node is the same as the packet, consume the packet. + if (element == currentPacket.element()) { + node.inventory.put(currentPacket.element(), currentPacket.amount()); + packets.remove(0); + } + } + + //Anything left in the list, backfire it. + for (ElementPacket packet : packets) + circle.addBackfire(packet.element(), packet.amount()); + + //Clear the remaining packets now that we backfired them. + packets.clear(); + } + } +} diff --git a/src/main/java/cassunshine/thework/alchemy/circle/node/type/AlchemyNodeTypes.java b/src/main/java/cassunshine/thework/alchemy/circle/node/type/AlchemyNodeTypes.java index abcf2f0..79f4574 100644 --- a/src/main/java/cassunshine/thework/alchemy/circle/node/type/AlchemyNodeTypes.java +++ b/src/main/java/cassunshine/thework/alchemy/circle/node/type/AlchemyNodeTypes.java @@ -10,6 +10,7 @@ public class AlchemyNodeTypes { public static final AlchemyNodeType NONE = new AlchemyNodeType(); public static final AlchemyNodeType DECONSTRUCT = new DeconstructNodeType().withItemHolding(i -> true); + public static final AlchemyNodeType RESEARCH = new ResearchNodeType(); public static final AlchemyNodeType CONSTRUCT = new ConstructNodeType(); @@ -22,7 +23,7 @@ public class AlchemyNodeTypes { NONE, //2 TRANSFER, //3 DECONSTRUCT, //4 - NONE, //5 + RESEARCH, //5 CONSTRUCT, //6 NONE, //7 NONE, //8 diff --git a/src/main/java/cassunshine/thework/alchemy/circle/node/type/ResearchNodeType.java b/src/main/java/cassunshine/thework/alchemy/circle/node/type/ResearchNodeType.java new file mode 100644 index 0000000..2fe1f77 --- /dev/null +++ b/src/main/java/cassunshine/thework/alchemy/circle/node/type/ResearchNodeType.java @@ -0,0 +1,4 @@ +package cassunshine.thework.alchemy.circle.node.type; + +public class ResearchNodeType extends AlchemyNodeType { +} diff --git a/src/main/java/cassunshine/thework/recipes/TheWorkRecipes.java b/src/main/java/cassunshine/thework/recipes/TheWorkRecipes.java index 7f7d072..0c11d33 100644 --- a/src/main/java/cassunshine/thework/recipes/TheWorkRecipes.java +++ b/src/main/java/cassunshine/thework/recipes/TheWorkRecipes.java @@ -12,6 +12,7 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.resource.Resource; @@ -28,6 +29,7 @@ public class TheWorkRecipes { private static ImmutableMap DECONSTRUCTION_RECIPES = ImmutableMap.of(); private static ImmutableMap CONSTRUCTION_RECIPES = ImmutableMap.of(); + private static ImmutableMap CONSTRUCTION_RECIPES_BY_ITEM = ImmutableMap.of(); private static ArrayList REACTIONS = new ArrayList<>(); @@ -43,6 +45,10 @@ public static ConstructionRecipe getConstruction(String signature) { return CONSTRUCTION_RECIPES.get(signature); } + public static ConstructionRecipe getConstruction(Item item) { + return CONSTRUCTION_RECIPES_BY_ITEM.get(item); + } + /** * Finds all matching reactions, putting them into a list. */ @@ -111,7 +117,8 @@ private static void loadDeconstructionRecipes(ResourceManager resourceManager) { private static void loadConstructionRecipes(ResourceManager resourceManager) { Map recipes = resourceManager.findResources("alchemy/construction", p -> p.getPath().endsWith(".json")); - ImmutableMap.Builder builder = ImmutableMap.builder(); + ImmutableMap.Builder constructRecipes = ImmutableMap.builder(); + ImmutableMap.Builder constructRecipesByItem = ImmutableMap.builder(); for (var entry : recipes.entrySet()) { var value = entry.getValue(); @@ -161,13 +168,17 @@ private static void loadConstructionRecipes(ResourceManager resourceManager) { } var recipe = new ConstructionRecipe(rings, outputs, TheWorkUtils.generateSignature(rings, r -> TheWorkUtils.generateSignature(r, e -> e.element().id.toString()))); - builder.put(recipe.signature, recipe); + constructRecipes.put(recipe.signature, recipe); + + if (recipe.outputs.length == 1) + constructRecipesByItem.put(recipe.outputs[0].getItem(), recipe); } catch (Exception e) { TheWorkMod.LOGGER.error(e.toString()); } } - CONSTRUCTION_RECIPES = builder.build(); + CONSTRUCTION_RECIPES = constructRecipes.build(); + CONSTRUCTION_RECIPES_BY_ITEM = constructRecipesByItem.build(); } private static void loadReactionRecipes(ResourceManager resourceManager) {