-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
De-hardcode shears (again) #3477
base: 1.20.4
Are you sure you want to change the base?
Conversation
Aren't tags saved under |
Apply the license header with |
@ZestyBlaze Generally, |
this works from 23w32a onwards ( for below that, you would remove |
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
...-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/MatchToolLootConditionMixin.java
Outdated
Show resolved
Hide resolved
...tem-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/BlockInteractShearsMixin.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/DispenserBlockMixin.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/DispenserBlockMixin.java
Outdated
Show resolved
Hide resolved
...m-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/EfficiencyEnchantmentMixin.java
Outdated
Show resolved
Hide resolved
...em-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/EntityInteractShearsMixin.java
Outdated
Show resolved
Hide resolved
...-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/MatchToolLootConditionMixin.java
Outdated
Show resolved
Hide resolved
...-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/MatchToolLootConditionMixin.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/TripwireBlockMixin.java
Outdated
Show resolved
Hide resolved
…lizer also change the way all the shears are found also change the way the mixins work
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/testmod/java/net/fabricmc/fabric/test/item/ShearsTest.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
...-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/MatchToolLootConditionMixin.java
Outdated
Show resolved
Hide resolved
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/shears/DispenserBlockMixin.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about modifying all loot tables, we should probably only do it for vanilla.
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsHelper.java
Outdated
Show resolved
Hide resolved
If someone could help me find a way to do that that would be amazing. Though it would be even harder now that we're moving towards making it stack-based, which means I'm mixing into I also don't really see why anyone would want to target only vanilla shears but ¯\_(ツ)_/¯. |
The way Forge does it is to just replace the loot tables with their own. Maybe we can move the modification into a datagen instead. |
Then it wouldn't be stack-based, and that seems like what modmuss and some others want. |
You can make a custom predicate that checks if the item is shears with #3493 😉 |
That looks pretty good, but how would I make my PR depend on yours? |
use custom codec impl
…v1/CustomItemPredicateRegistry.java Co-authored-by: apple502j <[email protected]>
# Conflicts: # fabric-item-api-v1/src/main/java/net/fabricmc/fabric/api/item/v1/FabricItemStack.java # fabric-item-api-v1/src/main/resources/fabric-item-api-v1.mixins.json # fabric-item-api-v1/src/testmod/resources/fabric.mod.json
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ShearsItemPredicate.java
Outdated
Show resolved
Hide resolved
/** | ||
* Allows Fabric API to replace any occurrences of {@link net.minecraft.item.Items#SHEARS minecraft:shears} with a custom predicate for stack-aware shears. This is the default if {@link #DENY} is not specified. | ||
* | ||
* @see net.fabricmc.fabric.api.item.v1.FabricItem#isShears | ||
*/ | ||
ALLOW, | ||
/** | ||
* Disallows Fabric API to replace any occurrences of {@link net.minecraft.item.Items#SHEARS minecraft:shears} with a custom predicate for stack-aware shears. | ||
* | ||
* @see net.fabricmc.fabric.api.item.v1.FabricItem#isShears | ||
*/ | ||
DENY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this, what's with the allow and deny? Why can't it be a boolean that checks if it is shears or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also mixes into
MatchToolLootCondition
and adds a custom predicate to it if its predicate contains shears. The custom predicate is a boolean value registered underfabric:allow_shears
and defaults totrue
. If the value isfalse
, the mixin will not add the custom predicate even if the predicate contains shears.
true is ALLOW
and false is DENY
this is made so mods can also target only shears using DENY if they want to for some reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I had in mind is a boolean predicate, maybe called fabric:is_shears
and value && item.isShears()
check that entirely replaces the vanilla items
predicate. People who want to match strictly vanilla shears can do so like before without the deny
shenanigans.
if (predicate.items().isPresent() && predicate.items().get().contains(Items.SHEARS.getRegistryEntry())) { | ||
CustomItemPredicate[] custom = predicate.custom().toArray(new CustomItemPredicate[0]); | ||
ImmutableList.Builder<CustomItemPredicate> builder = ImmutableList.builderWithExpectedSize(custom.length + 1); | ||
|
||
for (CustomItemPredicate customPredicate : custom) { | ||
if (customPredicate == ShearsItemPredicate.DENY) return; | ||
builder.add(custom); | ||
} | ||
|
||
((ItemPredicateExtensions) (Object) predicate).fabric_setCustom(builder.add(ShearsItemPredicate.ALLOW).build()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make it replace all predicates with the ShearsItemPredicate.ALLOW
by default? If anything, it should be defaults to deny.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it does
i chose to make it default to ALLOW cuz im lazy and dont want to datagen
also i doubt anyone should want to make it only work for shears so its opt-out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you change the conditions at runtime with LootTableEvents.MODIFY
? CC: @Juuxel
Thanks for all your work! I think it would be great if the changes were included as I own 2 mods that add shears to Minecraft. They would benefit greatly from this. Are there any plans to bring this PR to 1.20.5? What is needed to reach that? :) |
it should already work on 1.20.5, but this pr is kinda in a dead place rn |
I think it needs a rework after #3493 was closed, because of the vanilla's sub predicate system. |
For porting this to 1.20.6 I think it would be easier to add a new boolean component "IS_SHEARS" or something similar and add it to vanilla shears and also to custom shears. This component could be checked in all your mixins instead of adding a new tag, a new Edit: and don't forget the newly added functionalities: shearable Bogged entity & Wolf armor shearing |
Adding new component would make fabric api incompatible with vanilla |
yes, that is why i havent ported this to 1.20.5+ yet |
Adds a boolean method to
FabricItem
andFabricItemStack
,isShears
. It functions as a stack-aware check that allows items to function as shears. By default, the method returns true if the item is either an instance ofShearsItem
or in thefabric:shears
tag.If a stack
isShears
, it is able to shear pumpkins, de-arm tripwire, be enchanted with efficiency, haveShearsDispenserBehavior
(if there isn't already aDispenserBehavior
for the item registered), and shear snow golems, sheep, and mooshrooms.This also mixes into
MatchToolLootCondition
and adds a custom predicate to it if its predicate contains shears. The custom predicate is a boolean value registered underfabric:allow_shears
and defaults totrue
. If the value isfalse
, the mixin will not add the custom predicate even if the predicate contains shears.Supersedes/closes #1287 and closes #1226. Also depends on/includes #3493, so either merge that first or just merge this PR.