mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 18:50:51 +01:00
SPIGOT-7813: Material#isInteractable() always returns false
By: md_5 <git@md-5.net>
This commit is contained in:
parent
d7c74a442e
commit
d86a8b483e
1 changed files with 19 additions and 10 deletions
|
@ -1,6 +1,8 @@
|
||||||
package org.bukkit.craftbukkit.block;
|
package org.bukkit.craftbukkit.block;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import net.minecraft.core.BlockPosition;
|
import net.minecraft.core.BlockPosition;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
|
@ -54,28 +56,35 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
|
||||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasMethod(Class<?> clazz, String methodName, Class<?>... params) {
|
private static boolean hasMethod(Class<?> clazz, Class<?>... params) {
|
||||||
boolean hasMethod;
|
boolean hasMethod = false;
|
||||||
try {
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
hasMethod = clazz.getDeclaredMethod(methodName, params) != null;
|
if (Arrays.equals(method.getParameterTypes(), params)) {
|
||||||
} catch (NoSuchMethodException ex) {
|
Preconditions.checkArgument(!hasMethod, "More than one matching method for %s, args %s", clazz, Arrays.toString(params));
|
||||||
hasMethod = false;
|
|
||||||
|
hasMethod = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasMethod;
|
return hasMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Class<?>[] USE_WITHOUT_ITEM_ARGS = new Class[]{
|
||||||
|
IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class
|
||||||
|
};
|
||||||
|
private static final Class<?>[] USE_ITEM_ON_ARGS = new Class[]{
|
||||||
|
net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class
|
||||||
|
};
|
||||||
|
|
||||||
private static boolean isInteractable(Block block) {
|
private static boolean isInteractable(Block block) {
|
||||||
Class<?> clazz = block.getClass();
|
Class<?> clazz = block.getClass();
|
||||||
|
|
||||||
boolean hasMethod = hasMethod(clazz, "useWithoutItem", IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class)
|
boolean hasMethod = hasMethod(clazz, USE_WITHOUT_ITEM_ARGS) || hasMethod(clazz, USE_ITEM_ON_ARGS);
|
||||||
|| hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class);
|
|
||||||
|
|
||||||
if (!hasMethod && clazz.getSuperclass() != BlockBase.class) {
|
if (!hasMethod && clazz.getSuperclass() != BlockBase.class) {
|
||||||
clazz = clazz.getSuperclass();
|
clazz = clazz.getSuperclass();
|
||||||
|
|
||||||
hasMethod = hasMethod(clazz, "useWithoutItem", IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class)
|
hasMethod = hasMethod(clazz, USE_WITHOUT_ITEM_ARGS) || hasMethod(clazz, USE_ITEM_ON_ARGS);
|
||||||
|| hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasMethod;
|
return hasMethod;
|
||||||
|
|
Loading…
Reference in a new issue