ForgePatch/patches/minecraft/net/minecraft/client/gui/screen/inventory/CreativeScreen.java.patch

279 lines
13 KiB
Diff

--- a/net/minecraft/client/gui/screen/inventory/CreativeScreen.java
+++ b/net/minecraft/client/gui/screen/inventory/CreativeScreen.java
@@ -65,6 +65,8 @@
private boolean field_195377_F;
private boolean field_199506_G;
private final Map<ResourceLocation, Tag<Item>> field_214085_w = Maps.newTreeMap();
+ private static int tabPage = 0;
+ private int maxPages = 0;
public CreativeScreen(PlayerEntity p_i1088_1_) {
super(new CreativeScreen.CreativeContainer(p_i1088_1_), p_i1088_1_.field_71071_by, new StringTextComponent(""));
@@ -233,6 +235,12 @@
if (this.minecraft.field_71442_b.func_78758_h()) {
super.init();
this.minecraft.field_195559_v.func_197967_a(true);
+ int tabCount = ItemGroup.field_78032_a.length;
+ if (tabCount > 12) {
+ addButton(new net.minecraft.client.gui.widget.button.Button(field_147003_i, field_147009_r - 50, 20, 20, "<", b -> tabPage = Math.max(tabPage - 1, 0 )));
+ addButton(new net.minecraft.client.gui.widget.button.Button(field_147003_i + field_146999_f - 20, field_147009_r - 50, 20, 20, ">", b -> tabPage = Math.min(tabPage + 1, maxPages)));
+ maxPages = (int) Math.ceil((tabCount - 12) / 10D);
+ }
this.field_147062_A = new TextFieldWidget(this.font, this.field_147003_i + 82, this.field_147009_r + 6, 80, 9, I18n.func_135052_a("itemGroup.search"));
this.field_147062_A.func_146203_f(50);
this.field_147062_A.func_146185_a(false);
@@ -273,7 +281,7 @@
public boolean charTyped(char p_charTyped_1_, int p_charTyped_2_) {
if (this.field_195377_F) {
return false;
- } else if (field_147058_w != ItemGroup.field_78027_g.func_78021_a()) {
+ } else if (!ItemGroup.field_78032_a[field_147058_w].hasSearchBar()) {
return false;
} else {
String s = this.field_147062_A.func_146179_b();
@@ -291,7 +299,7 @@
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
this.field_195377_F = false;
- if (field_147058_w != ItemGroup.field_78027_g.func_78021_a()) {
+ if (!ItemGroup.field_78032_a[field_147058_w].hasSearchBar()) {
if (this.minecraft.field_71474_y.field_74310_D.func_197976_a(p_keyPressed_1_, p_keyPressed_2_)) {
this.field_195377_F = true;
this.func_147050_b(ItemGroup.field_78027_g);
@@ -327,6 +335,32 @@
private void func_147053_i() {
(this.field_147002_h).field_148330_a.clear();
this.field_214085_w.clear();
+
+ ItemGroup tab = ItemGroup.field_78032_a[field_147058_w];
+ if (tab.hasSearchBar() && tab != ItemGroup.field_78027_g) {
+ tab.func_78018_a(field_147002_h.field_148330_a);
+ if (!this.field_147062_A.func_146179_b().isEmpty()) {
+ //TODO: Make this a SearchTree not a manual search
+ String search = this.field_147062_A.func_146179_b().toLowerCase(Locale.ROOT);
+ java.util.Iterator<ItemStack> itr = field_147002_h.field_148330_a.iterator();
+ while (itr.hasNext()) {
+ ItemStack stack = itr.next();
+ boolean matches = false;
+ for (ITextComponent line : stack.func_82840_a(this.minecraft.field_71439_g, this.minecraft.field_71474_y.field_82882_x ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL)) {
+ if (TextFormatting.func_110646_a(line.getString()).toLowerCase(Locale.ROOT).contains(search)) {
+ matches = true;
+ break;
+ }
+ }
+ if (!matches)
+ itr.remove();
+ }
+ }
+ this.field_147067_x = 0.0F;
+ field_147002_h.func_148329_a(0.0F);
+ return;
+ }
+
String s = this.field_147062_A.func_146179_b();
if (s.isEmpty()) {
for(Item item : Registry.field_212630_s) {
@@ -372,9 +406,9 @@
protected void func_146979_b(int p_146979_1_, int p_146979_2_) {
ItemGroup itemgroup = ItemGroup.field_78032_a[field_147058_w];
- if (itemgroup.func_78019_g()) {
+ if (itemgroup != null && itemgroup.func_78019_g()) {
RenderSystem.disableBlend();
- this.font.func_211126_b(I18n.func_135052_a(itemgroup.func_78024_c()), 8.0F, 6.0F, 4210752);
+ this.font.func_211126_b(I18n.func_135052_a(itemgroup.func_78024_c()), 8.0F, 6.0F, itemgroup.getLabelColor());
}
}
@@ -385,7 +419,7 @@
double d1 = p_mouseClicked_3_ - (double)this.field_147009_r;
for(ItemGroup itemgroup : ItemGroup.field_78032_a) {
- if (this.func_195375_a(itemgroup, d0, d1)) {
+ if (itemgroup != null && this.func_195375_a(itemgroup, d0, d1)) {
return true;
}
}
@@ -406,7 +440,7 @@
this.field_147066_y = false;
for(ItemGroup itemgroup : ItemGroup.field_78032_a) {
- if (this.func_195375_a(itemgroup, d0, d1)) {
+ if (itemgroup != null && this.func_195375_a(itemgroup, d0, d1)) {
this.func_147050_b(itemgroup);
return true;
}
@@ -417,12 +451,15 @@
}
private boolean func_147055_p() {
+ if (ItemGroup.field_78032_a[field_147058_w] == null) return false;
return field_147058_w != ItemGroup.field_78036_m.func_78021_a() && ItemGroup.field_78032_a[field_147058_w].func_78017_i() && this.field_147002_h.func_148328_e();
}
private void func_147050_b(ItemGroup p_147050_1_) {
+ if (p_147050_1_ == null) return;
int i = field_147058_w;
field_147058_w = p_147050_1_.func_78021_a();
+ slotColor = p_147050_1_.getSlotColor();
this.field_147008_s.clear();
(this.field_147002_h).field_148330_a.clear();
if (p_147050_1_ == ItemGroup.field_192395_m) {
@@ -499,13 +536,15 @@
}
if (this.field_147062_A != null) {
- if (p_147050_1_ == ItemGroup.field_78027_g) {
+ if (p_147050_1_.hasSearchBar()) {
this.field_147062_A.func_146189_e(true);
this.field_147062_A.func_146205_d(false);
this.field_147062_A.func_146195_b(true);
if (i != p_147050_1_.func_78021_a()) {
this.field_147062_A.func_146180_a("");
}
+ this.field_147062_A.setWidth(p_147050_1_.getSearchbarWidth());
+ this.field_147062_A.x = this.field_147003_i + (82 /*default left*/ + 89 /*default width*/) - this.field_147062_A.getWidth();
this.func_147053_i();
} else {
@@ -565,16 +604,35 @@
this.renderBackground();
super.render(p_render_1_, p_render_2_, p_render_3_);
- for(ItemGroup itemgroup : ItemGroup.field_78032_a) {
- if (this.func_147052_b(itemgroup, p_render_1_, p_render_2_)) {
+ int start = tabPage * 10;
+ int end = Math.min(ItemGroup.field_78032_a.length, ((tabPage + 1) * 10) + 2);
+ if (tabPage != 0) start += 2;
+ boolean rendered = false;
+
+ for (int x = start; x < end; x++) {
+ ItemGroup itemgroup = ItemGroup.field_78032_a[x];
+ if (itemgroup != null && this.func_147052_b(itemgroup, p_render_1_, p_render_2_)) {
+ rendered = true;
break;
}
}
+ if (!rendered && !func_147052_b(ItemGroup.field_78027_g, p_render_1_, p_render_2_))
+ func_147052_b(ItemGroup.field_78036_m, p_render_1_, p_render_2_);
if (this.field_147064_C != null && field_147058_w == ItemGroup.field_78036_m.func_78021_a() && this.func_195359_a(this.field_147064_C.field_75223_e, this.field_147064_C.field_75221_f, 16, 16, (double)p_render_1_, (double)p_render_2_)) {
this.renderTooltip(I18n.func_135052_a("inventory.binSlot"), p_render_1_, p_render_2_);
}
+ if (maxPages != 0) {
+ String page = String.format("%d / %d", tabPage + 1, maxPages + 1);
+ RenderSystem.disableLighting();
+ this.setBlitOffset(300);
+ this.itemRenderer.field_77023_b = 300.0F;
+ font.func_211126_b(page, field_147003_i + (field_146999_f / 2) - (font.func_78256_a(page) / 2), field_147009_r - 44, -1);
+ this.setBlitOffset(0);
+ this.itemRenderer.field_77023_b = 0.0F;
+ }
+
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.func_191948_b(p_render_1_, p_render_2_);
}
@@ -622,7 +680,10 @@
}
}
- this.renderTooltip(list1, p_renderTooltip_2_, p_renderTooltip_3_);
+ net.minecraft.client.gui.FontRenderer font = p_renderTooltip_1_.func_77973_b().getFontRenderer(p_renderTooltip_1_);
+ net.minecraftforge.fml.client.gui.GuiUtils.preItemToolTip(p_renderTooltip_1_);
+ this.renderTooltip(list1, p_renderTooltip_2_, p_renderTooltip_3_, (font == null ? this.font : font));
+ net.minecraftforge.fml.client.gui.GuiUtils.postItemToolTip();
} else {
super.renderTooltip(p_renderTooltip_1_, p_renderTooltip_2_, p_renderTooltip_3_);
}
@@ -633,25 +694,44 @@
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
ItemGroup itemgroup = ItemGroup.field_78032_a[field_147058_w];
- for(ItemGroup itemgroup1 : ItemGroup.field_78032_a) {
- this.minecraft.func_110434_K().func_110577_a(field_147061_u);
- if (itemgroup1.func_78021_a() != field_147058_w) {
+ int start = tabPage * 10;
+ int end = Math.min(ItemGroup.field_78032_a.length, ((tabPage + 1) * 10 + 2));
+ if (tabPage != 0) start += 2;
+
+ for (int idx = start; idx < end; idx++) {
+ ItemGroup itemgroup1 = ItemGroup.field_78032_a[idx];
+ if (itemgroup1 != null && itemgroup1.func_78021_a() != field_147058_w) {
+ this.minecraft.func_110434_K().func_110577_a(itemgroup1.getTabsImage());
this.func_147051_a(itemgroup1);
}
}
- this.minecraft.func_110434_K().func_110577_a(new ResourceLocation("textures/gui/container/creative_inventory/tab_" + itemgroup.func_78015_f()));
+ if (tabPage != 0) {
+ if (itemgroup != ItemGroup.field_78027_g) {
+ this.minecraft.func_110434_K().func_110577_a(ItemGroup.field_78027_g.getTabsImage());
+ func_147051_a(ItemGroup.field_78027_g);
+ }
+ if (itemgroup != ItemGroup.field_78036_m) {
+ this.minecraft.func_110434_K().func_110577_a(ItemGroup.field_78036_m.getTabsImage());
+ func_147051_a(ItemGroup.field_78036_m);
+ }
+ }
+
+ this.minecraft.func_110434_K().func_110577_a(itemgroup.getBackgroundImage());
this.blit(this.field_147003_i, this.field_147009_r, 0, 0, this.field_146999_f, this.field_147000_g);
this.field_147062_A.render(p_146976_2_, p_146976_3_, p_146976_1_);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
int i = this.field_147003_i + 175;
int j = this.field_147009_r + 18;
int k = j + 112;
- this.minecraft.func_110434_K().func_110577_a(field_147061_u);
+ this.minecraft.func_110434_K().func_110577_a(itemgroup.getTabsImage());
if (itemgroup.func_78017_i()) {
this.blit(i, j + (int)((float)(k - j - 17) * this.field_147067_x), 232 + (this.func_147055_p() ? 0 : 12), 0, 12, 15);
}
+ if ((itemgroup == null || itemgroup.getTabPage() != tabPage) && (itemgroup != ItemGroup.field_78027_g && itemgroup != ItemGroup.field_78036_m))
+ return;
+
this.func_147051_a(itemgroup);
if (itemgroup == ItemGroup.field_78036_m) {
InventoryScreen.func_228187_a_(this.field_147003_i + 88, this.field_147009_r + 45, 20, (float)(this.field_147003_i + 88 - p_146976_2_), (float)(this.field_147009_r + 45 - 30 - p_146976_3_), this.minecraft.field_71439_g);
@@ -660,6 +740,7 @@
}
protected boolean func_195375_a(ItemGroup p_195375_1_, double p_195375_2_, double p_195375_4_) {
+ if (p_195375_1_.getTabPage() != tabPage && p_195375_1_ != ItemGroup.field_78027_g && p_195375_1_ != ItemGroup.field_78036_m) return false;
int i = p_195375_1_.func_78020_k();
int j = 28 * i;
int k = 0;
@@ -728,6 +809,8 @@
i1 = i1 + (this.field_147000_g - 4);
}
+ RenderSystem.color3f(1F, 1F, 1F); //Forge: Reset color in case Items change it.
+ RenderSystem.enableBlend(); //Forge: Make sure blend is enabled else tabs show a white border.
this.blit(l, i1, j, k, 28, 32);
this.setBlitOffset(100);
this.itemRenderer.field_77023_b = 100.0F;
@@ -896,6 +979,22 @@
public boolean func_82869_a(PlayerEntity p_82869_1_) {
return this.field_148332_b.func_82869_a(p_82869_1_);
}
+
+ @Override
+ public int getSlotIndex() {
+ return this.field_148332_b.getSlotIndex();
+ }
+
+ @Override
+ public boolean isSameInventory(Slot other) {
+ return this.field_148332_b.isSameInventory(other);
+ }
+
+ @Override
+ public Slot setBackground(ResourceLocation atlas, ResourceLocation sprite) {
+ this.field_148332_b.setBackground(atlas, sprite);
+ return this;
+ }
}
@OnlyIn(Dist.CLIENT)