make some right click handling more accessible
This commit is contained in:
parent
a142eaf552
commit
f262668414
@ -0,0 +1,29 @@
|
||||
package io.github.flemmli97.flan.api.fabric;
|
||||
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
/**
|
||||
* Interface for deciding what right click action should be prevented
|
||||
* This is used when handling fabrics {@link UseBlockCallback#EVENT}
|
||||
*/
|
||||
public interface ItemUseBlockFlags {
|
||||
|
||||
void stopCanUseBlocks(boolean flag);
|
||||
|
||||
void stopCanUseItems(boolean flag);
|
||||
|
||||
/**
|
||||
* If false prevents interaction with a block
|
||||
*/
|
||||
boolean allowUseBlocks();
|
||||
|
||||
/**
|
||||
* If false prevents right clicking with an item on a block
|
||||
*/
|
||||
boolean allowUseItems();
|
||||
|
||||
static ItemUseBlockFlags fromPlayer(ServerPlayer player) {
|
||||
return (ItemUseBlockFlags) player.gameMode;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.github.flemmli97.flan.fabric;
|
||||
|
||||
import io.github.flemmli97.flan.Flan;
|
||||
import io.github.flemmli97.flan.api.fabric.ItemUseBlockFlags;
|
||||
import io.github.flemmli97.flan.commands.CommandClaim;
|
||||
import io.github.flemmli97.flan.config.ConfigHandler;
|
||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||
@ -93,6 +94,8 @@ public class FlanFabric implements ModInitializer {
|
||||
return res;
|
||||
flags.stopCanUseBlocks(res == InteractionResult.FAIL);
|
||||
flags.stopCanUseItems(ItemInteractEvents.onItemUseBlock(new UseOnContext(p, hand, hitResult)) == InteractionResult.FAIL);
|
||||
if (!flags.allowUseBlocks() && !flags.allowUseItems())
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package io.github.flemmli97.flan.fabric;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface ItemUseBlockFlags {
|
||||
|
||||
void stopCanUseBlocks(boolean flag);
|
||||
|
||||
void stopCanUseItems(boolean flag);
|
||||
|
||||
static ItemUseBlockFlags fromPlayer(ServerPlayer player) {
|
||||
return (ItemUseBlockFlags) player.gameMode;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package io.github.flemmli97.flan.fabric.mixin;
|
||||
|
||||
import io.github.flemmli97.flan.fabric.ItemUseBlockFlags;
|
||||
import io.github.flemmli97.flan.api.fabric.ItemUseBlockFlags;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
@ -47,4 +47,14 @@ public abstract class ServerPlayerGameModeMixin implements ItemUseBlockFlags {
|
||||
public void stopCanUseItems(boolean flag) {
|
||||
this.stopInteractItemBlock = flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowUseBlocks() {
|
||||
return !this.stopInteractBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowUseItems() {
|
||||
return !this.stopInteractItemBlock;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user