Skip to content

Commit

Permalink
Merge branch '1.21.x' into relax_enum_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Sep 24, 2024
2 parents cf5d291 + 8ec872a commit f6ca17a
Show file tree
Hide file tree
Showing 30 changed files with 1,190 additions and 25 deletions.
23 changes: 23 additions & 0 deletions patches/net/minecraft/resources/RegistryDataLoader.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@

for (Entry<ResourceLocation, Resource> entry : filetoidconverter.listMatchingResources(p_321535_).entrySet()) {
ResourceLocation resourcelocation = entry.getKey();
@@ -304,13 +_,20 @@
void apply(RegistryDataLoader.Loader<?> p_321864_, RegistryOps.RegistryInfoLookup p_321656_);
}

- public static record RegistryData<T>(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty) {
+ public static record RegistryData<T>(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty, java.util.function.Consumer<net.neoforged.neoforge.registries.RegistryBuilder<T>> registryBuilderConsumer) {
+ public RegistryData(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, boolean requiredNonEmpty) {
+ this(key, elementCodec, requiredNonEmpty, registryBuilder -> {});
+ }
+
RegistryData(ResourceKey<? extends Registry<T>> p_251360_, Codec<T> p_248976_) {
this(p_251360_, p_248976_, false);
}

RegistryDataLoader.Loader<T> create(Lifecycle p_251662_, Map<ResourceKey<?>, Exception> p_251565_) {
- WritableRegistry<T> writableregistry = new MappedRegistry<>(this.key, p_251662_);
+ net.neoforged.neoforge.registries.RegistryBuilder<T> registryBuilder = new net.neoforged.neoforge.registries.RegistryBuilder<>(key);
+ registryBuilderConsumer.accept(registryBuilder);
+
+ WritableRegistry<T> writableregistry = (WritableRegistry<T>) registryBuilder.disableRegistrationCheck().create();
return new RegistryDataLoader.Loader<>(this, writableregistry, p_251565_);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--- a/net/minecraft/world/entity/ai/attributes/Attribute.java
+++ b/net/minecraft/world/entity/ai/attributes/Attribute.java
@@ -9,7 +_,7 @@
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

-public class Attribute {
+public class Attribute implements net.neoforged.neoforge.common.extensions.IAttributeExtension {
public static final Codec<Holder<Attribute>> CODEC = BuiltInRegistries.ATTRIBUTE.holderByNameCodec();
public static final StreamCodec<RegistryFriendlyByteBuf, Holder<Attribute>> STREAM_CODEC = ByteBufCodecs.holderRegistry(Registries.ATTRIBUTE);
private final double defaultValue;
@@ -50,6 +_,21 @@

public ChatFormatting getStyle(boolean p_347715_) {
return this.sentiment.getStyle(p_347715_);
+ }
+
+ // Neo: Patch in the default implementation of IAttributeExtension#getMergedStyle since we need access to Attribute#sentiment
+
+ protected static final net.minecraft.network.chat.TextColor MERGED_RED = net.minecraft.network.chat.TextColor.fromRgb(0xF93131);
+ protected static final net.minecraft.network.chat.TextColor MERGED_BLUE = net.minecraft.network.chat.TextColor.fromRgb(0x7A7AF9);
+ protected static final net.minecraft.network.chat.TextColor MERGED_GRAY = net.minecraft.network.chat.TextColor.fromRgb(0xCCCCCC);
+
+ @Override
+ public net.minecraft.network.chat.TextColor getMergedStyle(boolean isPositive) {
+ return switch (this.sentiment) {
+ case POSITIVE -> isPositive ? MERGED_BLUE : MERGED_RED;
+ case NEGATIVE -> isPositive ? MERGED_RED : MERGED_BLUE;
+ case NEUTRAL -> MERGED_GRAY;
+ };
}

public static enum Sentiment {
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/net/minecraft/world/entity/ai/attributes/Attributes.java
+++ b/net/minecraft/world/entity/ai/attributes/Attributes.java
@@ -54,7 +_,8 @@
"generic.jump_strength", new RangedAttribute("attribute.name.generic.jump_strength", 0.42F, 0.0, 32.0).setSyncable(true)
);
public static final Holder<Attribute> KNOCKBACK_RESISTANCE = register(
- "generic.knockback_resistance", new RangedAttribute("attribute.name.generic.knockback_resistance", 0.0, 0.0, 1.0)
+ // Neo: Convert Knockback Resistance to percent-based for more appropriate display using IAttributeExtension.
+ "generic.knockback_resistance", new net.neoforged.neoforge.common.PercentageAttribute("attribute.name.generic.knockback_resistance", 0.0, 0.0, 1.0)
);
public static final Holder<Attribute> LUCK = register(
"generic.luck", new RangedAttribute("attribute.name.generic.luck", 0.0, -1024.0, 1024.0).setSyncable(true)
@@ -72,7 +_,8 @@
"generic.movement_efficiency", new RangedAttribute("attribute.name.generic.movement_efficiency", 0.0, 0.0, 1.0).setSyncable(true)
);
public static final Holder<Attribute> MOVEMENT_SPEED = register(
- "generic.movement_speed", new RangedAttribute("attribute.name.generic.movement_speed", 0.7, 0.0, 1024.0).setSyncable(true)
+ // Neo: Convert Movement Speed to percent-based for more appropriate display using IAttributeExtension. Use a scale factor of 1000 since movement speed has 0.001 units.
+ "generic.movement_speed", new net.neoforged.neoforge.common.PercentageAttribute("attribute.name.generic.movement_speed", 0.7, 0.0, 1024.0, 1000).setSyncable(true)
);
public static final Holder<Attribute> OXYGEN_BONUS = register(
"generic.oxygen_bonus", new RangedAttribute("attribute.name.generic.oxygen_bonus", 0.0, 0.0, 1024.0).setSyncable(true)
17 changes: 13 additions & 4 deletions patches/net/minecraft/world/entity/player/Player.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@
if (p_36347_.getType().is(EntityTypeTags.REDIRECTABLE_PROJECTILE)
&& p_36347_ instanceof Projectile projectile
&& projectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) {
@@ -1170,8 +_,12 @@
@@ -1170,19 +_,28 @@
&& !this.isPassenger()
&& p_36347_ instanceof LivingEntity
&& !this.isSprinting();
+ // Neo: Fire the critical hit event and override the critical hit status and damage multiplier based on the event.
+ // The boolean local above (flag2) is the vanilla critical hit result.
+ // The boolean local above (flag1) is the vanilla critical hit result.
+ var critEvent = net.neoforged.neoforge.common.CommonHooks.fireCriticalHit(this, p_36347_, flag1, flag1 ? 1.5F : 1.0F);
+ flag1 = critEvent.isCriticalHit();
if (flag1) {
Expand All @@ -268,17 +268,26 @@
}

float f3 = f + f1;
@@ -1179,9 +_,7 @@
boolean flag2 = false;
double d0 = (double)(this.walkDist - this.walkDistO);
if (flag4 && !flag1 && !flag && this.onGround() && d0 < (double)this.getSpeed()) {
- if (flag4 && !flag1 && !flag && this.onGround() && d0 < (double)this.getSpeed()) {
+ // Neo: Replace !flag1 (!isCriticalHit) with the logic from the CriticalHitEvent.
+ boolean critBlocksSweep = critEvent.isCriticalHit() && critEvent.disableSweep();
+ if (flag4 && !critBlocksSweep && !flag && this.onGround() && d0 < (double)this.getSpeed()) {
+ // Neo: Make sweep attacks check SWORD_SWEEP instead of instanceof SwordItem.
ItemStack itemstack1 = this.getItemInHand(InteractionHand.MAIN_HAND);
- if (itemstack1.getItem() instanceof SwordItem) {
- flag2 = true;
- }
+ flag2 = itemstack1.canPerformAction(net.neoforged.neoforge.common.ItemAbilities.SWORD_SWEEP);
}
+
+ // Neo: Fire the SweepAttackEvent and overwrite the value of flag2 (the local controlling if a sweep will occur).
+ var sweepEvent = net.neoforged.neoforge.common.CommonHooks.fireSweepAttack(this, p_36347_, flag2);
+ flag2 = sweepEvent.isSweeping();

float f6 = 0.0F;
if (p_36347_ instanceof LivingEntity livingentity) {
@@ -1217,11 +_,12 @@

for (LivingEntity livingentity2 : this.level()
Expand Down
20 changes: 16 additions & 4 deletions patches/net/minecraft/world/item/ItemStack.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@
if (this.has(DataComponents.CUSTOM_NAME)) {
mutablecomponent.withStyle(ChatFormatting.ITALIC);
}
@@ -784,12 +_,14 @@
@@ -752,7 +_,9 @@
this.addToTooltip(DataComponents.ENCHANTMENTS, p_339637_, consumer, p_41653_);
this.addToTooltip(DataComponents.DYED_COLOR, p_339637_, consumer, p_41653_);
this.addToTooltip(DataComponents.LORE, p_339637_, consumer, p_41653_);
- this.addAttributeTooltips(consumer, p_41652_);
+ // Neo: Replace attribute tooltips with custom handling
+ net.neoforged.neoforge.common.util.AttributeUtil.addAttributeTooltips(this, consumer,
+ net.neoforged.neoforge.common.util.AttributeTooltipContext.of(p_41652_, p_339637_, p_41653_));
this.addToTooltip(DataComponents.UNBREAKABLE, p_339637_, consumer, p_41653_);
AdventureModePredicate adventuremodepredicate = this.get(DataComponents.CAN_BREAK);
if (adventuremodepredicate != null && adventuremodepredicate.showInTooltip()) {
@@ -784,10 +_,15 @@
list.add(DISABLED_ITEM_TOOLTIP);
}

Expand All @@ -157,12 +168,13 @@
}
}

+ /**
+ * @deprecated Neo: Use {@link net.neoforged.neoforge.client.util.TooltipUtil#addAttributeTooltips}
+ */
+ @Deprecated
private void addAttributeTooltips(Consumer<Component> p_330796_, @Nullable Player p_330530_) {
ItemAttributeModifiers itemattributemodifiers = this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
+ // Neo: We don't need to call IItemStackExtension#getAttributeModifiers here, since it will be done in forEachModifier.
if (itemattributemodifiers.showInTooltip()) {
for (EquipmentSlotGroup equipmentslotgroup : EquipmentSlotGroup.values()) {
MutableBoolean mutableboolean = new MutableBoolean(true);
@@ -897,6 +_,17 @@
return !this.getOrDefault(DataComponents.ENCHANTMENTS, ItemEnchantments.EMPTY).isEmpty();
}
Expand Down
13 changes: 13 additions & 0 deletions patches/net/minecraft/world/item/alchemy/PotionContents.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- a/net/minecraft/world/item/alchemy/PotionContents.java
+++ b/net/minecraft/world/item/alchemy/PotionContents.java
@@ -173,6 +_,10 @@
p_331296_.accept(CommonComponents.EMPTY);
p_331296_.accept(Component.translatable("potion.whenDrank").withStyle(ChatFormatting.DARK_PURPLE));

+ // Neo: Override handling of potion attribute tooltips to support IAttributeExtension
+ net.neoforged.neoforge.common.util.AttributeUtil.addPotionTooltip(list, p_331296_);
+ if (true) return;
+
for (Pair<Holder<Attribute>, AttributeModifier> pair : list) {
AttributeModifier attributemodifier = pair.getSecond();
double d1 = attributemodifier.amount();
4 changes: 4 additions & 0 deletions src/generated/resources/assets/c/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"tag.block.c.hidden_from_recipe_viewers": "Hidden From Recipe Viewers",
"tag.block.c.netherracks": "Netherracks",
"tag.block.c.obsidians": "Obsidians",
"tag.block.c.obsidians.crying": "Crying Obsidians",
"tag.block.c.obsidians.normal": "Normal Obsidians",
"tag.block.c.ore_bearing_ground.deepslate": "Deepslate Ore Bearing Ground",
"tag.block.c.ore_bearing_ground.netherrack": "Netherrack Ore Bearing Ground",
"tag.block.c.ore_bearing_ground.stone": "Stone Ore Bearing Ground",
Expand Down Expand Up @@ -272,6 +274,8 @@
"tag.item.c.nuggets.gold": "Gold Nuggets",
"tag.item.c.nuggets.iron": "Iron Nuggets",
"tag.item.c.obsidians": "Obsidians",
"tag.item.c.obsidians.crying": "Crying Obsidians",
"tag.item.c.obsidians.normal": "Normal Obsidians",
"tag.item.c.ore_bearing_ground.deepslate": "Deepslate Ore Bearing Ground",
"tag.item.c.ore_bearing_ground.netherrack": "Netherrack Ore Bearing Ground",
"tag.item.c.ore_bearing_ground.stone": "Stone Ore Bearing Ground",
Expand Down
4 changes: 2 additions & 2 deletions src/generated/resources/data/c/tags/block/obsidians.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"values": [
"minecraft:obsidian",
"minecraft:crying_obsidian",
"#c:obsidians/normal",
"#c:obsidians/crying",
{
"id": "#forge:obsidian",
"required": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:crying_obsidian"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:obsidian"
]
}
4 changes: 2 additions & 2 deletions src/generated/resources/data/c/tags/item/obsidians.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"values": [
"minecraft:obsidian",
"minecraft:crying_obsidian",
"#c:obsidians/normal",
"#c:obsidians/crying",
{
"id": "#forge:obsidian",
"required": false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:crying_obsidian"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"minecraft:obsidian"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.client.event;

import java.util.function.Consumer;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.neoforged.bus.api.Event;
import net.neoforged.neoforge.common.util.AttributeTooltipContext;
import net.neoforged.neoforge.common.util.AttributeUtil;

/**
* This event is fired after attribute tooltip lines have been added to an item stack's tooltip in {@link AttributeUtil#addAttributeTooltips}.
* <p>
* It can be used to add additional tooltip lines adjacent to the attribute lines without having to manually locate the inject point.
* <p>
* This event may be fired on both the logical client and logical server.
*/
public class AddAttributeTooltipsEvent extends Event {
protected final ItemStack stack;
protected final Consumer<Component> tooltip;
protected final AttributeTooltipContext ctx;

public AddAttributeTooltipsEvent(ItemStack stack, Consumer<Component> tooltip, AttributeTooltipContext ctx) {
this.stack = stack;
this.tooltip = tooltip;
this.ctx = ctx;
}

/**
* The current tooltip context.
*/
public AttributeTooltipContext getContext() {
return this.ctx;
}

/**
* The {@link ItemStack} with the tooltip.
*/
public ItemStack getStack() {
return this.stack;
}

/**
* Adds one or more {@link Component}s to the tooltip.
*/
public void addTooltipLines(Component... comps) {
for (Component comp : comps) {
this.tooltip.accept(comp);
}
}

/**
* Checks if the attribute tooltips should be shown on the current item stack.
* <p>
* This event is fired even if the component would prevent the normal tooltip lines from showing.
*/
public boolean shouldShow() {
return this.stack.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY).showInTooltip();
}
}
Loading

0 comments on commit f6ca17a

Please sign in to comment.