rewrite some interaction handling and to use some event calls instead of mixin. should cover ae2 wrenches now close #106
This commit is contained in:
parent
be4099fa54
commit
5dc0584a7a
@ -5,8 +5,9 @@ Flan 1.6.5
|
|||||||
- New config "customItemPermission" and "customBlockPermission"
|
- New config "customItemPermission" and "customBlockPermission"
|
||||||
allows to specify a mapping of item/block to permission
|
allows to specify a mapping of item/block to permission
|
||||||
example is endcrystals are mapped to the ENDCRYSTALPLACE permission internally
|
example is endcrystals are mapped to the ENDCRYSTALPLACE permission internally
|
||||||
Syntax is <item/block>-<permission>
|
Syntax is <item/block>-\<permission>
|
||||||
Use @ to indicate a tag
|
Use @ to indicate a tag
|
||||||
|
- Moved some interaction checks to a different location so more mods should be covered by default
|
||||||
|
|
||||||
Flan 1.6.4
|
Flan 1.6.4
|
||||||
======================
|
======================
|
||||||
|
@ -70,7 +70,9 @@ public class Config {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public List<String> itemPermission = Lists.newArrayList(
|
public List<String> itemPermission = Lists.newArrayList(
|
||||||
"@c:wrenches-INTERACTBLOCK"
|
"@c:wrenches-INTERACTBLOCK",
|
||||||
|
"appliedenergistics2:nether_quartz_wrench-INTERACTBLOCK",
|
||||||
|
"appliedenergistics2:certus_quartz_wrench-INTERACTBLOCK"
|
||||||
);
|
);
|
||||||
public List<String> blockPermission = Lists.newArrayList(
|
public List<String> blockPermission = Lists.newArrayList(
|
||||||
);
|
);
|
||||||
|
@ -24,6 +24,7 @@ import net.minecraft.world.entity.item.ItemEntity;
|
|||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.entity.projectile.Projectile;
|
import net.minecraft.world.entity.projectile.Projectile;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.DoorBlock;
|
import net.minecraft.world.level.block.DoorBlock;
|
||||||
import net.minecraft.world.level.block.LecternBlock;
|
import net.minecraft.world.level.block.LecternBlock;
|
||||||
@ -101,7 +102,7 @@ public class BlockInteractEvents {
|
|||||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||||
return InteractionResult.FAIL;
|
return InteractionResult.FAIL;
|
||||||
}
|
}
|
||||||
if (blockEntity != null) {
|
if (blockEntity != null && !player.isSecondaryUseActive() && !stack.isEmpty()) {
|
||||||
if (blockEntity instanceof LecternBlockEntity) {
|
if (blockEntity instanceof LecternBlockEntity) {
|
||||||
if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
|
if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
@ -116,7 +117,13 @@ public class BlockInteractEvents {
|
|||||||
return InteractionResult.FAIL;
|
return InteractionResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return claim.canInteract(player, PermissionRegistry.INTERACTBLOCK, hitResult.getBlockPos(), false) ? InteractionResult.PASS : InteractionResult.FAIL;
|
InteractionResult res = ItemInteractEvents.onItemUseBlock(new UseOnContext(player, hand, hitResult));
|
||||||
|
if (claim.canInteract(player, PermissionRegistry.INTERACTBLOCK, hitResult.getBlockPos(), false) || res == InteractionResult.FAIL) {
|
||||||
|
if (res == InteractionResult.FAIL)
|
||||||
|
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.blockPosition().getY());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,15 @@ package io.github.flemmli97.flan.mixin;
|
|||||||
|
|
||||||
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
import io.github.flemmli97.flan.event.BlockInteractEvents;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.InteractionHand;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.phys.BlockHitResult;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(BlockBehaviour.BlockStateBase.class)
|
@Mixin(BlockBehaviour.BlockStateBase.class)
|
||||||
public abstract class AbstractBlockStateMixin {
|
public abstract class AbstractBlockStateMixin {
|
||||||
@ -27,19 +22,6 @@ public abstract class AbstractBlockStateMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Can't use the hooks from both fabric or forge cause they are too generic.
|
|
||||||
* Wouldn't be able to place blocks after cancelling them
|
|
||||||
*/
|
|
||||||
@Inject(method = "use", at = @At(value = "HEAD"), cancellable = true)
|
|
||||||
private void useBlock(Level world, Player player, InteractionHand hand, BlockHitResult result, CallbackInfoReturnable<InteractionResult> info) {
|
|
||||||
InteractionResult res = BlockInteractEvents.useBlocks(player, world, hand, result);
|
|
||||||
if (res != InteractionResult.PASS) {
|
|
||||||
info.setReturnValue(res);
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
protected abstract BlockState asState();
|
protected abstract BlockState asState();
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package io.github.flemmli97.flan.mixin;
|
|
||||||
|
|
||||||
import io.github.flemmli97.flan.event.ItemInteractEvents;
|
|
||||||
import net.minecraft.world.InteractionResult;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(ItemStack.class)
|
|
||||||
public abstract class ItemStackMixin {
|
|
||||||
|
|
||||||
@Inject(method = "useOn", at = @At(value = "HEAD"), cancellable = true)
|
|
||||||
private void blockUse(UseOnContext context, CallbackInfoReturnable<InteractionResult> info) {
|
|
||||||
InteractionResult result = ItemInteractEvents.onItemUseBlock(context);
|
|
||||||
if (result != InteractionResult.PASS) {
|
|
||||||
info.setReturnValue(result);
|
|
||||||
info.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -10,7 +10,6 @@
|
|||||||
"EntityMixin",
|
"EntityMixin",
|
||||||
"TurtleEggMixin",
|
"TurtleEggMixin",
|
||||||
"IPersistentProjectileVars",
|
"IPersistentProjectileVars",
|
||||||
"ItemStackMixin",
|
|
||||||
"ILecternBlockValues",
|
"ILecternBlockValues",
|
||||||
"FluidMixin",
|
"FluidMixin",
|
||||||
"RaidManagerMixin",
|
"RaidManagerMixin",
|
||||||
|
@ -13,23 +13,30 @@ import io.github.flemmli97.flan.player.PlayerDataHandler;
|
|||||||
import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
|
import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
|
||||||
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.Event;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
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.UseEntityCallback;
|
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
||||||
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
|
||||||
public class FlanFabric implements ModInitializer {
|
public class FlanFabric implements ModInitializer {
|
||||||
|
|
||||||
|
public static final ResourceLocation EventPhase = new ResourceLocation("flan", "events");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
PlayerBlockBreakEvents.BEFORE.register(BlockInteractEvents::breakBlocks);
|
||||||
AttackBlockCallback.EVENT.register(BlockInteractEvents::startBreakBlocks);
|
AttackBlockCallback.EVENT.register(BlockInteractEvents::startBreakBlocks);
|
||||||
|
UseBlockCallback.EVENT.addPhaseOrdering(EventPhase, Event.DEFAULT_PHASE);
|
||||||
|
UseBlockCallback.EVENT.register(EventPhase, BlockInteractEvents::useBlocks);
|
||||||
UseEntityCallback.EVENT.register(EntityInteractEvents::useAtEntity);
|
UseEntityCallback.EVENT.register(EntityInteractEvents::useAtEntity);
|
||||||
AttackEntityCallback.EVENT.register(EntityInteractEvents::attackEntity);
|
AttackEntityCallback.EVENT.register(EntityInteractEvents::attackEntity);
|
||||||
UseItemCallback.EVENT.register(ItemInteractEvents::useItem);
|
UseItemCallback.EVENT.register(ItemInteractEvents::useItem);
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.7.4",
|
"fabricloader": ">=0.7.4",
|
||||||
"fabric": ">=0.19.0"
|
"fabric": ">=0.42.0"
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
"flamingo": "*"
|
"flamingo": "*"
|
||||||
|
@ -8,6 +8,7 @@ import io.github.flemmli97.flan.forgeevent.ServerEvents;
|
|||||||
import io.github.flemmli97.flan.forgeevent.WorldEventsForge;
|
import io.github.flemmli97.flan.forgeevent.WorldEventsForge;
|
||||||
import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
|
import io.github.flemmli97.flan.scoreboard.ClaimCriterias;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
@ -29,6 +30,7 @@ public class FlanForge {
|
|||||||
forge.addListener(ItemInteractEventsForge::useItem);
|
forge.addListener(ItemInteractEventsForge::useItem);
|
||||||
forge.addListener(BlockInteractEventsForge::startBreakBlocks);
|
forge.addListener(BlockInteractEventsForge::startBreakBlocks);
|
||||||
forge.addListener(BlockInteractEventsForge::breakBlocks);
|
forge.addListener(BlockInteractEventsForge::breakBlocks);
|
||||||
|
forge.addListener(EventPriority.HIGHEST, BlockInteractEventsForge::useBlocks);
|
||||||
forge.addListener(EntityInteractEventsForge::attackEntity);
|
forge.addListener(EntityInteractEventsForge::attackEntity);
|
||||||
forge.addListener(EntityInteractEventsForge::useAtEntity);
|
forge.addListener(EntityInteractEventsForge::useAtEntity);
|
||||||
forge.addListener(EntityInteractEventsForge::useEntity);
|
forge.addListener(EntityInteractEventsForge::useEntity);
|
||||||
|
@ -22,4 +22,12 @@ public class BlockInteractEventsForge {
|
|||||||
if (!BlockInteractEvents.breakBlocks((Level) event.getWorld(), event.getPlayer(), event.getPos(), event.getState(), event.getWorld().getBlockEntity(event.getPos())))
|
if (!BlockInteractEvents.breakBlocks((Level) event.getWorld(), event.getPlayer(), event.getPos(), event.getState(), event.getWorld().getBlockEntity(event.getPos())))
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void useBlocks(PlayerInteractEvent.RightClickBlock event) {
|
||||||
|
InteractionResult res = BlockInteractEvents.useBlocks(event.getPlayer(), event.getWorld(), event.getHand(), event.getHitVec());
|
||||||
|
if (res != InteractionResult.PASS) {
|
||||||
|
event.setCancellationResult(res);
|
||||||
|
event.setCanceled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user