Java 类net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock 实例源码

项目:GlobalXP    文件:EventHandler.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
    if(!(event.getWorld().getBlockState(event.getPos()).getBlock() instanceof XPBlock) || event.getHand() != EnumHand.MAIN_HAND)
        return;

    if(!event.getWorld().isRemote)
    {
        if(event.getEntityPlayer().isSneaking()) //sneaking = add all player XP to the block
        {
            ((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos())).addXP(event.getEntityPlayer().experienceTotal);
            event.getEntityPlayer().addExperienceLevel(-event.getEntityPlayer().experienceLevel - 1); // set player XP to 0
        }
        else //not sneaking = remove exactly enough XP from the block to get player to the next level
        {
            TileEntityXPBlock te = ((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos()));
            EntityPlayer player = event.getEntityPlayer();
            int neededXP = player.xpBarCap() - (int)player.experience;
            int availableXP = te.removeXP(neededXP);

            player.addExperience(availableXP);
        }
    }
}
项目:minecraft-territorialdealings    文件:EventListener.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
    if (event.getWorld().isRemote) { return; }
    if (Main.isPlayerInteractionAllowed()) { return; }  // Not my business

    Main.console("[TERRITORIAL DEALINGS] Block at x " + event.getPos().getX() + " / y " + event.getPos().getY() + " / z " + event.getPos().getZ() + " touched by player " + event.getEntityPlayer().getName() + ".");

    Chunk chunk = event.getEntityPlayer().worldObj.getChunkFromBlockCoords(event.getPos());

    if (TerritoryHandler.canPlayerEditChunk(event.getEntityPlayer(), chunk))    // Checks out
    {
        Main.console("[TERRITORIAL DEALINGS] Player is allowed to interact with this chunk. Doing nothing.");
    }
    else
    {
        Main.console("[TERRITORIAL DEALINGS] Player is not allowed to interact with this chunk. Cancelling.");
        event.setCanceled(true);    // Not having it
    }
}
项目:minecraft-territorialdealings    文件:EventListener.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
    if (event.getWorld().isRemote) { return; }      // Not doing this on client side
    if (!Main.shouldCheckInteraction()) { return; } // Not my business

    Main.console("Block at x" + event.getPos().getX() + " y" + event.getPos().getY() + " z" + event.getPos().getZ() + " touched by player " + event.getEntityPlayer().getName() + 
            " (ID " + event.getEntityPlayer().getGameProfile().getId() + ").");

    Chunk chunk = event.getEntityPlayer().worldObj.getChunkFromBlockCoords(event.getPos());

    if (TerritoryHandler.canPlayerEditChunk(event.getEntityPlayer().worldObj, event.getEntityPlayer(), chunk))  // Checks out
    {
        Main.console("Player is allowed to interact with this chunk. Doing nothing.");
    }
    else
    {
        Main.console("Player is not allowed to interact with this chunk. Cancelling.");
        event.setCanceled(true);    // Not having it
    }
}
项目:wizards-of-lua    文件:SwingArmEventTest.java   
@Test
public void test_rightclick() {
  // Given:
  mc().player().setPosition(playerPos);
  ItemStack item = mc().getItemStack(Blocks.SAND);
  mc().player().setMainHandItem(item);
  mc().setBlock(clickPos, Blocks.OBSIDIAN);
  EnumHand hand = EnumHand.MAIN_HAND;
  EnumFacing facing = EnumFacing.WEST;
  Vec3d hitvec = new Vec3d(clickPos);
  String expected = hand.name();

  mc().executeCommand("/lua q=Events.connect('SwingArmEvent'); e=q:pop(); print(e.hand)");

  // When:
  mc().player().rightclick(clickPos, facing, hitvec, hand);

  // Then:
  RightClickBlock act1 = mc().waitFor(RightClickBlock.class);
  assertThat(act1.getPos()).isEqualTo(clickPos);
  ServerLog4jEvent act = mc().waitFor(ServerLog4jEvent.class);
  assertThat(act.getMessage()).isEqualTo(expected);
}
项目:wizards-of-lua    文件:TestEnvironmentTest.java   
@Test
public void test_player_can_rightclick_on_blockpos() {
  // Given:
  mc().player().setPosition(playerPos);
  mc().player().setRotationYaw(0);
  ItemStack item = mc().getItemStack(Blocks.PLANKS);
  mc().player().setMainHandItem(item);
  mc().setBlock(clickPos, Blocks.OBSIDIAN);

  EnumHand hand = EnumHand.MAIN_HAND;
  EnumFacing facing = EnumFacing.WEST;
  Vec3d hitvec = new Vec3d(clickPos);

  // When:
  mc().player().rightclick(clickPos, facing, hitvec, hand);

  // Then:
  RightClickBlock act = mc().waitFor(RightClickBlock.class);
  assertThat(act.getPos()).isEqualTo(clickPos);
}
项目:CrystalMod    文件:ItemCrystalWrench.java   
@Override  
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (world.isRemote) {
      //If its client side we have to return pass so this method is called on server, where we need to perform the op 
      return EnumActionResult.PASS;
    }
    final IBlockState blockState = world.getBlockState(pos);
    IBlockState bs = blockState;
    Block block = bs.getBlock();
    boolean ret = false;
    if (block != null) {
        RightClickBlock e = new RightClickBlock(player, hand, pos,side, new Vec3d(hitX, hitY, hitZ));
        if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
            return EnumActionResult.PASS;
        }
        if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
            ret = true;
        } 
    }
    if (ret) {
        player.swingArm(hand);
    }
    return (ret && !world.isRemote) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
