mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
[1.18.x] Fix Banner Patterns not being extensible (#8530)
Co-authored-by: Curle <[email protected]>
This commit is contained in:
1 parent
d4c8708229
commit
f179eed971
8 files changed
+177
-1
No files matched your search
@@ -0,0 +1,44 @@
|
||||
--- a/net/minecraft/client/gui/screens/inventory/LoomScreen.java
|
||||
+++ b/net/minecraft/client/gui/screens/inventory/LoomScreen.java
|
||||
@@ -125,20 +_,20 @@
|
||||
int l2 = j + 13;
|
||||
int l = this.f_99072_ + 16;
|
||||
|
||||
- for(int i1 = this.f_99072_; i1 < l && i1 < BannerPattern.f_58526_ - BannerPattern.f_58527_; ++i1) {
|
||||
+ for(int i1 = this.f_99072_; i1 < l && i1 < net.minecraftforge.common.ForgeHooks.getNonPatternItemCount(); ++i1) {
|
||||
int j1 = i1 - this.f_99072_;
|
||||
int k1 = j2 + j1 % 4 * 14;
|
||||
int l1 = l2 + j1 / 4 * 14;
|
||||
RenderSystem.m_157456_(0, f_99060_);
|
||||
int i2 = this.f_97727_;
|
||||
- if (i1 == this.f_97732_.m_39891_()) {
|
||||
+ if (net.minecraftforge.common.ForgeHooks.getActualPatternIndex(i1) == this.f_97732_.m_39891_()) {
|
||||
i2 += 14;
|
||||
} else if (p_99101_ >= k1 && p_99102_ >= l1 && p_99101_ < k1 + 14 && p_99102_ < l1 + 14) {
|
||||
i2 += 28;
|
||||
}
|
||||
|
||||
this.m_93228_(p_99099_, k1, l1, 0, i2, 14, 14);
|
||||
- this.m_99108_(i1, k1, l1);
|
||||
+ this.m_99108_(net.minecraftforge.common.ForgeHooks.getActualPatternIndex(i1), k1, l1);
|
||||
}
|
||||
} else if (this.f_99068_) {
|
||||
int k2 = i + 60;
|
||||
@@ -209,7 +_,7 @@
|
||||
int j = i + 56;
|
||||
this.f_99070_ = ((float)p_99088_ - (float)i - 7.5F) / ((float)(j - i) - 15.0F);
|
||||
this.f_99070_ = Mth.m_14036_(this.f_99070_, 0.0F, 1.0F);
|
||||
- int k = f_99061_ - 4;
|
||||
+ int k = net.minecraftforge.common.ForgeHooks.getTotalPatternRows() - 4;
|
||||
int l = (int)((double)(this.f_99070_ * (float)k) + 0.5D);
|
||||
if (l < 0) {
|
||||
l = 0;
|
||||
@@ -224,7 +_,7 @@
|
||||
|
||||
public boolean m_6050_(double p_99079_, double p_99080_, double p_99081_) {
|
||||
if (this.f_99067_) {
|
||||
- int i = f_99061_ - 4;
|
||||
+ int i = net.minecraftforge.common.ForgeHooks.getTotalPatternRows() - 4;
|
||||
float f = (float)p_99081_ / (float)i;
|
||||
this.f_99070_ = Mth.m_14036_(this.f_99070_ - f, 0.0F, 1.0F);
|
||||
this.f_99072_ = 1 + (int)(this.f_99070_ * (float)i + 0.5F) * 4;
|
||||
@@ -0,0 +1,22 @@
|
||||
--- a/net/minecraft/world/inventory/LoomMenu.java
|
||||
+++ b/net/minecraft/world/inventory/LoomMenu.java
|
||||
@@ -114,8 +_,8 @@
|
||||
}
|
||||
|
||||
public boolean m_6366_(Player p_39867_, int p_39868_) {
|
||||
- if (p_39868_ > 0 && p_39868_ <= BannerPattern.f_58528_) {
|
||||
- this.f_39846_.m_6422_(p_39868_);
|
||||
+ if (p_39868_ > 0 && p_39868_ <= net.minecraftforge.common.ForgeHooks.getNonPatternItemCount() - 1) {
|
||||
+ this.f_39846_.m_6422_(net.minecraftforge.common.ForgeHooks.getActualPatternIndex(p_39868_));
|
||||
this.m_39898_();
|
||||
return true;
|
||||
} else {
|
||||
@@ -128,7 +_,7 @@
|
||||
ItemStack itemstack1 = this.f_39849_.m_7993_();
|
||||
ItemStack itemstack2 = this.f_39850_.m_7993_();
|
||||
ItemStack itemstack3 = this.f_39851_.m_7993_();
|
||||
- if (itemstack3.m_41619_() || !itemstack.m_41619_() && !itemstack1.m_41619_() && this.f_39846_.m_6501_() > 0 && (this.f_39846_.m_6501_() < BannerPattern.f_58526_ - BannerPattern.f_58527_ || !itemstack2.m_41619_())) {
|
||||
+ if (itemstack3.m_41619_() || !itemstack.m_41619_() && !itemstack1.m_41619_() && this.f_39846_.m_6501_() > 0 && (this.f_39846_.m_6501_() < net.minecraftforge.common.ForgeHooks.getNonPatternItemCount() || !itemstack2.m_41619_())) {
|
||||
if (!itemstack2.m_41619_() && itemstack2.m_41720_() instanceof BannerPatternItem) {
|
||||
CompoundTag compoundtag = BlockItem.m_186336_(itemstack);
|
||||
boolean flag = compoundtag != null && compoundtag.m_128425_("Patterns", 9) && !itemstack.m_41619_() && compoundtag.m_128437_("Patterns", 10).size() >= 6;
|
||||
@@ -0,0 +1,12 @@
|
||||
--- a/net/minecraft/world/item/BannerItem.java
|
||||
+++ b/net/minecraft/world/item/BannerItem.java
|
||||
@@ -32,7 +_,8 @@
|
||||
DyeColor dyecolor = DyeColor.m_41053_(compoundtag1.m_128451_("Color"));
|
||||
BannerPattern bannerpattern = BannerPattern.m_58575_(compoundtag1.m_128461_("Pattern"));
|
||||
if (bannerpattern != null) {
|
||||
- p_40544_.add((new TranslatableComponent("block.minecraft.banner." + bannerpattern.m_58572_() + "." + dyecolor.m_41065_())).m_130940_(ChatFormatting.GRAY));
|
||||
+ net.minecraft.resources.ResourceLocation fileLoc = new net.minecraft.resources.ResourceLocation(bannerpattern.m_58572_());
|
||||
+ p_40544_.add((new TranslatableComponent("block." + fileLoc.m_135827_() + ".banner." + fileLoc.m_135815_() + "." + dyecolor.m_41065_())).m_130940_(ChatFormatting.GRAY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,34 @@
|
||||
BASE("base", "b", false),
|
||||
SQUARE_BOTTOM_LEFT("square_bottom_left", "bl"),
|
||||
SQUARE_BOTTOM_RIGHT("square_bottom_right", "br"),
|
||||
@@ -106,6 +_,14 @@
|
||||
@@ -54,10 +_,16 @@
|
||||
PIGLIN("piglin", "pig", true);
|
||||
|
||||
private static final BannerPattern[] f_58529_ = values();
|
||||
+ /** @deprecated Use {@link BannerPattern#values()} and get the length from the array **/
|
||||
+ @Deprecated
|
||||
public static final int f_58526_ = f_58529_.length;
|
||||
+ /** @deprecated Subtract {@link net.minecraftforge.common.ForgeHooks#getNonPatternItemCount()} from {@link BannerPattern#values()} **/
|
||||
+ @Deprecated
|
||||
public static final int f_58527_ = (int)Arrays.stream(f_58529_).filter((p_58581_) -> {
|
||||
return p_58581_.f_58530_;
|
||||
}).count();
|
||||
+ /** @deprecated Subtract 1 from {@link net.minecraftforge.common.ForgeHooks#getNonPatternItemCount()} to get the maximum non-pattern item index**/
|
||||
+ @Deprecated
|
||||
public static final int f_58528_ = f_58526_ - f_58527_ - 1;
|
||||
public final boolean f_58530_;
|
||||
private final String f_58531_;
|
||||
@@ -75,7 +_,8 @@
|
||||
|
||||
public ResourceLocation m_58577_(boolean p_58578_) {
|
||||
String s = p_58578_ ? "banner" : "shield";
|
||||
- return new ResourceLocation("entity/" + s + "/" + this.m_58572_());
|
||||
+ ResourceLocation fileLoc = new ResourceLocation(this.m_58572_());
|
||||
+ return new ResourceLocation(fileLoc.m_135827_(), "entity/" + s + "/" + fileLoc.m_135815_());
|
||||
}
|
||||
|
||||
public String m_58572_() {
|
||||
@@ -106,6 +_,19 @@
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -21,6 +48,11 @@
|
||||
+
|
||||
+ public static BannerPattern create(String enumName, String fileNameIn, String hashNameIn, boolean hasPatternItem) {
|
||||
+ throw new IllegalStateException("Enum not extended");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void init() {
|
||||
+ net.minecraftforge.common.ForgeHooks.refreshBannerPatternData();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.common;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
@@ -63,6 +64,7 @@ import net.minecraft.world.item.*;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BannerPattern;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.storage.WorldData;
|
||||
@@ -1482,7 +1484,33 @@ public class ForgeHooks
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
private static BannerPattern[] nonPatternItems;
|
||||
private static int totalPatternRows;
|
||||
|
||||
public static void refreshBannerPatternData()
|
||||
{
|
||||
nonPatternItems = Arrays.stream(BannerPattern.values())
|
||||
.filter(p -> !p.hasPatternItem)
|
||||
.toArray(BannerPattern[]::new);
|
||||
totalPatternRows = (nonPatternItems.length + 2) / 4;
|
||||
}
|
||||
|
||||
public static int getTotalPatternRows()
|
||||
{
|
||||
return totalPatternRows;
|
||||
}
|
||||
|
||||
public static int getNonPatternItemCount()
|
||||
{
|
||||
return nonPatternItems.length;
|
||||
}
|
||||
|
||||
public static int getActualPatternIndex(int index)
|
||||
{
|
||||
return nonPatternItems[index].ordinal();
|
||||
}
|
||||
|
||||
public static boolean shouldSuppressEnderManAnger(EnderMan enderMan, Player player, ItemStack mask)
|
||||
{
|
||||
return mask.isEnderMask(player, enderMan) || MinecraftForge.EVENT_BUS.post(new EnderManAngerEvent(enderMan, player));
|
||||
|
||||
@@ -455,6 +455,7 @@ public net.minecraft.world.level.block.WoolCarpetBlock <init>(Lnet/minecraft/wor
|
||||
public net.minecraft.world.level.block.Block m_49805_(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;I)V # popExperience
|
||||
public net.minecraft.world.level.block.FireBlock m_53492_(Lnet/minecraft/world/level/block/state/BlockState;)I # getBurnOdd
|
||||
public net.minecraft.world.level.block.FireBlock m_53494_(Lnet/minecraft/world/level/block/state/BlockState;)I # getFlameOdds
|
||||
public net.minecraft.world.level.block.entity.BannerPattern f_58530_ # hasPatternItem
|
||||
public net.minecraft.world.level.block.entity.BlockEntityType$BlockEntitySupplier
|
||||
public net.minecraft.world.level.block.entity.HopperBlockEntity m_59395_(I)V # setCooldown
|
||||
public net.minecraft.world.level.block.entity.HopperBlockEntity m_59409_()Z # isOnCustomCooldown
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Minecraft Forge - Forge Development LLC
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.block;
|
||||
|
||||
import net.minecraft.world.item.BannerPatternItem;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.entity.BannerPattern;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
@Mod("banner_pattern_test")
|
||||
public class BannerPatternTest
|
||||
{
|
||||
|
||||
private static final boolean ENABLED = true;
|
||||
|
||||
public BannerPatternTest()
|
||||
{
|
||||
if (!ENABLED) return;
|
||||
|
||||
BannerPattern.create("BANNER_PATTERN_TEST_TEST1", "banner_pattern_test:test1", "bpt:t1");
|
||||
var pattern = BannerPattern.create("BANNER_PATTERN_TEST_TEST2", "banner_pattern_test:test2", "bpt:t2", true);
|
||||
BannerPattern.create("BANNER_PATTERN_TEST_TEST3", "banner_pattern_test:test3", "bpt:t3");
|
||||
|
||||
var register = DeferredRegister.create(ForgeRegistries.ITEMS, "banner_pattern_test");
|
||||
register.register("pattern_item_test", () -> new BannerPatternItem(pattern, new Item.Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
|
||||
register.register(FMLJavaModLoadingContext.get().getModEventBus());
|
||||
}
|
||||
}
|
||||
@@ -226,5 +226,7 @@ license="LGPL v2.1"
|
||||
modId="custom_rarity_test"
|
||||
[[mods]]
|
||||
modId="data_pack_registries_test"
|
||||
[[mods]]
|
||||
modId="banner_pattern_test"
|
||||
|
||||
# ADD ABOVE THIS LINE
|
||||
Reference in new issue
Block a user