left click blocks check
This commit is contained in:
parent
25107f2223
commit
5c95c9aed2
@ -31,11 +31,16 @@ import net.minecraft.util.Hand;
|
|||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class BlockInteractEvents {
|
public class BlockInteractEvents {
|
||||||
|
|
||||||
|
public static ActionResult startBreakBlocks(PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) {
|
||||||
|
return breakBlocks(world, player, pos, world.getBlockState(pos), world.getBlockEntity(pos)) ? ActionResult.PASS : ActionResult.FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean breakBlocks(World world, PlayerEntity p, BlockPos pos, BlockState state, BlockEntity tile) {
|
public static boolean breakBlocks(World world, PlayerEntity p, BlockPos pos, BlockState state, BlockEntity tile) {
|
||||||
if (world.isClient || p.isSpectator())
|
if (world.isClient || p.isSpectator())
|
||||||
return true;
|
return true;
|
||||||
|
@ -10,6 +10,7 @@ import io.github.flemmli97.flan.integration.playerability.PlayerAbilityEvents;
|
|||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
|
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||||
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
|
||||||
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
||||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||||
@ -22,6 +23,7 @@ public class FlanFabric implements ModInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
||||||
|
AttackBlockCallback.EVENT.register(BlockInteractEvents::startBreakBlocks);
|
||||||
UseBlockCallback.EVENT.register(BlockInteractEvents::useBlocks);
|
UseBlockCallback.EVENT.register(BlockInteractEvents::useBlocks);
|
||||||
UseEntityCallback.EVENT.register(EntityInteractEvents::useAtEntity);
|
UseEntityCallback.EVENT.register(EntityInteractEvents::useAtEntity);
|
||||||
AttackEntityCallback.EVENT.register(EntityInteractEvents::attackEntity);
|
AttackEntityCallback.EVENT.register(EntityInteractEvents::attackEntity);
|
||||||
|
@ -20,6 +20,7 @@ public class FlanForge {
|
|||||||
forge.addListener(WorldEventsForge::pistonCanPush);
|
forge.addListener(WorldEventsForge::pistonCanPush);
|
||||||
forge.addListener(WorldEventsForge::preventMobSpawn);
|
forge.addListener(WorldEventsForge::preventMobSpawn);
|
||||||
forge.addListener(ItemInteractEventsForge::useItem);
|
forge.addListener(ItemInteractEventsForge::useItem);
|
||||||
|
forge.addListener(BlockInteractEventsForge::startBreakBlocks);
|
||||||
forge.addListener(BlockInteractEventsForge::breakBlocks);
|
forge.addListener(BlockInteractEventsForge::breakBlocks);
|
||||||
forge.addListener(BlockInteractEventsForge::useBlocks);
|
forge.addListener(BlockInteractEventsForge::useBlocks);
|
||||||
forge.addListener(EntityInteractEventsForge::attackEntity);
|
forge.addListener(EntityInteractEventsForge::attackEntity);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.github.flemmli97.flan.forgeevent;
|
package io.github.flemmli97.flan.forgeevent;
|
||||||
|
|
||||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
@ -8,8 +9,15 @@ import net.minecraftforge.event.world.BlockEvent;
|
|||||||
|
|
||||||
public class BlockInteractEventsForge {
|
public class BlockInteractEventsForge {
|
||||||
|
|
||||||
|
public static void startBreakBlocks(PlayerInteractEvent.LeftClickBlock event) {
|
||||||
|
if (!(event.getWorld() instanceof ServerWorld))
|
||||||
|
return;
|
||||||
|
if (BlockInteractEvents.startBreakBlocks(event.getPlayer(), event.getWorld(), event.getHand(), event.getPos(), event.getFace()) == ActionResult.FAIL)
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
|
||||||
public static void breakBlocks(BlockEvent.BreakEvent event) {
|
public static void breakBlocks(BlockEvent.BreakEvent event) {
|
||||||
if (!(event.getWorld() instanceof World))
|
if (!(event.getWorld() instanceof ServerWorld))
|
||||||
return;
|
return;
|
||||||
if (!BlockInteractEvents.breakBlocks((World) event.getWorld(), event.getPlayer(), event.getPos(), event.getState(), event.getWorld().getBlockEntity(event.getPos())))
|
if (!BlockInteractEvents.breakBlocks((World) event.getWorld(), event.getPlayer(), event.getPos(), event.getState(), event.getWorld().getBlockEntity(event.getPos())))
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user