项目:Aether-Legacy    文件:AetherEventHandler.java   
@SubscribeEvent
public void checkBlockBannedEvent(RightClickBlock event)
{
    EntityPlayer player = event.getEntityPlayer();
    ItemStack currentStack = event.getItemStack();

    if (player.dimension == AetherConfig.getAetherDimensionID())
    {
        if (currentStack != null && (currentStack.getItem() == Items.FLINT_AND_STEEL || currentStack.getItem() == Item.getItemFromBlock(Blocks.TORCH) || currentStack.getItem() == Items.FIRE_CHARGE))
        {
            for (int i = 0; i < 10; ++i)
            {
                event.getWorld().spawnParticle(EnumParticleTypes.SMOKE_LARGE, event.getHitVec().xCoord, event.getHitVec().yCoord, event.getHitVec().zCoord, 0.0D, 0.0D, 0.0D, new int [] {});
            }

            event.setCanceled(true);

        }
        else if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.BED)
        {
            event.setCanceled(true);
        }
    }
}
项目:geomastery    文件:BlockEvents.java   
/** Makes portals if config. */
@SubscribeEvent
public void rightClick(RightClickBlock event) {

    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    ItemStack stack = event.getItemStack();
    Item item = stack.getItem();
    BlockPos pos = event.getPos();

    if (GeoConfig.compatibility.portals && item == GeoItems.FIREOPAL &&
            world instanceof WorldServer) {

        new Teleporter((WorldServer) world).makePortal(player);
        stack.shrink(1);
    }

    if (GeoConfig.compatibility.portals && item == GeoItems.AMETHYST) {

        Items.ENDER_EYE.onItemUse(player, world, pos,
                event.getHand(), event.getFace(), 0, 0, 0);
    }
}
项目:ForageCraft    文件:PotatoPlanter.java   
@SubscribeEvent
public void poisonousPotatoRightClick(RightClickBlock event)
{
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();

    if((event.getEntityPlayer().getHeldItemMainhand()!=null)
    &&(player.getHeldItemMainhand().getItem()==Items.POISONOUS_POTATO)
    &&(event.getFace()==EnumFacing.UP)
    &&world.getBlockState(event.getPos()).getBlock().canSustainPlant(world.getBlockState(event.getPos()), world, event.getPos(), EnumFacing.UP, (IPlantable) Items.POTATO))
    {
        if(!world.isRemote)
        {
            if(!player.capabilities.isCreativeMode)
                {
                    player.inventory.clearMatchingItems(Items.POISONOUS_POTATO, -1, 1, null);
                }
            if(world.getBlockState(event.getPos().up(+1)).getBlock()==Blocks.AIR)
            {
                world.setBlockState(event.getPos().up(+1),Blocks.POTATOES.getDefaultState());
            }
        }   
    }
}
项目:MineCamera    文件:EventLoader.java   
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void rightClickBlock(RightClickBlock event) {
    if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera") && event.getItemStack() == null
            && event.getSide().isClient() && event.getHand().equals(EnumHand.MAIN_HAND)) {
        System.out.println("RightClickBlock,HandType=" + event.getHand());
        ActiveTripod(Minecraft.getMinecraft().thePlayer.getName(),
                ((EntityTripod) event.getWorld()
                        .getEntityByID(event.getEntityPlayer().getEntityData().getInteger("renderViewCamera")))
                                .getDelay());
        event.setCanceled(true);
    }
}
项目:harshencastle    文件:ElytraPendant.java   
@HarshenEvent
public void onRightClick(PlayerInteractEvent event)
{
    if(event.getEntityPlayer().world.isRemote && HarshenUtils.toArray(RightClickBlock.class, RightClickEmpty.class).contains(event.getClass()) &&
            event.getEntityPlayer().getHeldItemMainhand().isEmpty() && event.getEntityPlayer().isElytraFlying())
    {
        HarshenNetwork.sendToServer(new MessagePacketSummonFirework());

        Vec3d vec3d = event.getEntityPlayer().getLookVec();
        event.getEntityPlayer().motionX += vec3d.x * 0.1D + (vec3d.x * 2.5D - event.getEntityPlayer().motionX) * 0.5D;
        event.getEntityPlayer().motionY += vec3d.y * 0.1D + (vec3d.y * 2.5D - event.getEntityPlayer().motionY) * 0.5D;
        event.getEntityPlayer().motionZ += vec3d.z * 0.1D + (vec3d.z * 2.5D - event.getEntityPlayer().motionZ) * 0.5D;
    }
}
项目:Geolosys    文件:ForgeEventListener.java   
@SubscribeEvent
public void registerEvent(RightClickBlock event)
{
    try
    {
        IBlockState state = event.getWorld().getBlockState(event.getPos());
        if (state.getBlock() == Geolosys.getInstance().ORE_SAMPLE || state.getBlock() == Geolosys.getInstance().ORE_SAMPLE_VANILLA)
        {
            if (event.getEntityPlayer().isSneaking() && event.getWorld().isRemote)
            {
                if (jmAPI.playerAccepts(Lib.MODID, DisplayType.Waypoint))
                {
                    String name = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)).getDisplayName();
                    try
                    {
                        jmAPI.show(new Waypoint(Lib.MODID, name, event.getWorld().provider.getDimension(), event.getPos()));
                    }
                    catch (Throwable t)
                    {
                        Geolosys.getInstance().LOGGER.info(t.getMessage());
                    }
                }
            }
        }
    }
    catch (NullPointerException ignored)
    {
    }
}
项目:wizards-of-lua    文件:TestEnvironmentTest.java   
@Test
public void test_can_receive_RightClickBlock_Event() {
  // Given:
  BlockPos pos = BlockPos.ORIGIN;

  // When:
  mc().post(newRightClickBlockEvent(mc().player().getDelegate(), pos));

  // Then:
  RightClickBlock act = mc().waitFor(RightClickBlock.class);
  assertThat(act.getPos()).isEqualTo(pos);
}
项目:wizards-of-lua    文件:EventRecorder.java   
@SubscribeEvent
public void onEvent(RightClickBlock evt) {
  // TODO can we remove this check?
  if (evt.getWorld().isRemote) {
    return;
  }
  addEvent(evt);
}
项目:CrystalMod    文件:EventHandler.java   
@SuppressWarnings("deprecation")
@SubscribeEvent(priority = EventPriority.LOW)
    public void onPlayerInteract(PlayerInteractEvent event) {
        if(event.getEntityPlayer() !=null && event.getWorld() !=null && event instanceof RightClickBlock){
            BlockPos pos = EntityUtil.getEntityLookedBlock(event.getEntityPlayer(), (float)CrystalMod.proxy.getReachDistanceForPlayer(event.getEntityPlayer()));
            if(pos !=null){
                if(event.getWorld().isBlockLoaded(pos)){
                    IBlockState state = event.getWorld().getBlockState(pos);
                    if(state.getBlock() == Blocks.WOOL && ItemStackTools.isValid(event.getEntityPlayer().getHeldItem(event.getHand())) && ItemUtil.itemStackMatchesOredict(event.getEntityPlayer().getHeldItem(event.getHand()), "slimeball")){

                        int waterCt = 0;
                        for(EnumFacing face : EnumFacing.VALUES){
                            IBlockState state2 = event.getWorld().getBlockState(pos.offset(face));
                            if(state2 !=null && state2.getBlock().getMaterial(state2) == Material.WATER){
                                waterCt++;
                            }
                        }

                        if(waterCt >= 4){
                            event.getWorld().setBlockState(pos, Blocks.SPONGE.getDefaultState());
                            event.getEntityPlayer().swingArm(event.getHand());

                            if (!event.getWorld().isRemote)
                            {
                                event.getWorld().playEvent(2001, pos, Block.getStateId(state));
                            }

                            if(!event.getEntityPlayer().capabilities.isCreativeMode)
                            event.getEntityPlayer().setHeldItem(event.getHand(), ItemUtil.consumeItem(event.getEntityPlayer().getHeldItem(event.getHand())));
                        }
                    }
                }
            }
        }
    }
