mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-10-26 14:23:55 +00:00
New Curios-Inspired GUI (#13)
This commit is contained in:
1 parent
63833f2fbb
commit
b57a7a1dd6
13 files changed
+704
-322
No files matched your search
+1
-30
@@ -1,32 +1,3 @@
|
||||
/*
|
||||
* Add your dependencies here. Supported configurations:
|
||||
* - api("group:name:version:classifier"): if you use the types from this dependency in the public API of this mod
|
||||
* Available at runtime and compiletime for mods depending on this mod
|
||||
* - implementation("g:n:v:c"): if you need this for internal implementation details of the mod, but none of it is visible via the public API
|
||||
* Available at runtime but not compiletime for mods depending on this mod
|
||||
* - compileOnly("g:n:v:c"): if the mod you're building doesn't need this dependency during runtime at all, e.g. for optional mods
|
||||
* Not available at all for mods depending on this mod, only visible at compiletime for this mod
|
||||
* - compileOnlyApi("g:n:v:c"): like compileOnly, but also visible at compiletime for mods depending on this mod
|
||||
* Available at compiletime but not runtime for mods depending on this mod
|
||||
* - runtimeOnlyNonPublishable("g:n:v:c"): if you want to include a mod in this mod's runClient/runServer runs, but not publish it as a dependency
|
||||
* Not available at all for mods depending on this mod, only visible at runtime for this mod
|
||||
* - runtimeOnly("g:n:v:c"): if you don't need this at compile time, but want it to be present at runtime
|
||||
* Available at runtime for mods depending on this mod
|
||||
* - annotationProcessor("g:n:v:c"): mostly for java compiler plugins, if you know you need this, use it, otherwise don't worry
|
||||
* - testCONFIG("g:n:v:c") - replace CONFIG by one of the above (except api), same as above but for the test sources instead of main
|
||||
*
|
||||
* - shadowImplementation("g:n:v:c"): effectively the same as API, but the dependency is included in your jar under a renamed package name
|
||||
* Requires you to enable usesShadowedDependencies in gradle.properties
|
||||
*
|
||||
* - compile("g:n:v:c"): deprecated, replace with "api" (works like the old "compile") or "implementation" (can be more efficient)
|
||||
*
|
||||
* You can exclude transitive dependencies (dependencies of the chosen dependency) by appending { transitive = false } if needed,
|
||||
* but use this sparingly as it can break using your mod as another mod's dependency if you're not careful.
|
||||
*
|
||||
* Gradle names for some of the configuration can be misleading, compileOnlyApi and runtimeOnly both get published as dependencies in Maven, but compileOnly does not.
|
||||
* The buildscript adds runtimeOnlyNonPublishable to also have a runtime dependency that's not published.
|
||||
*
|
||||
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
|
||||
*/
|
||||
dependencies {
|
||||
implementation("com.github.GTNewHorizons:NotEnoughItems:2.7.51-GTNH:dev")
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import baubles.api.BaubleType;
|
||||
import baubles.common.BaublesConfig;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
|
||||
@@ -227,7 +228,7 @@ public class BaubleExpandedSlots {
|
||||
* @return The number of bauble slots currently used.
|
||||
*/
|
||||
public static int slotsCurrentlyUsed() {
|
||||
return slotLimit - newSlotsRemaining;
|
||||
return BaublesConfig.showUnusedSlots ? BaubleExpandedSlots.slotLimit : slotLimit - newSlotsRemaining;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,39 +7,71 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
|
||||
import static baubles.common.BaublesConfig.useOldGuiButton;
|
||||
|
||||
public class GuiBaublesButton extends GuiButton {
|
||||
|
||||
public GuiBaublesButton(int p_i1021_1_, int p_i1021_2_, int p_i1021_3_,
|
||||
int p_i1021_4_, int p_i1021_5_, String p_i1021_6_) {
|
||||
super(p_i1021_1_, p_i1021_2_, p_i1021_3_, p_i1021_4_, p_i1021_5_, p_i1021_6_);
|
||||
}
|
||||
|
||||
public void drawButton(Minecraft mc, int xx, int yy)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
FontRenderer fontrenderer = mc.fontRenderer;
|
||||
mc.getTextureManager().bindTexture(GuiPlayerExpanded.background);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = xx >= this.xPosition && yy >= this.yPosition && xx < this.xPosition + this.width && yy < this.yPosition + this.height;
|
||||
int k = this.getHoverState(this.field_146123_n);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
|
||||
if (k==1) {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 200, 48, 10, 10);
|
||||
} else {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 210, 48, 10, 10);
|
||||
this.drawCenteredString(fontrenderer, this.displayString,
|
||||
this.xPosition + 5, this.yPosition + this.height, 0xffffff);
|
||||
}
|
||||
|
||||
this.mouseDragged(mc, xx, yy);
|
||||
|
||||
|
||||
}
|
||||
public GuiBaublesButton(int buttonId, int xIn, int yIn, int widthIn, int heightIn, String resource) {
|
||||
super(buttonId, xIn, yIn, widthIn, heightIn, resource);
|
||||
}
|
||||
|
||||
public void drawButton(Minecraft mc, int xx, int yy) {
|
||||
if (!this.visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
FontRenderer fontrenderer = mc.fontRenderer;
|
||||
if (useOldGuiButton) {
|
||||
mc.getTextureManager().bindTexture(GuiPlayerExpanded.background);
|
||||
} else {
|
||||
mc.getTextureManager().bindTexture(GuiPlayerExpanded.gui_background);
|
||||
}
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.field_146123_n = xx >= this.xPosition && yy >= this.yPosition && xx < this.xPosition + this.width && yy < this.yPosition + this.height;
|
||||
int hover = this.getHoverState(this.field_146123_n);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
if (hover == 1) {
|
||||
if (useOldGuiButton) {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 200, 48, 10, 10);
|
||||
} else {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 50, 0, 14, 14);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (useOldGuiButton) {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 210, 48, 10, 10);
|
||||
this.drawCenteredString(fontrenderer, this.displayString,
|
||||
this.xPosition + 5, this.yPosition + this.height, 0xffffff);
|
||||
} else {
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 50, 14, 14, 14);
|
||||
|
||||
int labelWidth = fontrenderer.getStringWidth(this.displayString);
|
||||
|
||||
int labelX = this.xPosition + 20;
|
||||
int labelY = this.yPosition - this.height;
|
||||
int labelHeight = 8;
|
||||
|
||||
int borderColorDark = 0xF0100010;
|
||||
int borderColorLight = 0x505000FF;
|
||||
int borderColorLightFaded = (borderColorLight & 0xFEFEFE) >> 1 | borderColorLight & 0xFF000000;
|
||||
|
||||
this.drawGradientRect(labelX - 3, labelY - 4, labelX + labelWidth + 3, labelY - 3, borderColorDark, borderColorDark);
|
||||
this.drawGradientRect(labelX - 3, labelY + labelHeight + 3, labelX + labelWidth + 3, labelY + labelHeight + 4, borderColorDark, borderColorDark);
|
||||
this.drawGradientRect(labelX - 3, labelY - 3, labelX + labelWidth + 3, labelY + labelHeight + 3, borderColorDark, borderColorDark);
|
||||
this.drawGradientRect(labelX - 4, labelY - 3, labelX - 3, labelY + labelHeight + 3, borderColorDark, borderColorDark);
|
||||
this.drawGradientRect(labelX + labelWidth + 3, labelY - 3, labelX + labelWidth + 4, labelY + labelHeight + 3, borderColorDark, borderColorDark);
|
||||
|
||||
this.drawGradientRect(labelX - 3, labelY - 2, labelX - 2, labelY + labelHeight + 2, borderColorLight, borderColorLightFaded);
|
||||
this.drawGradientRect(labelX + labelWidth + 2, labelY - 2, labelX + labelWidth + 3, labelY + labelHeight + 2, borderColorLight, borderColorLightFaded);
|
||||
this.drawGradientRect(labelX - 3, labelY - 3, labelX + labelWidth + 3, labelY - 2, borderColorLight, borderColorLight);
|
||||
this.drawGradientRect(labelX - 3, labelY + labelHeight + 2, labelX + labelWidth + 3, labelY + labelHeight + 3, borderColorLightFaded, borderColorLightFaded);
|
||||
|
||||
this.drawString(fontrenderer, this.displayString, labelX, labelY, 0xFFFFFF);
|
||||
}
|
||||
this.mouseDragged(mc, xx, yy);
|
||||
}
|
||||
}
|
||||
@@ -12,40 +12,47 @@ import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
public class GuiEvents {
|
||||
|
||||
import static baubles.common.BaublesConfig.useOldGuiButton;
|
||||
|
||||
public class GuiEvents {
|
||||
|
||||
@SideOnly(value = Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public void guiPostInit(GuiScreenEvent.InitGuiEvent.Post event) {
|
||||
if (!(event.gui instanceof GuiInventory) && !(event.gui instanceof GuiPlayerExpanded)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.gui instanceof GuiInventory || event.gui instanceof GuiPlayerExpanded) {
|
||||
|
||||
int xSize = 176;
|
||||
int ySize = 166;
|
||||
|
||||
int guiLeft = (event.gui.width - xSize) / 2;
|
||||
int guiTop = (event.gui.height - ySize) / 2;
|
||||
|
||||
if (!event.gui.mc.thePlayer.getActivePotionEffects().isEmpty() && isNeiHidden()) {
|
||||
guiLeft = 160 + (event.gui.width - xSize - 200) / 2;
|
||||
}
|
||||
|
||||
event.buttonList.add(new GuiBaublesButton(55, guiLeft + 66, guiTop + 9, 10, 10,
|
||||
I18n.format((event.gui instanceof GuiInventory)?"button.baubles":"button.normal", new Object[0])));
|
||||
}
|
||||
|
||||
}
|
||||
int xSize = 176;
|
||||
int ySize = 166;
|
||||
|
||||
int guiLeft = (event.gui.width - xSize) / 2;
|
||||
int guiTop = (event.gui.height - ySize) / 2;
|
||||
|
||||
if (!event.gui.mc.thePlayer.getActivePotionEffects().isEmpty() && isNeiHidden()) {
|
||||
guiLeft = 160 + (event.gui.width - xSize - 200) / 2;
|
||||
}
|
||||
|
||||
String tooltip = I18n.format((event.gui instanceof GuiInventory) ? "button.baubles" : "button.normal");
|
||||
if (useOldGuiButton) {
|
||||
event.buttonList.add(new GuiBaublesButton(55, guiLeft + 66, guiTop + 9, 10, 10,
|
||||
tooltip));
|
||||
} else {
|
||||
event.buttonList.add(new GuiBaublesButton(55, guiLeft + 26, guiTop + 9, 10, 10,
|
||||
tooltip));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SideOnly(value = Side.CLIENT)
|
||||
@SubscribeEvent
|
||||
public void guiPostAction(GuiScreenEvent.ActionPerformedEvent.Post event) {
|
||||
|
||||
if (event.gui instanceof GuiInventory) {
|
||||
if (event.button.id == 55) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketOpenBaublesInventory(event.gui.mc.thePlayer));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (event.gui instanceof GuiPlayerExpanded) {
|
||||
if (event.button.id == 55) {
|
||||
event.gui.mc.displayGuiScreen(new GuiInventory(event.gui.mc.thePlayer));
|
||||
@@ -53,17 +60,17 @@ public class GuiEvents {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Method isNEIHidden;
|
||||
boolean isNeiHidden() {
|
||||
boolean hidden=true;
|
||||
boolean hidden = true;
|
||||
try {
|
||||
if (isNEIHidden==null) {
|
||||
Class fake = Class.forName("codechicken.nei.NEIClientConfig");
|
||||
if (isNEIHidden == null) {
|
||||
Class<?> fake = Class.forName("codechicken.nei.NEIClientConfig");
|
||||
isNEIHidden = fake.getMethod("isHidden");
|
||||
}
|
||||
hidden = (Boolean) isNEIHidden.invoke(null);
|
||||
} catch(Exception ex) { }
|
||||
} catch (Exception ignored) {}
|
||||
return hidden;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,26 @@
|
||||
package baubles.client.gui;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import baubles.api.expanded.BaubleExpandedSlots;
|
||||
import baubles.common.Baubles;
|
||||
@@ -10,18 +29,24 @@ import baubles.common.container.ContainerPlayerExpanded;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.achievement.GuiAchievements;
|
||||
import net.minecraft.client.gui.achievement.GuiStats;
|
||||
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public static final ResourceLocation background = new ResourceLocation("baubles","textures/gui/bauble_inventory.png");
|
||||
import static baubles.common.BaublesConfig.useOldGuiRendering;
|
||||
import static net.minecraft.client.gui.inventory.GuiInventory.func_147046_a;
|
||||
|
||||
@Optional.Interface(iface = "codechicken.nei.api.INEIGuiHandler", modid = "NotEnoughItems")
|
||||
public class GuiPlayerExpanded extends GuiContainer implements INEIGuiHandler {
|
||||
|
||||
public static final ResourceLocation background = new ResourceLocation("baubles","textures/gui/bauble_inventory.png");
|
||||
public static final ResourceLocation gui_background = new ResourceLocation("baubles","textures/gui/bauble_background.png");
|
||||
private static final ResourceLocation creative_inventory_tabs = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
|
||||
|
||||
private static final boolean hasLwjgl3 = Loader.isModLoaded("lwjgl3ify");
|
||||
|
||||
/**
|
||||
* x size of the inventory window in pixels. Defined as float, passed as int.
|
||||
@@ -32,6 +57,15 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
*/
|
||||
private float ySizeFloat;
|
||||
|
||||
public boolean showActivePotionEffects;
|
||||
|
||||
/** Amount scrolled in inventory (0 = top, 1 = bottom) */
|
||||
private float currentScroll;
|
||||
/** True if the scrollbar is being dragged */
|
||||
private boolean isScrolling;
|
||||
/** True if the left mouse button was held down last time drawScreen was called. */
|
||||
private boolean wasClicking;
|
||||
|
||||
public GuiPlayerExpanded(EntityPlayer player) {
|
||||
super(new ContainerPlayerExpanded(player.inventory, !player.worldObj.isRemote, player));
|
||||
allowUserInput = true;
|
||||
@@ -40,11 +74,11 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
@Override
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
try {
|
||||
((ContainerPlayerExpanded)inventorySlots).baubles.blockEvents = false;
|
||||
} catch (Exception e) {}
|
||||
((ContainerPlayerExpanded) inventorySlots).baubles.blockEvents = false;
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,73 +88,191 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
public void initGui() {
|
||||
buttonList.clear();
|
||||
super.initGui();
|
||||
|
||||
if (!this.mc.thePlayer.getActivePotionEffects().isEmpty() && !useOldGuiRendering) {
|
||||
this.showActivePotionEffects = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
@Override
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
super.drawScreen(par1, par2, par3);
|
||||
xSizeFloat = (float)par1;
|
||||
ySizeFloat = (float)par2;
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
xSizeFloat = (float) mouseX;
|
||||
ySizeFloat = (float) mouseY;
|
||||
|
||||
handleScrollbar(mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.getTextureManager().bindTexture(background);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
final int slotOffset = 18;
|
||||
final int slotStartX = guiLeft + 79;
|
||||
final int slotStartY = guiTop + 7;
|
||||
|
||||
//bauble slot backgrounds
|
||||
for (int slotIndex = 0; slotIndex < BaubleExpandedSlots.slotLimit; slotIndex++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(slotIndex);
|
||||
if(BaublesConfig.showUnusedSlots || !slotType.equals(BaubleExpandedSlots.unknownType)) {
|
||||
//Slot slot = (Slot)inventorySlots.inventorySlots.get(slotIndex + 4);
|
||||
drawTexturedModalRect(slotStartX + (slotOffset * (slotIndex / 4)), slotStartY + (slotOffset * (slotIndex % 4)), 200, 0, 18, 18);
|
||||
}
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
if (!useOldGuiRendering) {
|
||||
this.fontRendererObj.drawString(I18n.format("container.crafting"), 86, 16, 4210752);
|
||||
}
|
||||
drawPlayerModel(guiLeft + 51, guiTop + 75, 30, (float)(guiLeft + 51) - xSizeFloat, (float)(guiTop + 25) - ySizeFloat, mc.thePlayer);
|
||||
}
|
||||
|
||||
public static void drawPlayerModel(int x, int y, int scale, float yaw, float pitch, EntityLivingBase playerdrawn) {
|
||||
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float)x, (float)y, 50.0F);
|
||||
GL11.glScalef((float)(-scale), (float)scale, (float)scale);
|
||||
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
|
||||
float f2 = playerdrawn.renderYawOffset;
|
||||
float f3 = playerdrawn.rotationYaw;
|
||||
float f4 = playerdrawn.rotationPitch;
|
||||
float f5 = playerdrawn.prevRotationYawHead;
|
||||
float f6 = playerdrawn.rotationYawHead;
|
||||
GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glRotatef(-((float)Math.atan((double)(pitch / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
|
||||
playerdrawn.renderYawOffset = (float)Math.atan((double)(yaw / 40.0F)) * 20.0F;
|
||||
playerdrawn.rotationYaw = (float)Math.atan((double)(yaw / 40.0F)) * 40.0F;
|
||||
playerdrawn.rotationPitch = -((float)Math.atan((double)(pitch / 40.0F))) * 20.0F;
|
||||
playerdrawn.rotationYawHead = playerdrawn.rotationYaw;
|
||||
playerdrawn.prevRotationYawHead = playerdrawn.rotationYaw;
|
||||
GL11.glTranslatef(0.0F, playerdrawn.yOffset, 0.0F);
|
||||
RenderManager.instance.playerViewY = 180.0F;
|
||||
RenderManager.instance.renderEntityWithPosYaw(playerdrawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
|
||||
playerdrawn.renderYawOffset = f2;
|
||||
playerdrawn.rotationYaw = f3;
|
||||
playerdrawn.rotationPitch = f4;
|
||||
playerdrawn.prevRotationYawHead = f5;
|
||||
playerdrawn.rotationYawHead = f6;
|
||||
GL11.glPopMatrix();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
if (useOldGuiRendering) {
|
||||
mc.getTextureManager().bindTexture(background);
|
||||
} else {
|
||||
mc.getTextureManager().bindTexture(GuiInventory.field_147001_a);
|
||||
}
|
||||
|
||||
this.drawBaubleSlots();
|
||||
if (showActivePotionEffects) {
|
||||
drawPotionEffects();
|
||||
}
|
||||
|
||||
// Player model
|
||||
func_147046_a(guiLeft + 51, guiTop + 75, 30, (float) (guiLeft + 51) - xSizeFloat, (float) (guiTop + 25) - ySizeFloat, mc.thePlayer);
|
||||
}
|
||||
|
||||
private void drawBaubleSlots() {
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
int upperHeight = 7 + BaubleExpandedSlots.slotsCurrentlyUsed() * 18;
|
||||
if (!useOldGuiRendering) {
|
||||
this.mc.getTextureManager().bindTexture(gui_background);
|
||||
}
|
||||
|
||||
final int slotOffset = 18;
|
||||
int slotStartX = guiLeft - 26;
|
||||
int slotStartY = 12;
|
||||
|
||||
if (useOldGuiRendering) {
|
||||
slotStartX = guiLeft + 79;
|
||||
slotStartY = guiTop + 7;
|
||||
} else {
|
||||
if (BaubleExpandedSlots.slotsCurrentlyUsed() <= 8) {
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4, 0, 0, 27, upperHeight);
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4 + upperHeight, 0, 151, 27, 7);
|
||||
} else {
|
||||
this.drawTexturedModalRect(this.guiLeft - 26, this.guiTop + 4, 0, 0, 27, 158);
|
||||
this.drawTexturedModalRect(this.guiLeft - 42, this.guiTop + 4, 27, 0, 23, 158);
|
||||
this.mc.getTextureManager().bindTexture(creative_inventory_tabs);
|
||||
this.drawTexturedModalRect(this.guiLeft - 34, this.guiTop + 12 + (int) (127f * this.currentScroll), 232, 0, 12, 15);
|
||||
}
|
||||
}
|
||||
|
||||
// Bauble slot backgrounds
|
||||
for (int slotIndex = 0; slotIndex < BaubleExpandedSlots.slotLimit; slotIndex++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(slotIndex);
|
||||
if (!BaublesConfig.showUnusedSlots && slotType.equals(BaubleExpandedSlots.unknownType)) {
|
||||
continue;
|
||||
}
|
||||
if (useOldGuiRendering) {
|
||||
drawTexturedModalRect(slotStartX + (slotOffset * (slotIndex / 4)), slotStartY + (slotOffset * (slotIndex % 4)), 200, 0, 18, 18);
|
||||
} else {
|
||||
drawTexturedModalRect(slotStartX + (slotOffset * (slotIndex / 4)), slotStartY + (slotOffset * slotIndex), 200, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawPotionEffects() {
|
||||
int slotIndent = 26;
|
||||
if (BaubleExpandedSlots.slotsCurrentlyUsed() > 8) {
|
||||
slotIndent = 42;
|
||||
}
|
||||
int positionHorizontal = guiLeft - slotIndent - 124;
|
||||
int positionVertical = guiTop;
|
||||
Collection<PotionEffect> potionCollection = this.mc.thePlayer.getActivePotionEffects();
|
||||
|
||||
if (potionCollection.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
int maxNumber = 33;
|
||||
|
||||
if (potionCollection.size() > 5) {
|
||||
maxNumber = 132 / (potionCollection.size() - 1);
|
||||
}
|
||||
|
||||
for (PotionEffect effect : potionCollection) {
|
||||
Potion potion = Potion.potionTypes[effect.getPotionID()];
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(field_147001_a);
|
||||
this.drawTexturedModalRect(positionHorizontal, positionVertical, 0, 166, 140, 32);
|
||||
|
||||
if (potion.hasStatusIcon()) {
|
||||
int potionIconIndex = potion.getStatusIconIndex();
|
||||
this.drawTexturedModalRect(positionHorizontal + 6, positionVertical + 7, potionIconIndex % 8 * 18, 198 + potionIconIndex / 8 * 18, 18, 18);
|
||||
}
|
||||
|
||||
potion.renderInventoryEffect(positionHorizontal, positionVertical, effect, mc);
|
||||
if (!potion.shouldRenderInvText(effect)) continue;
|
||||
String potionName = I18n.format(potion.getName());
|
||||
|
||||
if (effect.getAmplifier() >= 1) {
|
||||
potionName = potionName + " " + I18n.format("enchantment.level." + effect.getAmplifier());
|
||||
}
|
||||
this.fontRendererObj.drawStringWithShadow(potionName, positionHorizontal + 10 + 18, positionVertical + 6, 16777215);
|
||||
String s = Potion.getDurationString(effect);
|
||||
this.fontRendererObj.drawStringWithShadow(s, positionHorizontal + 10 + 18, positionVertical + 6 + 10, 8355711);
|
||||
positionVertical += maxNumber;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needsScrollBars() {
|
||||
return ((ContainerPlayerExpanded) this.inventorySlots).canScroll();
|
||||
}
|
||||
|
||||
private void handleScrollbar(int mouseX, int mouseY) {
|
||||
boolean leftMouseDown = Mouse.isButtonDown(0);
|
||||
|
||||
if (!this.wasClicking && leftMouseDown && isClickInScrollbar(mouseX, mouseY)) {
|
||||
this.isScrolling = this.needsScrollBars();
|
||||
}
|
||||
|
||||
if (!leftMouseDown) {
|
||||
this.isScrolling = false;
|
||||
}
|
||||
|
||||
this.wasClicking = leftMouseDown;
|
||||
|
||||
if (this.isScrolling) {
|
||||
int scrollbarYStart = this.guiTop + 12;
|
||||
int scrollbarYEnd = scrollbarYStart + 139;
|
||||
|
||||
this.currentScroll = ((float) (mouseY - scrollbarYStart) - 7.5F) /
|
||||
((float) (scrollbarYEnd - scrollbarYStart) - 15.0F);
|
||||
|
||||
if (this.currentScroll < 0.0F) {
|
||||
this.currentScroll = 0.0F;
|
||||
}
|
||||
if (this.currentScroll > 1.0F) {
|
||||
this.currentScroll = 1.0F;
|
||||
}
|
||||
|
||||
((ContainerPlayerExpanded) this.inventorySlots).scrollTo(this.currentScroll);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
int wheel = Mouse.getEventDWheel();
|
||||
if (wheel == 0 || !this.needsScrollBars()) {
|
||||
return;
|
||||
}
|
||||
if (!hasLwjgl3) {
|
||||
// LWJGL2 reports different scroll values for every platform, 120 for one tick on Windows.
|
||||
// LWJGL3 reports the delta in exact scroll ticks.
|
||||
// Round away from zero to avoid dropping small scroll events
|
||||
if (wheel > 0) {
|
||||
wheel = Math.addExact(Math.addExact(wheel, 120), -1) / 120;
|
||||
} else {
|
||||
wheel = -(int) Math.addExact(Math.addExact(-wheel, 120), -1) / 120;
|
||||
}
|
||||
}
|
||||
int i = BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
this.currentScroll = (float) ((double) this.currentScroll - wheel / (double) i);
|
||||
this.currentScroll = MathHelper.clamp_float(this.currentScroll, 0.0F, 1.0F);
|
||||
((ContainerPlayerExpanded) this.inventorySlots).scrollTo(this.currentScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,4 +293,124 @@ public class GuiPlayerExpanded extends InventoryEffectRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) {
|
||||
if (slotIn != null && clickType == 4 && slotIn.xDisplayPosition < 0 && !useOldGuiRendering) {
|
||||
clickType = 0;
|
||||
}
|
||||
super.handleMouseClick(slotIn, slotId, clickedButton, clickType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (isClickInUI(mouseX, mouseY)) { // Prevent dropping items when clicking in UI
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int mouseButton) {
|
||||
if (isClickInUI(mouseX, mouseY)) { // Prevent dropping items when clicking in UI
|
||||
return;
|
||||
}
|
||||
|
||||
super.mouseMovedOrUp(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the mouse is clicked in the scroll bar.
|
||||
*/
|
||||
private boolean isClickInScrollbar(int mouseX, int mouseY) {
|
||||
int scrollbarXStart = this.guiLeft - 34;
|
||||
int scrollbarYStart = this.guiTop + 12;
|
||||
int scrollbarXEnd = scrollbarXStart + 14;
|
||||
int scrollbarYEnd = scrollbarYStart + 139;
|
||||
|
||||
return mouseX >= scrollbarXStart && mouseY >= scrollbarYStart &&
|
||||
mouseX < scrollbarXEnd && mouseY < scrollbarYEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the mouse is clicked in the scrollbar or the surrounding area.
|
||||
*/
|
||||
private boolean isClickInUI(int mouseX, int mouseY) {
|
||||
int scrollbarXStart = this.guiLeft - 42;
|
||||
int scrollbarYStart = this.guiTop + 5;
|
||||
int scrollbarXEnd = scrollbarXStart + 27;
|
||||
int scrollbarYEnd = scrollbarYStart + 156;
|
||||
|
||||
return mouseX >= scrollbarXStart && mouseY >= scrollbarYStart &&
|
||||
mouseX < scrollbarXEnd && mouseY < scrollbarYEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public Iterable<Integer> getItemSpawnSlots(GuiContainer gui, ItemStack item) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public List<TaggedInventoryArea> getInventoryAreas(GuiContainer gui) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Optional.Method(modid = "NotEnoughItems")
|
||||
public boolean hideItemPanelSlot(GuiContainer gui, int slotX, int slotY, int slotW, int slotH) {
|
||||
int upperHeight = 7 + BaubleExpandedSlots.slotsCurrentlyUsed() * 18;
|
||||
if (!(gui instanceof GuiPlayerExpanded) || useOldGuiRendering) {
|
||||
return false;
|
||||
}
|
||||
int slotIndent = 26;
|
||||
int slotWidth = 18;
|
||||
if (BaubleExpandedSlots.slotsCurrentlyUsed() > 8) {
|
||||
slotIndent = 42;
|
||||
slotWidth = 36;
|
||||
}
|
||||
if (NEIClientConfig.ignorePotionOverlap()) {
|
||||
return (new Rectangle4i( guiLeft - slotIndent, guiTop + 4, slotWidth, upperHeight + 4).intersects(new Rectangle4i(slotX, slotY, slotW, slotH)));
|
||||
}
|
||||
int x = this.guiLeft - 124 - slotIndent;
|
||||
int y = this.guiTop;
|
||||
Minecraft minecraft = gui.mc;
|
||||
if (minecraft == null) {
|
||||
return false;
|
||||
}
|
||||
EntityPlayerSP player = minecraft.thePlayer;
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
Collection<PotionEffect> activePotionEffects = player.getActivePotionEffects();
|
||||
if (activePotionEffects.isEmpty()) {
|
||||
return (new Rectangle4i( guiLeft - slotIndent, guiTop + 4, slotWidth, upperHeight + 4).intersects(new Rectangle4i(slotX, slotY, slotW, slotH)));
|
||||
}
|
||||
int height = 33;
|
||||
if (activePotionEffects.size() > 5) {
|
||||
height = 132 / (activePotionEffects.size() - 1);
|
||||
}
|
||||
Rectangle4i slotRect = new Rectangle4i(slotX, slotY, slotW, slotH);
|
||||
Rectangle4i baubleSlots = new Rectangle4i( guiLeft - slotIndent, guiTop + 4, slotWidth, upperHeight + 4);
|
||||
for (PotionEffect effect : activePotionEffects) {
|
||||
Rectangle4i box = new Rectangle4i(x, y, 140, 32);
|
||||
box.include(baubleSlots);
|
||||
if (box.intersects(slotRect)) return true;
|
||||
y += height;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ public class BaublesConfig {
|
||||
public static boolean hideDebugItem = true;
|
||||
|
||||
public static int[] soulBoundEnchantments = new int[] {};
|
||||
|
||||
public static boolean useOldGuiButton = false;
|
||||
public static boolean useOldGuiRendering = false;
|
||||
public static boolean showUnusedSlots = false;
|
||||
public static boolean manualSlotSelection = false;
|
||||
|
||||
@@ -23,6 +26,7 @@ public class BaublesConfig {
|
||||
static final String categoryDebug = "debug";
|
||||
static final String categoryGeneral = "general";
|
||||
static final String categoryMenu = "menu";
|
||||
static final String categoryClient = "client";
|
||||
static final String categoryOverride = "override";
|
||||
|
||||
public static void loadConfig(Configuration config) {
|
||||
@@ -38,6 +42,10 @@ public class BaublesConfig {
|
||||
"IDs of enchantments that should be treated as soul bound when on items in a bauble slot."
|
||||
).getIntList();
|
||||
|
||||
//categoryClient
|
||||
useOldGuiButton = config.getBoolean("useOldGuiButton", categoryClient, useOldGuiButton, "Use the old Baubles Button texture and location instead.\n");
|
||||
useOldGuiRendering = config.getBoolean("useOldRendering", categoryClient, useOldGuiRendering, "Display the old Bauble GUI instead of the new sidebar.\n");
|
||||
|
||||
//categoryMenu
|
||||
showUnusedSlots = config.getBoolean("showUnusedSlots", categoryMenu, showUnusedSlots, "Display unused Bauble slots.\n");
|
||||
manualSlotSelection = config.getBoolean("manualSlotSelection", categoryMenu, manualSlotSelection,
|
||||
@@ -51,11 +59,11 @@ public class BaublesConfig {
|
||||
config.getCategory(categoryOverride).get("defualtSlotTypes").set(currentSlotAssignments);
|
||||
|
||||
overrideSlotTypes = config.getStringList("slotTypeOverrides", categoryOverride, overrideSlotTypes,
|
||||
"Slot assignments to use if manualSlotSelection is enabled.\nAny assignents after the first " +
|
||||
"Slot assignments to use if manualSlotSelection is enabled.\nAny assignments after the first " +
|
||||
BaubleExpandedSlots.slotLimit + " will be ignored.\n!Adding, moving, or removing slots of the "
|
||||
+ BaubleExpandedSlots.amuletType + ", " + BaubleExpandedSlots.ringType + ", or " + BaubleExpandedSlots.beltType +
|
||||
" types will reduce compatibility with mods made for original Baubles versions!\n",
|
||||
currentlyRegisteredTypes.toArray(new String[currentlyRegisteredTypes.size()])
|
||||
currentlyRegisteredTypes.toArray(new String[0])
|
||||
);
|
||||
|
||||
if(manualSlotSelection) {
|
||||
|
||||
@@ -10,29 +10,51 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static baubles.common.BaublesConfig.useOldGuiRendering;
|
||||
|
||||
public class ContainerPlayerExpanded extends Container {
|
||||
|
||||
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
|
||||
public IInventory craftResult = new InventoryCraftResult();
|
||||
public InventoryBaubles baubles;
|
||||
|
||||
private final EntityPlayer thePlayer;
|
||||
|
||||
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean par2, EntityPlayer player) {
|
||||
public ContainerPlayerExpanded(InventoryPlayer playerInv, boolean isClient, EntityPlayer player) {
|
||||
this.thePlayer = player;
|
||||
baubles = new InventoryBaubles(player);
|
||||
baubles.setEventHandler(this);
|
||||
if (!player.worldObj.isRemote) {
|
||||
if (isClient) {
|
||||
baubles.stackList = PlayerHandler.getPlayerBaubles(player).stackList;
|
||||
}
|
||||
|
||||
int i;
|
||||
int j;
|
||||
|
||||
//armor
|
||||
if (!useOldGuiRendering) {
|
||||
this.addSlotToContainer(new SlotCrafting(playerInv.player, this.craftMatrix, this.craftResult, 0, 144, 36));
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
for (j = 0; j < 2; ++j) {
|
||||
this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Armor slots
|
||||
for (i = 0; i < 4; ++i) {
|
||||
final int k = i;
|
||||
this.addSlotToContainer(new Slot(playerInv, playerInv.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
|
||||
@@ -41,7 +63,7 @@ public class ContainerPlayerExpanded extends Container {
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack) {
|
||||
if (itemStack == null) return false;
|
||||
if (itemStack == null || itemStack.getItem() == null) return false;
|
||||
return itemStack.getItem().isValidArmor(itemStack, k, thePlayer);
|
||||
}
|
||||
|
||||
@@ -57,26 +79,93 @@ public class ContainerPlayerExpanded extends Container {
|
||||
final int slotStartX = 80;
|
||||
final int slotStartY = 8;
|
||||
|
||||
//bauble slots
|
||||
for(i = 0; i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(i);
|
||||
if(BaublesConfig.showUnusedSlots || !slotType.equals(BaubleExpandedSlots.unknownType)) {
|
||||
addSlotToContainer(new SlotBauble(baubles, slotType, i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4))));
|
||||
}
|
||||
}
|
||||
|
||||
//inventory slots
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
|
||||
// Bauble slots
|
||||
for (i = 0; i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
String slotType = BaubleExpandedSlots.getSlotType(i);
|
||||
if (BaublesConfig.showUnusedSlots || !slotType.equals(BaubleExpandedSlots.unknownType)) {
|
||||
if (useOldGuiRendering) {
|
||||
addSlotToContainer(new SlotBauble(baubles, slotType, i, slotStartX + (slotOffset * (i / 4)), slotStartY + (slotOffset * (i % 4))));
|
||||
} else {
|
||||
addSlotToContainer(new SlotBauble(baubles, slotType, i, -18, 12 + (slotOffset * i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//hotbar slots
|
||||
for (i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
|
||||
// Inventory slots
|
||||
for (i = 0; i < 3; ++i) {
|
||||
for (j = 0; j < 9; ++j) {
|
||||
this.addSlotToContainer(new Slot(playerInv, j + (i + 1) * 9, slotStartY + j * slotOffset, 84 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Hotbar slots
|
||||
for (i = 0; i < 9; ++i) {
|
||||
this.addSlotToContainer(new Slot(playerInv, i, slotStartY + i * slotOffset, 142));
|
||||
}
|
||||
|
||||
if (!useOldGuiRendering) {
|
||||
this.onCraftMatrixChanged(this.craftMatrix);
|
||||
this.scrollTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory par1IInventory) {
|
||||
if (!useOldGuiRendering) {
|
||||
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.thePlayer.worldObj));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer player) {
|
||||
super.onContainerClosed(player);
|
||||
if (useOldGuiRendering) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
|
||||
|
||||
if (itemstack != null) {
|
||||
if (!player.inventory.addItemStackToInventory(itemstack)) {
|
||||
player.dropPlayerItemWithRandomChoice(itemstack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.craftResult.setInventorySlotContents(0, null);
|
||||
if (!player.worldObj.isRemote) {
|
||||
PlayerHandler.setPlayerBaubles(player, baubles);
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollTo(float offset) {
|
||||
if (!canScroll()) return;
|
||||
final int activeBaubleSlots = BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
|
||||
offset = Math.max(0, Math.min(1, offset));
|
||||
|
||||
int shownSlots = 8;
|
||||
int slotOffset = (int) (offset * (activeBaubleSlots - shownSlots) + 0.5F);
|
||||
|
||||
if (slotOffset < 0) {
|
||||
slotOffset = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < activeBaubleSlots && i < BaubleExpandedSlots.slotLimit; i++) {
|
||||
//TODO: Find a way to not use a magic number to get to the correct ID range for the Slot editing.
|
||||
Slot slot = (Slot) this.inventorySlots.get(9 + i);
|
||||
if (i >= 0) {
|
||||
slot.yDisplayPosition = (12 - (slotOffset * 18) + (i) * 18);
|
||||
if (slot.yDisplayPosition < 12 || slot.yDisplayPosition > 8 * 18) {
|
||||
// Hide the rest of the slots!
|
||||
slot.yDisplayPosition = -2000;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canScroll() {
|
||||
return BaubleExpandedSlots.slotsCurrentlyUsed() > 8 && !useOldGuiRendering;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,75 +174,96 @@ public class ContainerPlayerExpanded extends Container {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
|
||||
* Called when a player shift-clicks on a slot. You must override this, or you will crash when someone does that.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||
ItemStack returnStack = null;
|
||||
Slot slot = (Slot)inventorySlots.get(slotIndex);
|
||||
final int visibleBaubleSlots = BaublesConfig.showUnusedSlots ? BaubleExpandedSlots.slotLimit : BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
|
||||
if(slot != null && slot.getHasStack()) {
|
||||
ItemStack originalStack = slot.getStack();
|
||||
returnStack = originalStack.copy();
|
||||
Item item = returnStack.getItem();
|
||||
|
||||
if(item instanceof ItemArmor && !((Slot)inventorySlots.get(((ItemArmor)item).armorType)).getHasStack()) {
|
||||
int armorSlot = ((ItemArmor)item).armorType;
|
||||
if(!mergeItemStack(originalStack, armorSlot, armorSlot + 1, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if(slotIndex >= 4 + visibleBaubleSlots && item instanceof IBauble && ((IBauble) item).canEquip(returnStack, thePlayer)) {
|
||||
for(int baubleSlot = 4; baubleSlot < 4 + visibleBaubleSlots; baubleSlot++) {
|
||||
if(returnStack == null) {
|
||||
break;
|
||||
}
|
||||
if(!((Slot)inventorySlots.get(baubleSlot)).getHasStack()) {
|
||||
String[] types;
|
||||
if(item instanceof IBaubleExpanded) {
|
||||
types = ((IBaubleExpanded)item).getBaubleTypes(returnStack);
|
||||
} else {
|
||||
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(((IBauble)item).getBaubleType(returnStack))};
|
||||
}
|
||||
for(String type : types) {
|
||||
if((type.equals(BaubleExpandedSlots.universalType) || type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4))) && !mergeItemStack(originalStack, baubleSlot, baubleSlot + 1, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(slotIndex >= 4 + visibleBaubleSlots && slotIndex < 31 + visibleBaubleSlots) {
|
||||
if(!mergeItemStack(originalStack, 31 + visibleBaubleSlots, 40 + visibleBaubleSlots, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if(slotIndex >= 31 + visibleBaubleSlots && slotIndex < 40 + visibleBaubleSlots) {
|
||||
if(!mergeItemStack(originalStack, 4 + visibleBaubleSlots, 31 + visibleBaubleSlots, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if(!mergeItemStack(originalStack, 4 + visibleBaubleSlots, 40 + visibleBaubleSlots, false, slot)) {
|
||||
returnStack = null;
|
||||
}
|
||||
|
||||
if(originalStack.stackSize <= 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if(returnStack != null && originalStack.stackSize == returnStack.stackSize) {
|
||||
returnStack = null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(player, originalStack);
|
||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||
final int visibleBaubleSlots = BaubleExpandedSlots.slotsCurrentlyUsed();
|
||||
int craftingActive = 5;
|
||||
if (useOldGuiRendering) {
|
||||
craftingActive = 0;
|
||||
}
|
||||
|
||||
if (slot == null || !slot.getHasStack()) {
|
||||
return returnStack;
|
||||
}
|
||||
ItemStack originalStack = slot.getStack();
|
||||
returnStack = originalStack.copy();
|
||||
Item item = returnStack.getItem();
|
||||
|
||||
if (!useOldGuiRendering) {
|
||||
if (slotIndex == 0) {
|
||||
if (!mergeItemStack(originalStack, 4 + craftingActive + visibleBaubleSlots, 40 + craftingActive + visibleBaubleSlots, true)) {
|
||||
return null;
|
||||
}
|
||||
slot.onSlotChange(originalStack, returnStack);
|
||||
} else if (slotIndex < 5) {
|
||||
if (!mergeItemStack(originalStack, 4 + craftingActive + visibleBaubleSlots, 40 + craftingActive + visibleBaubleSlots, false)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item instanceof ItemArmor armor && !((Slot) inventorySlots.get(craftingActive + armor.armorType)).getHasStack()) {
|
||||
int armorSlot = craftingActive + armor.armorType;
|
||||
if (!mergeItemStack(originalStack, armorSlot, armorSlot + 1, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if (slotIndex >= 4 + craftingActive + visibleBaubleSlots && item instanceof IBauble bauble && bauble.canEquip(returnStack, thePlayer)) {
|
||||
for (int baubleSlot = 4 + craftingActive; baubleSlot < 4 + craftingActive + visibleBaubleSlots; baubleSlot++) {
|
||||
if (returnStack == null) {
|
||||
break;
|
||||
}
|
||||
if (((Slot) inventorySlots.get(baubleSlot)).getHasStack()) {
|
||||
continue;
|
||||
}
|
||||
String[] types;
|
||||
if (item instanceof IBaubleExpanded) {
|
||||
types = ((IBaubleExpanded) item).getBaubleTypes(returnStack);
|
||||
} else {
|
||||
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(bauble.getBaubleType(returnStack))};
|
||||
}
|
||||
for (String type : types) {
|
||||
if ((type.equals(BaubleExpandedSlots.universalType)
|
||||
|| type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4 - craftingActive)))
|
||||
&& !mergeItemStack(originalStack, baubleSlot, baubleSlot + 1, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (slotIndex >= 4 + craftingActive + visibleBaubleSlots && slotIndex < 31 + craftingActive + visibleBaubleSlots) {
|
||||
if (!mergeItemStack(originalStack, 31 + craftingActive + visibleBaubleSlots, 40 + craftingActive + visibleBaubleSlots, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if (slotIndex >= 31 + craftingActive + visibleBaubleSlots && slotIndex < 40 + craftingActive + visibleBaubleSlots) {
|
||||
if (!mergeItemStack(originalStack, 4 + craftingActive + visibleBaubleSlots, 31 + craftingActive + visibleBaubleSlots, false)) {
|
||||
returnStack = null;
|
||||
}
|
||||
} else if (!mergeItemStack(originalStack, 4 + craftingActive + visibleBaubleSlots, 40 + craftingActive + visibleBaubleSlots, false, slot)) {
|
||||
returnStack = null;
|
||||
}
|
||||
|
||||
if (originalStack.stackSize <= 0) {
|
||||
slot.putStack(null);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (returnStack != null && originalStack.stackSize == returnStack.stackSize) {
|
||||
returnStack = null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(player, originalStack);
|
||||
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
private void unequipBauble(ItemStack stack) {
|
||||
// if (stack.getItem() instanceof IBauble) {
|
||||
// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer);
|
||||
// }
|
||||
//if (stack.getItem() instanceof IBauble) {
|
||||
// ((IBauble)stack.getItem()).onUnequipped(stack, thePlayer);
|
||||
//}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -162,75 +272,67 @@ public class ContainerPlayerExpanded extends Container {
|
||||
super.putStacksInSlots(p_75131_1_);
|
||||
}
|
||||
|
||||
protected boolean mergeItemStack(ItemStack itemStack, int par2, int par3, boolean par4, Slot ss) {
|
||||
boolean flag1 = false;
|
||||
int k = par2;
|
||||
protected boolean mergeItemStack(ItemStack sourceStack, int startIndex, int endIndex, boolean reverse, Slot sourceSlot) {
|
||||
boolean merged = false;
|
||||
int index = reverse ? endIndex - 1 : startIndex;
|
||||
|
||||
if (par4) {
|
||||
k = par3 - 1;
|
||||
}
|
||||
Slot targetSlot;
|
||||
ItemStack targetStack;
|
||||
|
||||
Slot slot;
|
||||
ItemStack itemstack1;
|
||||
// First pass: try stacking into existing stacks
|
||||
if (sourceStack.isStackable()) {
|
||||
while (sourceStack.stackSize > 0 && (!reverse && index < endIndex || reverse && index >= startIndex)) {
|
||||
targetSlot = (Slot) inventorySlots.get(index);
|
||||
targetStack = targetSlot.getStack();
|
||||
|
||||
if (itemStack.isStackable()) {
|
||||
while (itemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) {
|
||||
slot = (Slot)inventorySlots.get(k);
|
||||
itemstack1 = slot.getStack();
|
||||
if (targetStack != null && targetStack.getItem() == sourceStack.getItem() &&
|
||||
(!sourceStack.getHasSubtypes() || sourceStack.getItemDamage() == targetStack.getItemDamage()) &&
|
||||
ItemStack.areItemStackTagsEqual(sourceStack, targetStack)) {
|
||||
|
||||
if (itemstack1 != null && itemstack1.getItem() == itemStack.getItem() && (!itemStack.getHasSubtypes() || itemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemStack, itemstack1)) {
|
||||
int l = itemstack1.stackSize + itemStack.stackSize;
|
||||
if (l <= itemStack.getMaxStackSize()) {
|
||||
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
||||
itemStack.stackSize = 0;
|
||||
itemstack1.stackSize = l;
|
||||
slot.onSlotChanged();
|
||||
flag1 = true;
|
||||
} else if (itemstack1.stackSize < itemStack.getMaxStackSize()) {
|
||||
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
||||
itemStack.stackSize -= itemStack.getMaxStackSize() - itemstack1.stackSize;
|
||||
itemstack1.stackSize = itemStack.getMaxStackSize();
|
||||
slot.onSlotChanged();
|
||||
flag1 = true;
|
||||
int combinedSize = targetStack.stackSize + sourceStack.stackSize;
|
||||
|
||||
if (combinedSize <= sourceStack.getMaxStackSize()) {
|
||||
if (sourceSlot instanceof SlotBauble) {
|
||||
unequipBauble(sourceStack);
|
||||
}
|
||||
sourceStack.stackSize = 0;
|
||||
targetStack.stackSize = combinedSize;
|
||||
targetSlot.onSlotChanged();
|
||||
return true;
|
||||
} else if (targetStack.stackSize < sourceStack.getMaxStackSize()) {
|
||||
if (sourceSlot instanceof SlotBauble) {
|
||||
unequipBauble(sourceStack);
|
||||
}
|
||||
sourceStack.stackSize -= sourceStack.getMaxStackSize() - targetStack.stackSize;
|
||||
targetStack.stackSize = sourceStack.getMaxStackSize();
|
||||
targetSlot.onSlotChanged();
|
||||
merged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (par4) {
|
||||
--k;
|
||||
} else {
|
||||
++k;
|
||||
}
|
||||
index = reverse ? index - 1 : index + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack.stackSize > 0) {
|
||||
if (par4) {
|
||||
k = par3 - 1;
|
||||
} else {
|
||||
k = par2;
|
||||
// Second pass: put into empty slots
|
||||
index = reverse ? endIndex - 1 : startIndex;
|
||||
while (!reverse && index < endIndex || reverse && index >= startIndex) {
|
||||
targetSlot = (Slot) inventorySlots.get(index);
|
||||
targetStack = targetSlot.getStack();
|
||||
|
||||
if (targetStack == null) {
|
||||
if (sourceSlot instanceof SlotBauble) {
|
||||
unequipBauble(sourceStack);
|
||||
}
|
||||
targetSlot.putStack(sourceStack.copy());
|
||||
targetSlot.onSlotChanged();
|
||||
sourceStack.stackSize = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
while (!par4 && k < par3 || par4 && k >= par2) {
|
||||
slot = (Slot)inventorySlots.get(k);
|
||||
itemstack1 = slot.getStack();
|
||||
|
||||
if (itemstack1 == null) {
|
||||
if (ss instanceof SlotBauble) unequipBauble(itemStack);
|
||||
slot.putStack(itemStack.copy());
|
||||
slot.onSlotChanged();
|
||||
itemStack.stackSize = 0;
|
||||
flag1 = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (par4) {
|
||||
--k;
|
||||
} else {
|
||||
++k;
|
||||
}
|
||||
}
|
||||
index = reverse ? index - 1 : index + 1;
|
||||
}
|
||||
return flag1;
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package baubles.common.event;
|
||||
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import baubles.common.network.PacketHandler;
|
||||
import baubles.common.network.PacketOpenBaublesInventory;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
@@ -5,16 +5,12 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class PacketHandler
|
||||
{
|
||||
public class PacketHandler {
|
||||
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Baubles.MODID.toLowerCase());
|
||||
|
||||
public static void init()
|
||||
{
|
||||
public static void init() {
|
||||
INSTANCE.registerMessage(PacketOpenBaublesInventory.class, PacketOpenBaublesInventory.class, 0, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketOpenNormalInventory.class, PacketOpenNormalInventory.class, 1, Side.SERVER);
|
||||
INSTANCE.registerMessage(PacketSyncBauble.class, PacketSyncBauble.class, 2, Side.CLIENT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketOpenBaublesInventory implements IMessage, IMessageHandler<PacketOpenBaublesInventory, IMessage> {
|
||||
|
||||
|
||||
public PacketOpenBaublesInventory() {}
|
||||
|
||||
|
||||
public PacketOpenBaublesInventory(EntityPlayer player) {}
|
||||
|
||||
@Override
|
||||
@@ -24,6 +24,4 @@ public class PacketOpenBaublesInventory implements IMessage, IMessageHandler<Pac
|
||||
ctx.getServerHandler().playerEntity.openGui(Baubles.instance, Baubles.GUI, ctx.getServerHandler().playerEntity.worldObj, (int)ctx.getServerHandler().playerEntity.posX, (int)ctx.getServerHandler().playerEntity.posY, (int)ctx.getServerHandler().playerEntity.posZ);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketOpenNormalInventory implements IMessage, IMessageHandler<PacketOpenNormalInventory, IMessage> {
|
||||
|
||||
|
||||
public PacketOpenNormalInventory() {}
|
||||
|
||||
|
||||
public PacketOpenNormalInventory(EntityPlayer player) {}
|
||||
|
||||
@Override
|
||||
@@ -20,10 +20,8 @@ public class PacketOpenNormalInventory implements IMessage, IMessageHandler<Pack
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketOpenNormalInventory message, MessageContext ctx) {
|
||||
ctx.getServerHandler().playerEntity.openContainer.onContainerClosed(ctx.getServerHandler().playerEntity);
|
||||
ctx.getServerHandler().playerEntity.openContainer.onContainerClosed(ctx.getServerHandler().playerEntity);
|
||||
ctx.getServerHandler().playerEntity.openContainer = ctx.getServerHandler().playerEntity.inventoryContainer;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -15,13 +15,13 @@ import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PacketSyncBauble implements IMessage, IMessageHandler<PacketSyncBauble, IMessage> {
|
||||
|
||||
|
||||
int slot;
|
||||
int playerId;
|
||||
ItemStack bauble=null;
|
||||
|
||||
ItemStack bauble = null;
|
||||
|
||||
public PacketSyncBauble() {}
|
||||
|
||||
|
||||
public PacketSyncBauble(EntityPlayer player, int slot) {
|
||||
this.slot = slot;
|
||||
this.bauble = PlayerHandler.getPlayerBaubles(player).getStackInSlot(slot);
|
||||
@@ -33,28 +33,25 @@ public class PacketSyncBauble implements IMessage, IMessageHandler<PacketSyncBau
|
||||
buffer.writeByte(slot);
|
||||
buffer.writeInt(playerId);
|
||||
PacketBuffer pb = new PacketBuffer(buffer);
|
||||
try { pb.writeItemStackToBuffer(bauble); } catch (IOException e) {}
|
||||
try { pb.writeItemStackToBuffer(bauble); } catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buffer)
|
||||
{
|
||||
public void fromBytes(ByteBuf buffer) {
|
||||
slot = buffer.readByte();
|
||||
playerId = buffer.readInt();
|
||||
PacketBuffer pb = new PacketBuffer(buffer);
|
||||
try { bauble = pb.readItemStackFromBuffer(); } catch (IOException e) {}
|
||||
try { bauble = pb.readItemStackFromBuffer(); } catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketSyncBauble message, MessageContext ctx) {
|
||||
World world = Baubles.proxy.getClientWorld();
|
||||
if (world==null) return null;
|
||||
Entity p = world.getEntityByID(message.playerId);
|
||||
if (p !=null && p instanceof EntityPlayer) {
|
||||
PlayerHandler.getPlayerBaubles((EntityPlayer) p).stackList[message.slot]=message.bauble;
|
||||
if (world == null) return null;
|
||||
Entity e = world.getEntityByID(message.playerId);
|
||||
if (e instanceof EntityPlayer player) {
|
||||
PlayerHandler.getPlayerBaubles(player).stackList[message.slot]=message.bauble;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Reference in new issue
Block a user