-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.21.x' into relax_enum_checks
- Loading branch information
Showing
30 changed files
with
1,190 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
patches/net/minecraft/world/entity/ai/attributes/Attribute.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
22 changes: 22 additions & 0 deletions
22
patches/net/minecraft/world/entity/ai/attributes/Attributes.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
patches/net/minecraft/world/item/alchemy/PotionContents.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/c/tags/block/obsidians/crying.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:crying_obsidian" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/c/tags/block/obsidians/normal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:obsidian" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/c/tags/item/obsidians/crying.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:crying_obsidian" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/generated/resources/data/c/tags/item/obsidians/normal.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"minecraft:obsidian" | ||
] | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/net/neoforged/neoforge/client/event/AddAttributeTooltipsEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.