项目:blockbuster    文件:ActionHandler.java   
/**
 * Event listener for Action.INTERACT_BLOCK (when player right clicks on
 * a block)
 */
@SubscribeEvent
public void onPlayerRightClickBlock(RightClickBlock event)
{
    EntityPlayer player = event.getEntityPlayer();
    List<Action> events = CommonProxy.manager.getActions(player);

    if (!player.worldObj.isRemote && events != null)
    {
        events.add(new InteractBlockAction(event.getPos()));
    }
}
项目:shifted-snow    文件:ModEventHandler.java   
@SubscribeEvent(priority = EventPriority.HIGH)
public void handleClickOnSnowable(RightClickBlock e) {
  if (e.getItemStack() == null || e.getItemStack().getItem() != Item.getItemFromBlock(Blocks.SNOW_LAYER))
    return;

  BlockPos pos = e.getPos().up();
  BlockPos posUnder = e.getPos();

  boolean result = handleClick(pos, posUnder, e.getWorld());
  if (result)
    e.setCanceled(result);
}
项目:shifted-snow    文件:ModEventHandler.java   
@SubscribeEvent(priority = EventPriority.LOW)
public void handleClickAtSnowableSide(RightClickBlock e) {
  if (e.getItemStack() == null || e.getItemStack().getItem() != Item.getItemFromBlock(Blocks.SNOW_LAYER))
    return;

  BlockPos pos = e.getPos().offset(e.getFace()).up();
  BlockPos posUnder = e.getPos().offset(e.getFace());

  boolean result = handleClick(pos, posUnder, e.getWorld());
  if (result)
    e.setCanceled(result);
}
项目:shifted-snow    文件:ModEventHandler.java   
@SubscribeEvent
public void handleClickUnderSnowable(RightClickBlock e) {
  if (e.getItemStack() == null || e.getItemStack().getItem() != Item.getItemFromBlock(Blocks.SNOW_LAYER))
    return;

  BlockPos pos = e.getPos().up(2);
  BlockPos posUnder = e.getPos().up();

  boolean result = handleClick(pos, posUnder, e.getWorld());
  if (result)
    e.setCanceled(result);
}
项目:shifted-snow    文件:ModEventHandler.java   
@SubscribeEvent
public void handleClickOnSnow(RightClickBlock e) {
  if (e.getItemStack() == null || e.getItemStack().getItem() != Item.getItemFromBlock(Blocks.SNOW_LAYER))
    return;

  BlockPos pos = e.getPos();
  BlockPos posUnder = e.getPos().down();

  boolean result = handleClick(pos, posUnder, e.getWorld());
  if (result)
    e.setCanceled(result);
}
项目:Signals    文件:RailReplacerEventHandler.java   
/**
 * Makes it so when a player right clicks a rail block with a different rail item, it will be replaced, without having to remove and place a rail.
 * @param e
 */
