prevent double processing when clicking on a block with item function
This commit is contained in:
parent
7153224934
commit
85e9ff23fd
@ -15,7 +15,6 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseItemCallback;
|
||||
|
||||
|
||||
public class Flan implements ModInitializer {
|
||||
|
||||
@Override
|
||||
|
@ -20,6 +20,7 @@ import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -92,10 +93,10 @@ public class BlockInteractEvents {
|
||||
DoubleBlockHalf half = state.get(DoorBlock.HALF);
|
||||
if (half == DoubleBlockHalf.LOWER) {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().up());
|
||||
player.world.updateListeners(hitResult.getBlockPos().up(), other, other, 2);
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().up(), other));
|
||||
} else {
|
||||
BlockState other = world.getBlockState(hitResult.getBlockPos().down());
|
||||
player.world.updateListeners(hitResult.getBlockPos().down(), other, other, 2);
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().down(), other));
|
||||
}
|
||||
}
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
|
@ -18,6 +18,7 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
@ -81,21 +82,28 @@ public class ItemInteractEvents {
|
||||
return ActionResult.PASS;
|
||||
boolean actualInClaim = placePos.getY()>=claim.getDimensions()[4];
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
|
||||
if (actualInClaim && context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, true))
|
||||
if (context.getStack().getItem() == Items.END_CRYSTAL) {
|
||||
if (claim.canInteract(player, EnumPermission.ENDCRYSTALPLACE, placePos, false))
|
||||
return ActionResult.PASS;
|
||||
return ActionResult.FAIL;
|
||||
else if(actualInClaim) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
if (claim.canInteract(player, EnumPermission.PLACE, placePos, true)) {
|
||||
if (claim.canInteract(player, EnumPermission.PLACE, placePos, false)) {
|
||||
if(!actualInClaim && context.getStack().getItem() instanceof BlockItem){
|
||||
claim.extendDownwards(placePos);
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
BlockState other = context.getWorld().getBlockState(placePos.up());
|
||||
player.world.updateListeners(placePos.up(), other, other, 2);
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
else if(actualInClaim) {
|
||||
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
|
||||
BlockState other = context.getWorld().getBlockState(placePos.up());
|
||||
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(placePos.up(), other));
|
||||
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
||||
return ActionResult.FAIL;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
private static boolean cantClaimInWorld(ServerWorld world) {
|
||||
@ -118,8 +126,11 @@ public class ItemInteractEvents {
|
||||
return;
|
||||
}
|
||||
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
||||
Claim claim = storage.getClaimAt(target);
|
||||
Claim claim = storage.getClaimAt(target.add(0,255,0));
|
||||
PlayerClaimData data = PlayerClaimData.get(player);
|
||||
if(data.claimCooldown())
|
||||
return;
|
||||
data.setClaimActionCooldown();
|
||||
if (claim != null) {
|
||||
if (claim.canInteract(player, EnumPermission.EDITCLAIM, target)) {
|
||||
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
||||
|
Loading…
Reference in New Issue
Block a user