Fix more errors regarding GUI stuff.

This commit is contained in:
alexbegt committed 2019-04-25 20:39:48 -04:00
1 parent aaed92248c
commit a81f47c074
17 files changed
+222 -160

No files matched your search

+20 -21
View File
@@ -1,15 +1,16 @@
package slimeknights.mantle;
import net.minecraftforge.fml.DistExecutor;
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.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import slimeknights.mantle.client.ClientProxy;
import slimeknights.mantle.common.CommonProxy;
/**
@@ -19,38 +20,36 @@ import slimeknights.mantle.common.CommonProxy;
*
* @author Sunstrike <[email protected]>
*/
@Mod(modid = Mantle.modId,
name = Mantle.modName,
version = Mantle.modVersion,
dependencies = "required-after:forge@[14.21.1.2387,)",
acceptedMinecraftVersions = "[1.12,1.13)")
@Mod(Mantle.modId)
public class Mantle {
public static final String modId = "mantle";
public static final String modName = "Mantle";
public static final String modVersion = "${version}";
public static final Logger logger = LogManager.getLogger("Mantle");
/* Instance of this mod, used for grabbing prototype fields */
@Instance("mantle")
public static Mantle instance;
/* Proxies for sides, used for graphics processing */
@SidedProxy(clientSide = "slimeknights.mantle.client.ClientProxy", serverSide = "slimeknights.mantle.common.CommonProxy")
public static CommonProxy proxy;
public static CommonProxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> CommonProxy::new);
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){
public Mantle()
{
instance = this;
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::preInit);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::init);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::postInit);
}
private void preInit(final FMLCommonSetupEvent event) {
proxy.preInit();
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
private void init(final InterModEnqueueEvent event) {
proxy.init();
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
private void postInit(final InterModProcessEvent event) {
proxy.postInit();
}
}
@@ -1,6 +1,7 @@
package slimeknights.mantle.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Rectangle2d;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraftforge.api.distmarker.Dist;
@@ -39,8 +40,8 @@ public abstract class GuiModule extends GuiContainer {
return guiTop + ySize;
}
public Rectangle getArea() {
return new Rectangle(guiLeft, guiTop, xSize, ySize);
public Rectangle2d getArea() {
return new Rectangle2d(guiLeft, guiTop, xSize, ySize);
}
@Override
@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Rectangle2d;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
@@ -55,8 +56,8 @@ public class GuiMultiModule extends GuiContainer {
modules.add(module);
}
public List<Rectangle> getModuleAreas() {
List<Rectangle> areas = new ArrayList<Rectangle>(modules.size());
public List<Rectangle2d> getModuleAreas() {
List<Rectangle2d> areas = new ArrayList<Rectangle2d>(modules.size());
for(GuiModule module : modules) {
areas.add(module.getArea());
}
@@ -4,14 +4,14 @@ 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 net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull;
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK;
@SideOnly(Side.CLIENT)
@OnlyIn(Dist.CLIENT)
public class GuiArrow extends GuiButton {
private static final int X = 412;
@@ -33,9 +33,10 @@ public class GuiArrow extends GuiButton {
}
@Override
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) {
public void render(int mouseX, int mouseY, float partialTicks) {
if(this.visible) {
mc.getTextureManager().bindTexture(TEX_BOOK);
Minecraft minecraft = Minecraft.getInstance();
minecraft.getTextureManager().bindTexture(TEX_BOOK);
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
@@ -45,9 +46,9 @@ public class GuiArrow extends GuiButton {
float g = ((color >> 8) & 0xff) / 255.F;
float b = (color & 0xff) / 255.F;
GlStateManager.color(r, g, b);
GlStateManager.color3f(r, g, b);
Gui.drawScaledCustomSizeModalRect(x, y, arrowType.x, arrowType.y, width, height, width, height, 512, 512);
this.mouseDragged(mc, mouseX, mouseY);
this.renderBg(minecraft, mouseX, mouseY);
}
}
@@ -15,6 +15,7 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.InputMappings;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketClientStatus;
import net.minecraft.stats.StatisticsManager;
@@ -22,8 +23,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.IOException;
import java.util.ArrayList;
@@ -32,6 +31,7 @@ import java.util.List;
import javax.annotation.Nullable;
import org.lwjgl.glfw.GLFW;
import slimeknights.mantle.client.book.BookHelper;
import slimeknights.mantle.client.book.BookLoader;
import slimeknights.mantle.client.book.action.StringActionProcessor;
@@ -124,16 +124,16 @@ public class GuiBook extends GuiScreen {
}
protected int getMouseX(boolean rightSide) {
return (int) ((Mouse.getX() * this.width / this.mc.displayWidth - leftOffset(rightSide)) / PAGE_SCALE);
return (int) ((Minecraft.getInstance().mouseHelper.getMouseX() * this.width / this.mc.mainWindow.getFramebufferWidth() - leftOffset(rightSide)) / PAGE_SCALE);
}
protected int getMouseY() {
return (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - topOffset()) / PAGE_SCALE);
return (int) ((this.height - Minecraft.getInstance().mouseHelper.getMouseY() * this.height / this.mc.mainWindow.getFramebufferWidth() - 1 - topOffset()) / PAGE_SCALE);
}
@Override
@SuppressWarnings("ForLoopReplaceableByForEach")
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
public void render(int mouseX, int mouseY, float partialTicks) {
init();
FontRenderer fontRenderer = book.fontRenderer;
if(fontRenderer == null) {
@@ -199,27 +199,27 @@ public class GuiBook extends GuiScreen {
float scale = fontRenderer.getStringWidth(book.appearance.title) <= 67 ? 2.5F : 2F;
GlStateManager.scale(scale, scale, 1F);
fontRenderer.drawString(book.appearance.title, (width / 2) / scale + 3 - fontRenderer
.getStringWidth(book.appearance.title) / 2, (height / 2 - fontRenderer.FONT_HEIGHT / 2) / scale - 4, 0xAE8000, true);
GlStateManager.scalef(scale, scale, 1F);
fontRenderer.drawStringWithShadow(book.appearance.title, (width / 2) / scale + 3 - fontRenderer
.getStringWidth(book.appearance.title) / 2, (height / 2 - fontRenderer.FONT_HEIGHT / 2) / scale - 4, 0xAE8000);
GlStateManager.popMatrix();
}
if(!book.appearance.subtitle.isEmpty()) {
GlStateManager.pushMatrix();
GlStateManager.scale(1.5F, 1.5F, 1F);
fontRenderer.drawString(book.appearance.subtitle, (width / 2) / 1.5F + 7 - fontRenderer
.getStringWidth(book.appearance.subtitle) / 2, (height / 2 + 100 - fontRenderer.FONT_HEIGHT * 2) / 1.5F, 0xAE8000, true);
GlStateManager.scalef(1.5F, 1.5F, 1F);
fontRenderer.drawStringWithShadow(book.appearance.subtitle, (width / 2) / 1.5F + 7 - fontRenderer
.getStringWidth(book.appearance.subtitle) / 2, (height / 2 + 100 - fontRenderer.FONT_HEIGHT * 2) / 1.5F, 0xAE8000);
GlStateManager.popMatrix();
}
} else {
render.bindTexture(TEX_BOOK);
RenderHelper.disableStandardItemLighting();
GlStateManager.color(coverR, coverG, coverB);
GlStateManager.color3f(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);
GlStateManager.color3f(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);
@@ -227,11 +227,11 @@ public class GuiBook extends GuiScreen {
GlStateManager.pushMatrix();
drawerTransform(false);
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
GlStateManager.scalef(PAGE_SCALE, PAGE_SCALE, 1F);
if(book.appearance.drawPageNumbers) {
String pNum = (page - 1) * 2 + 2 + "";
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA, false);
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA);
}
int mX = getMouseX(false);
@@ -241,7 +241,7 @@ public class GuiBook extends GuiScreen {
for(int i = 0; i < leftElements.size(); i++) {
BookElement element = leftElements.get(i);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.color4f(1F, 1F, 1F, 1F);
element.draw(mX, mY, partialTicks, fontRenderer);
}
@@ -249,7 +249,7 @@ public class GuiBook extends GuiScreen {
for(int i = 0; i < leftElements.size(); i++) {
BookElement element = leftElements.get(i);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.color4f(1F, 1F, 1F, 1F);
element.drawOverlay(mX, mY, partialTicks, fontRenderer);
}
@@ -259,7 +259,7 @@ public class GuiBook extends GuiScreen {
// 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);
GlStateManager.color4f(1F, 1F, 1F, 1F);
RenderHelper.disableStandardItemLighting();
int fullPageCount = book.getFullPageCount(advancementCache);
@@ -269,11 +269,11 @@ public class GuiBook extends GuiScreen {
GlStateManager.pushMatrix();
drawerTransform(true);
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
GlStateManager.scalef(PAGE_SCALE, PAGE_SCALE, 1F);
if(book.appearance.drawPageNumbers) {
String pNum = (page - 1) * 2 + 3 + "";
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA, false);
fontRenderer.drawString(pNum, PAGE_WIDTH / 2 - fontRenderer.getStringWidth(pNum) / 2, PAGE_HEIGHT - 10, 0xFFAAAAAA);
}
int mX = getMouseX(true);
@@ -283,7 +283,7 @@ public class GuiBook extends GuiScreen {
for(int i = 0; i < rightElements.size(); i++) {
BookElement element = rightElements.get(i);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.color4f(1F, 1F, 1F, 1F);
element.draw(mX, mY, partialTicks, fontRenderer);
}
@@ -291,7 +291,7 @@ public class GuiBook extends GuiScreen {
for(int i = 0; i < rightElements.size(); i++) {
BookElement element = rightElements.get(i);
GlStateManager.color(1F, 1F, 1F, 1F);
GlStateManager.color4f(1F, 1F, 1F, 1F);
element.drawOverlay(mX, mY, partialTicks, fontRenderer);
}
@@ -299,7 +299,7 @@ public class GuiBook extends GuiScreen {
}
}
super.drawScreen(mouseX, mouseY, partialTicks);
super.render(mouseX, mouseY, partialTicks);
GlStateManager.popMatrix();
}
@@ -417,23 +417,66 @@ public class GuiBook extends GuiScreen {
height /= 2F;
}*/
previousArrow = new GuiArrow(0, -50, -50, GuiArrow.ArrowType.PREV, book.appearance.arrowColor, book.appearance.arrowColorHover);
nextArrow = new GuiArrow(1, -50, -50, GuiArrow.ArrowType.NEXT, book.appearance.arrowColor, book.appearance.arrowColorHover);
backArrow = new GuiArrow(2, width / 2 - GuiArrow.WIDTH / 2, height / 2 + GuiArrow.HEIGHT / 2 + PAGE_HEIGHT/2, GuiArrow.ArrowType.LEFT, book.appearance.arrowColor, book.appearance.arrowColorHover);
indexArrow = new GuiArrow(3, width / 2 - PAGE_WIDTH_UNSCALED - GuiArrow.WIDTH / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, GuiArrow.ArrowType.BACK_UP, book.appearance.arrowColor, book.appearance.arrowColorHover);
previousArrow = new GuiArrow(0, -50, -50, GuiArrow.ArrowType.PREV, book.appearance.arrowColor, book.appearance.arrowColorHover) {
@Override
public void onClick(double mouseX, double mouseY) {
page--;
if(page < -1) {
page = -1;
}
buttonList.clear();
buttonList.add(previousArrow);
buttonList.add(nextArrow);
buttonList.add(backArrow);
buttonList.add(indexArrow);
oldPage = -2;
buildPages();
}
};
nextArrow = new GuiArrow(1, -50, -50, GuiArrow.ArrowType.NEXT, book.appearance.arrowColor, book.appearance.arrowColorHover) {
@Override
public void onClick(double mouseX, double mouseY) {
page++;
int fullPageCount = book.getFullPageCount(advancementCache);
if(page >= fullPageCount) {
page = fullPageCount - 1;
}
oldPage = -2;
buildPages();
}
};
backArrow = new GuiArrow(2, width / 2 - GuiArrow.WIDTH / 2, height / 2 + GuiArrow.HEIGHT / 2 + PAGE_HEIGHT/2, GuiArrow.ArrowType.LEFT, book.appearance.arrowColor, book.appearance.arrowColorHover) {
@Override
public void onClick(double mouseX, double mouseY) {
if(oldPage >= -1) {
page = oldPage;
}
oldPage = -2;
buildPages();
}
};
indexArrow = new GuiArrow(3, width / 2 - PAGE_WIDTH_UNSCALED - GuiArrow.WIDTH / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, GuiArrow.ArrowType.BACK_UP, book.appearance.arrowColor, book.appearance.arrowColorHover) {
@Override
public void onClick(double mouseX, double mouseY) {
openPage(book.findPageNumber("index.page1"));
oldPage = -2;
buildPages();
}
};
buttons.clear();
buttons.add(previousArrow);
buttons.add(nextArrow);
buttons.add(backArrow);
buttons.add(indexArrow);
buildPages();
}
@Override
public void updateScreen() {
super.updateScreen();
public void tick() {
super.tick();
previousArrow.visible = page != -1;
nextArrow.visible = page + 1 < book.getFullPageCount(advancementCache);
@@ -454,72 +497,80 @@ public class GuiBook extends GuiScreen {
nextArrow.y = height / 2 + 75;
}
@Override
/*@Override
TODO: REMOVE
public void actionPerformed(GuiButton button) {
if(button instanceof GuiBookmark) {
openPage(book.findPageNumber(((GuiBookmark) button).data.page, advancementCache));
return;
}
}*/
if(button == previousArrow) {
page--;
if(page < -1) {
page = -1;
}
} else if(button == nextArrow) {
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
super.keyPressed(keyCode, scanCode, modifiers);
switch(keyCode) {
case GLFW.GLFW_KEY_LEFT:
case GLFW.GLFW_KEY_A:
page--;
if(page < -1) {
page = -1;
}
oldPage = -2;
buildPages();
return true;
case GLFW.GLFW_KEY_RIGHT:
case GLFW.GLFW_KEY_D:
page++;
int fullPageCount = book.getFullPageCount(advancementCache);
if(page >= fullPageCount) {
page = fullPageCount - 1;
}
oldPage = -2;
buildPages();
return true;
case GLFW.GLFW_KEY_F3:
debug = !debug;
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
public boolean mouseScrolled(double scrollDelta) {
if (scrollDelta < 0.0D) {
page++;
int fullPageCount = book.getFullPageCount(advancementCache);
if(page >= fullPageCount) {
page = fullPageCount - 1;
}
} else if(button == backArrow) {
if(oldPage >= -1) {
page = oldPage;
oldPage = -2;
buildPages();
return true;
}
else if (scrollDelta > 0.0D) {
page--;
if(page < -1) {
page = -1;
}
} else if(button == indexArrow) {
openPage(book.findPageNumber("index.page1"));
oldPage = -2;
buildPages();
return true;
}
oldPage = -2;
buildPages();
return super.mouseScrolled(scrollDelta);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
super.keyTyped(typedChar, keyCode);
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
public void handleMouseInput() throws IOException {
super.handleMouseInput();
int scroll = Mouse.getDWheel();
if (scroll < 0)
actionPerformed(nextArrow);
else if (scroll > 0)
actionPerformed(previousArrow);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
boolean right = false;
mouseX = getMouseX(false);
@@ -537,15 +588,15 @@ public class GuiBook extends GuiScreen {
element.mouseClicked(mouseX, mouseY, mouseButton);
// if we changed page stop so we don't act on the new page
if(page != oldPage) {
break;
return true;
}
}
return super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) {
boolean right = false;
mouseX = getMouseX(false);
mouseY = getMouseY();
@@ -558,12 +609,13 @@ public class GuiBook extends GuiScreen {
// 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.mouseReleased(mouseX, mouseY, state);
element.mouseReleased(mouseX, mouseY, mouseButton);
}
return super.mouseReleased(mouseX, mouseY, mouseButton);
}
@Override
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
public boolean mouseDragged(double mouseX, double mouseY, int clickedMouseButton, double timeSinceLaslick, double unknown) {
boolean right = false;
mouseX = getMouseX(false);
mouseY = getMouseY();
@@ -578,6 +630,8 @@ public class GuiBook extends GuiScreen {
BookElement element = right ? rightElements.get(i) : leftElements.get(i);
element.mouseClickMove(mouseX, mouseY, clickedMouseButton);
}
return true;
}
@Override
@@ -39,15 +39,15 @@ public abstract class BookElement extends Gui {
public void drawOverlay(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
}
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
}
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton) {
public void mouseClickMove(double mouseX, double mouseY, int clickedMouseButton) {
}
public void mouseReleased(int mouseX, int mouseY, int clickedMouseButton) {
public void mouseReleased(double mouseX, double mouseY, int clickedMouseButton) {
}
@@ -16,7 +16,7 @@ public class ElementAnimationToggle extends ElementArrow {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
if(callback != null && isHovered(mouseX, mouseY)) {
if(callback.onButtonClick(buttonId, this)) {
toggled = !toggled;
@@ -16,7 +16,7 @@ public class ElementArrow extends ElementButton {
@Override
public void draw(int mouseX, int mouseY, float partialTicks, FontRenderer fontRenderer) {
button.drawButton(mc, mouseX, mouseY, partialTicks);
button.render(mouseX, mouseY, partialTicks);
}
}
@@ -13,7 +13,7 @@ public abstract class ElementButton extends SizedBookElement {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
if(callback != null && isHovered(mouseX, mouseY)) {
callback.onButtonClick(buttonId, this);
}
@@ -108,7 +108,7 @@ public class ElementItem extends SizedBookElement {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
if(mouseButton == 0 && isHovered(mouseX, mouseY) && currentItem < itemCycle.size()) {
if(action != null) {
StringActionProcessor.process(action, parent);
@@ -89,7 +89,7 @@ public class ElementSection extends SizedBookElement {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
if(mouseButton == 0 && section != null && section.isUnlocked(parent.advancementCache) && isHovered(mouseX, mouseY)) {
parent.openPage(parent.book.getFirstPageNumber(section, parent.advancementCache));
}
@@ -264,18 +264,18 @@ public class ElementStructure extends SizedBookElement implements IButtonClickHa
private int lastY;
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
//lastX = mouseX;
//lastY = mouseY;
lastClick = new int[] {mouseX, mouseY};
lastClick = new int[] {(int) mouseX, (int) mouseY};
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton) {
int dx = mouseX - lastX;
int dy = mouseX - lastY;
public void mouseClickMove(double mouseX, double mouseY, int clickedMouseButton) {
int dx = (int) mouseX - lastX;
int dy = (int) mouseX - lastY;
float maxSpeed = 1f;
float changeX = Math.min(maxSpeed, dx/100f);
@@ -292,7 +292,7 @@ public class ElementStructure extends SizedBookElement implements IButtonClickHa
}
@Override
public void mouseReleased(int mouseX, int mouseY, int clickedMouseButton) {
public void mouseReleased(double mouseX, double mouseY, int clickedMouseButton) {
super.mouseReleased(mouseX, mouseY, clickedMouseButton);
lastClick = null;
}
@@ -52,7 +52,7 @@ public class ElementText extends SizedBookElement {
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
public void mouseClicked(double mouseX, double mouseY, int mouseButton) {
if(mouseButton == 0) {
doAction = true;
}
@@ -15,7 +15,7 @@ public abstract class SizedBookElement extends BookElement {
this.height = height;
}
public boolean isHovered(int mouseX, int mouseY) {
public boolean isHovered(double mouseX, double mouseY) {
return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height;
}
}
@@ -16,9 +16,9 @@ import net.minecraft.util.INameable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.IWorldNameable;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
@@ -38,7 +38,7 @@ public abstract class BaseContainer<T extends TileEntity> extends Container {
protected final Block originalBlock; // used to check if the block we interacted with got broken
protected final BlockPos pos;
protected final World world;
protected final IItemHandler itemHandler;
protected final LazyOptional<IItemHandler> itemHandler;
public List<Container> subContainers = Lists.newArrayList();
@@ -49,11 +49,11 @@ public abstract class BaseContainer<T extends TileEntity> extends Container {
public BaseContainer(T tile, EnumFacing invDir) {
this.tile = tile;
if(tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, invDir)) {
if(tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, invDir).isPresent()) {
itemHandler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, invDir);
}
else {
itemHandler = new EmptyHandler();
itemHandler = net.minecraftforge.common.util.LazyOptional.of(() -> new EmptyHandler());
}
this.world = tile.getWorld();
@@ -85,7 +85,7 @@ public abstract class BaseContainer<T extends TileEntity> extends Container {
}
public IItemHandler getItemHandler() {
return itemHandler;
return itemHandler.orElse(new EmptyHandler());
}
/**
@@ -129,8 +129,8 @@ public abstract class BaseContainer<T extends TileEntity> extends Container {
public String getInventoryDisplayName() {
INameable nameable = null;
if (itemHandler instanceof InvWrapper) {
nameable = ((InvWrapper) itemHandler).getInv();
if (itemHandler.orElse(new EmptyHandler()) instanceof InvWrapper) {
nameable = ((InvWrapper) itemHandler.orElse(new EmptyHandler())).getInv();
// if the inventory doesn't have a name fall back to checking the tileentity
if (nameable.getDisplayName() == null) {
nameable = null;
@@ -1,13 +1,14 @@
package slimeknights.mantle.item;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.List;
@@ -18,21 +19,25 @@ import slimeknights.mantle.util.LocUtils;
// Item with automatic tooltip support
public class ItemTooltip extends Item {
public ItemTooltip(Properties properties) {
super(properties);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
addOptionalTooltip(stack, tooltip);
super.addInformation(stack, worldIn, tooltip, flagIn);
}
public static void addOptionalTooltip(ItemStack stack, List<String> tooltip) {
if(I18n.canTranslate(stack.getUnlocalizedName() + ".tooltip")) {
public static void addOptionalTooltip(ItemStack stack, List<ITextComponent> tooltip) {
if(I18n.hasKey(stack.getDisplayName() + ".tooltip")) {
tooltip.addAll(LocUtils.getTooltips(TextFormatting.GRAY.toString() +
LocUtils.translateRecursive(stack.getUnlocalizedName() + ".tooltip")));
LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
}
else if(I18n.canTranslate(stack.getUnlocalizedName() + ".tooltip")) {
else if(I18n.hasKey(stack.getDisplayName() + ".tooltip")) {
tooltip.addAll(LocUtils.getTooltips(
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(stack.getUnlocalizedName() + ".tooltip")));
TextFormatting.GRAY.toString() + LocUtils.translateRecursive(stack.getDisplayName() + ".tooltip")));
}
}
}
@@ -1,8 +1,9 @@
package slimeknights.mantle.util;
import com.google.common.collect.Lists;
import net.minecraft.util.text.translation.I18n;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import java.util.List;
import java.util.Locale;
@@ -21,22 +22,22 @@ public abstract class LocUtils {
}
public static String translateRecursive(String key, Object... params) {
return I18n.translateToLocal(I18n.translateToLocalFormatted(key, params));
return I18n.format(I18n.format(key, params));
}
public static List<String> getTooltips(String text) {
List<String> list = Lists.newLinkedList();
public static List<ITextComponent> getTooltips(String text) {
List<ITextComponent> list = Lists.newLinkedList();
if(text == null)
return list;
int j = 0;
int k;
while((k = text.indexOf("\\n", j)) >= 0)
{
list.add(text.substring(j, k));
list.add(new TextComponentString(text.substring(j, k)));
j = k+2;
}
list.add(text.substring(j, text.length()));
list.add(new TextComponentString(text.substring(j, text.length())));
return list;
}