@SubscribeEvent
public void onBlockInteraction(RightClickBlock e){
    if(!e.getWorld().isRemote && e.getFace() == EnumFacing.UP) {
        ItemStack stack = e.getEntityPlayer().getHeldItemMainhand();
        BlockRailBase railBlock = getRailBlock(stack);
        if(railBlock != null) {
            IBlockState state = e.getWorld().getBlockState(e.getPos());
            IRail rail = RailManager.getInstance().getRail(e.getWorld(), e.getPos(), state);
            if(rail != null && state.getBlock() != railBlock) {
                EnumRailDirection dir = rail.getDirection(e.getWorld(), e.getPos(), state);
                e.getWorld().destroyBlock(e.getPos(), !e.getEntityPlayer().isCreative());
                List<EntityItem> drops = e.getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(e.getPos()));
                for(EntityItem drop : drops) {
                    drop.setPickupDelay(0);
                    drop.onCollideWithPlayer(e.getEntityPlayer());
                }

                e.getWorld().setBlockState(e.getPos(), railBlock.getDefaultState());
                if(!e.getEntityPlayer().isCreative()) stack.shrink(1);

                //Set the rail orientation equal to the old rail, if possible.
                if(railBlock.getShapeProperty().getAllowedValues().contains(dir)) {
                    IBlockState curState = e.getWorld().getBlockState(e.getPos());
                    e.getWorld().setBlockState(e.getPos(), curState.withProperty(railBlock.getShapeProperty(), dir));
                }
            }
        }
    }
}
项目:Cyclic    文件:ItemBlockScaffolding.java   
/**
 * This event is fired on both sides whenever the player right clicks while targeting a block. This event controls which of {@link net.minecraft.block.Block#onBlockActivated} and/or
 * {@link net.minecraft.item.Item#onItemUse} will be called after {@link net.minecraft.item.Item#onItemUseFirst} is called. Canceling the event will cause none of the above three to be called. There
 * are various results to this event, see the getters below. Note that handling things differently on the client vs server may cause desynchronizations!
 */
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event) {
  //instanceof ItemBlockScaffolding 
  if (event.getItemStack() != null && event.getItemStack().getItem() == this && event.getEntityPlayer().isSneaking()) {
    EnumFacing opp = event.getFace().getOpposite();
    BlockPos dest = UtilWorld.nextReplaceableInDirection(event.getWorld(), event.getPos(), opp, 16, this.getBlock());
    this.onItemUse(event.getEntityPlayer(), event.getWorld(), dest, event.getHand(), opp, 0, 0, 0);
    event.setCanceled(true);
  }
}
项目:HardVox    文件:SelectionListener.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event) {
    dueProcess(event, RegionSelector::selectSecondary);
}
项目:wizards-of-lua    文件:TestDataFactory.java   
protected RightClickBlock newRightClickBlockEvent(EntityPlayerMP player, BlockPos pos) {
  EnumHand hand = EnumHand.MAIN_HAND;
  EnumFacing face = EnumFacing.SOUTH;
  Vec3d hitVec = Vec3d.ZERO;
  return new RightClickBlock(player, hand, pos, face, hitVec);
}
项目:wizards-of-lua    文件:WolTestBase.java   
protected Iterable<BlockPos> positionsOf(Iterable<RightClickBlock> events) {
  return Iterables.transform(events, RightClickBlock::getPos);
}
项目:ExoMagica    文件:RitualHandler.java   
@SubscribeEvent
public void interact(RightClickBlock event) {
    if(event.getSide() != Side.SERVER) return;

    World world = event.getWorld();
    BlockPos pos = event.getPos();

    IBlockState state = world.getBlockState(pos);
    if(state == null) return;
    if(!(state.getBlock() instanceof IRitualCore)) return;
    IRitualCore core = (IRitualCore)state.getBlock();
    pos = core.getRitualCorePosition(world, pos, state);
    if(!core.isRitualCore(world, pos, state)) return;

    ItemStack stack = event.getItemStack();
    if(stack == null) return;
    Item item = stack.getItem();
    if(item == Items.STICK) {

    } else if(item instanceof IWand) {

    } else {
        return;
    }

    event.setCanceled(true);
    event.setUseBlock(Result.DENY);

    List<EntityRitual> rituals = world.getEntitiesWithinAABB(EntityRitual.class, new AxisAlignedBB(pos));
    for(int i = 0; i < rituals.size(); i++) {
        RitualRecipeContainer c = rituals.get(i).getContainer();
        if(c != null && c.world == world && c.pos.equals(pos)) return; // There is already a ritual running here
    }

    IRitual ritual = findRitual(core, world, pos);
    if(ritual == null) return;

    Map<String, List<IInventory>> inventories = ritual.getInventories(core, world, pos);
    if(inventories.isEmpty()) return;
    HashBiMap<String, IRitualRecipe> recipes = RITUALS_RECIPES.get(ritual);
    IRitualRecipe recipe = findRitualRecipe(ritual, recipes.values(), inventories);
    if(recipe == null) return;

    int ticks = recipe.getDuration(ritual);
    if(ticks == -1) ticks = ritual.getDuration(recipe, core, world, pos);

    RitualRecipeContainer container = ritual.createContainer(recipe, core, world, pos, ticks, inventories, Side.SERVER);

    if(container != null) {
        world.spawnEntityInWorld(new EntityRitual(world, container));
    }
}
项目:TeleToro    文件:Teletory.java   
@SubscribeEvent
public void useFlintAndSteel(RightClickBlock event) {
    if (event.getItemStack() == null || event.getItemStack().getItem() != Items.FLINT_AND_STEEL) {
        return;
    }

    BlockPos pos = event.getPos();

    int par4 = pos.getX();
    int par5 = pos.getY();
    int par6 = pos.getZ();

    int par7;

    if (event.getFace() == null) {
        par7 = 0;
    } else {
        par7 = event.getFace().getIndex();
    }

    if (par7 == 0) {
        par5--;
    }
    if (par7 == 1) {
        par5++;
    }
    if (par7 == 2) {
        par6--;
    }
    if (par7 == 3) {
        par6++;
    }
    if (par7 == 4) {
        par4--;
    }
    if (par7 == 5) {
        par4++;
    }

    Block i1 = getBlock(event.getWorld(), par4, par5, par6);
    if (i1 == Blocks.AIR) {
        boolean created = BlockTeletoryPortal.INSTANCE.trySpawnPortal(event.getWorld(), new BlockPos(par4, par5, par6));
        if (created) {
            event.setCanceled(true);
        }
    }
}
项目:EnchantmentRevealer    文件:Events.java   
@SubscribeEvent
public void onInteract(RightClickBlock event) {
    lastInteractPos = event.getPos();
}
项目:EZStorage2    文件:SecurityEvents.java   
/** Right click event */
@SubscribeEvent
public void onRightClickSystem(RightClickBlock e) {
    securityCanceler(e);
}
项目:SecurityCraft    文件:SCEventHandler.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event){
    if(event.getHand() == EnumHand.MAIN_HAND)
        if(!event.getWorld().isRemote){
            World world = event.getWorld();
            TileEntity tileEntity = world.getTileEntity(event.getPos());
            Block block = world.getBlockState(event.getPos()).getBlock();

            if(PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.codebreaker) && handleCodebreaking(event)) {
                event.setCanceled(true);
                return;
            }

            if(tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockModifier)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockModifier.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                return;
            }

            if(tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.getEntityPlayer(), Items.NAME_TAG) && event.getEntityPlayer().inventory.getCurrentItem().hasDisplayName()){
                event.setCanceled(true);

                for(String character : new String[]{"(", ")"})
                    if(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName().contains(character)) {
                        PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.error").replace("#n", event.getEntityPlayer().inventory.getCurrentItem().getDisplayName()).replace("#c", character), TextFormatting.RED);
                        return;
                    }

                if(((INameable) tileEntity).getCustomName().matches(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName())) {
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().inventory.getCurrentItem().stackSize--;

                ((INameable) tileEntity).setCustomName(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName());
                return;
            }

            if(tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockRemover)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockRemover.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                if(block == SCContent.laserBlock){
                    world.destroyBlock(event.getPos(), true);
                    BlockLaserBlock.destroyAdjacentLasers(event.getWorld(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }else{
                    world.destroyBlock(event.getPos(), true);
                    world.removeTileEntity(event.getPos());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }
            }
        }
}
项目:SecurityCraft    文件:SCEventHandler.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event){
    if(event.getHand() == EnumHand.MAIN_HAND)
        if(!event.getWorld().isRemote){
            World world = event.getWorld();
            TileEntity tileEntity = world.getTileEntity(event.getPos());
            Block block = world.getBlockState(event.getPos()).getBlock();

            if(PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.codebreaker) && handleCodebreaking(event)) {
                event.setCanceled(true);
                return;
            }

            if(tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockModifier)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockModifier.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                return;
            }

            if(tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.getEntityPlayer(), Items.NAME_TAG) && event.getEntityPlayer().inventory.getCurrentItem().hasDisplayName()){
                event.setCanceled(true);

                for(String character : new String[]{"(", ")"})
                    if(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName().contains(character)) {
                        PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.error").replace("#n", event.getEntityPlayer().inventory.getCurrentItem().getDisplayName()).replace("#c", character), TextFormatting.RED);
                        return;
                    }

                if(((INameable) tileEntity).getCustomName().matches(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName())) {
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().inventory.getCurrentItem().shrink(1);

                ((INameable) tileEntity).setCustomName(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName());
                return;
            }

            if(tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockRemover)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockRemover.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                if(block == SCContent.laserBlock){
                    world.destroyBlock(event.getPos(), true);
                    BlockLaserBlock.destroyAdjacentLasers(event.getWorld(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }else{
                    world.destroyBlock(event.getPos(), true);
                    world.removeTileEntity(event.getPos());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }
            }
        }
}
项目:SecurityCraft    文件:SCEventHandler.java   
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event){
    if(event.getHand() == EnumHand.MAIN_HAND)
        if(!event.getWorld().isRemote){
            World world = event.getWorld();
            TileEntity tileEntity = world.getTileEntity(event.getPos());
            Block block = world.getBlockState(event.getPos()).getBlock();

            if(PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.codebreaker) && handleCodebreaking(event)) {
                event.setCanceled(true);
                return;
            }

            if(tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockModifier)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockModifier.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                return;
            }

            if(tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.getEntityPlayer(), Items.NAME_TAG) && event.getEntityPlayer().inventory.getCurrentItem().hasDisplayName()){
                event.setCanceled(true);

                for(String character : new String[]{"(", ")"})
                    if(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName().contains(character)) {
                        PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.error").replace("#n", event.getEntityPlayer().inventory.getCurrentItem().getDisplayName()).replace("#c", character), TextFormatting.RED);
                        return;
                    }

                if(((INameable) tileEntity).getCustomName().matches(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName())) {
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), "Naming", ClientUtils.localize("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), TextFormatting.RED);
                    return;
                }

                event.getEntityPlayer().inventory.getCurrentItem().shrink(1);

                ((INameable) tileEntity).setCustomName(event.getEntityPlayer().inventory.getCurrentItem().getDisplayName());
                return;
            }

            if(tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.getEntityPlayer(), SCContent.universalBlockRemover)){
                event.setCanceled(true);

                if(!((IOwnable) tileEntity).getOwner().isOwner(event.getEntityPlayer())){
                    PlayerUtils.sendMessageToPlayer(event.getEntityPlayer(), ClientUtils.localize("item.universalBlockRemover.name"), ClientUtils.localize("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), TextFormatting.RED);
                    return;
                }

                if(block == SCContent.laserBlock){
                    world.destroyBlock(event.getPos(), true);
                    BlockLaserBlock.destroyAdjacentLasers(event.getWorld(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }else{
                    world.destroyBlock(event.getPos(), true);
                    world.removeTileEntity(event.getPos());
                    event.getEntityPlayer().inventory.getCurrentItem().damageItem(1, event.getEntityPlayer());
                }
            }
        }
}
项目:EnderIO    文件:ItemYetaWrench.java   
@Override
public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side,
    float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {

  if (world.isRemote) {
    // If its client side we have to return pass so this method is called on server, where we need to perform the op
    return EnumActionResult.PASS;
  }

  final IBlockState blockState = world.getBlockState(pos);
  IBlockState bs = blockState;
  Block block = bs.getBlock();
  boolean ret = false;
  RightClickBlock e = new RightClickBlock(player, hand, pos, side, new Vec3d(hitX, hitY, hitZ));
  if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
    return EnumActionResult.PASS;
  }
  if (block instanceof BlockDoor) {
    EnumDoorHalf half = bs.getValue(BlockDoor.HALF);
    if (half == EnumDoorHalf.UPPER) {
      pos = pos.down();
    }
  }
  if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
    ret = true;
  } else if (block instanceof IBlockPaintableBlock && !player.isSneaking() && !YetaUtil.shouldHeldItemHideFacades(player)) {
    IBlockState paintSource = ((IBlockPaintableBlock) block).getPaintSource(blockState, world, pos);
    if (paintSource != null) {
      final IBlockState rotatedPaintSource = PaintUtil.rotate(paintSource);
      if (rotatedPaintSource != paintSource) {
        ((IBlockPaintableBlock) block).setPaintSource(blockState, world, pos, rotatedPaintSource);
      }
      ret = true;
    }
  }

  // Need to catch 'shift-clicks' here and pass them on manually or an item in the off hand can eat the right click
  // so 'onBlockActivated' is never called
  if (!ret && player.isSneaking() && block instanceof BlockEio<?>) {
    BlockEio<?> beio = (BlockEio<?>) block;
    if (beio.shouldWrench(world, pos, player, side)) {
      beio.onBlockActivated(world, pos, bs, player, hand, side, hitX, hitY, hitZ);
      ret = true;
    }
  }
  if (ret) {
    player.swingArm(hand);
  }
  return ret ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}