mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
better usable item detection
This commit is contained in:
parent
7ae28e9ba5
commit
ce8cd89320
1 changed files with 11 additions and 1 deletions
|
@ -13,6 +13,7 @@ import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.decoration.DisplayEntity;
|
import net.minecraft.entity.decoration.DisplayEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.consume.UseAction;
|
import net.minecraft.item.consume.UseAction;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
|
@ -123,7 +124,7 @@ public class Utl {
|
||||||
// try the default conditions
|
// try the default conditions
|
||||||
if (filter.isBlock() && itemStack.getItem() instanceof BlockItem) return true;
|
if (filter.isBlock() && itemStack.getItem() instanceof BlockItem) return true;
|
||||||
if (filter.isFood() && food.contains(itemStack.getUseAction())) return true;
|
if (filter.isFood() && food.contains(itemStack.getUseAction())) return true;
|
||||||
if (filter.isUsable() && !notUsable.contains(itemStack.getUseAction())) return true;
|
if (filter.isUsable() && hasItemUse(itemStack)) return true;
|
||||||
|
|
||||||
// if nothing else is met, the item is filtered out
|
// if nothing else is met, the item is filtered out
|
||||||
return false;
|
return false;
|
||||||
|
@ -191,6 +192,15 @@ public class Utl {
|
||||||
return isMethodOverridden(AbstractBlock.class, blockState.getBlock().getClass(), "onUse", BlockState.class, World.class, BlockPos.class, PlayerEntity.class, BlockHitResult.class);
|
return isMethodOverridden(AbstractBlock.class, blockState.getBlock().getClass(), "onUse", BlockState.class, World.class, BlockPos.class, PlayerEntity.class, BlockHitResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if an item has a use
|
||||||
|
* @param itemStack the itemstack to check
|
||||||
|
* @return if the item has a use or not
|
||||||
|
*/
|
||||||
|
public static boolean hasItemUse(ItemStack itemStack) {
|
||||||
|
return isMethodOverridden(Item.class, itemStack.getItem().getClass(), "use", World.class, PlayerEntity.class, Hand.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks if a method in the base class has been overridden in the subclass(es) by:
|
* checks if a method in the base class has been overridden in the subclass(es) by:
|
||||||
* checking the subclass and its supers till the original method is found or the original method is found
|
* checking the subclass and its supers till the original method is found or the original method is found
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue