Java 类net.minecraft.block.BlockStructure 实例源码

项目:harshencastle    文件:HarshenTemplate.java   
public Map<BlockPos, String> getDataBlocks(BlockPos pos, PlacementSettings placementIn)
{
    Map<BlockPos, String> map = Maps.<BlockPos, String>newHashMap();
    StructureBoundingBox structureboundingbox = placementIn.getBoundingBox();

    for (Template.BlockInfo template$blockinfo : this.blocks)
    {
        BlockPos blockpos = transformedBlockPos(placementIn, template$blockinfo.pos).add(pos);

        if (structureboundingbox == null || structureboundingbox.isVecInside(blockpos))
        {
            IBlockState iblockstate = template$blockinfo.blockState;

            if (iblockstate.getBlock() instanceof BlockStructure && template$blockinfo.tileentityData != null)
            {
                TileEntityStructure.Mode tileentitystructure$mode = TileEntityStructure.Mode.valueOf(template$blockinfo.tileentityData.getString("mode"));

                if (tileentitystructure$mode == TileEntityStructure.Mode.DATA)
                {
                    map.put(blockpos, template$blockinfo.tileentityData.getString("metadata"));
                }
            }
        }
    }

    return map;
}
项目:Backmemed    文件:TileEntityStructure.java   
private void updateBlockState()
{
    if (this.world != null)
    {
        BlockPos blockpos = this.getPos();
        IBlockState iblockstate = this.world.getBlockState(blockpos);

        if (iblockstate.getBlock() == Blocks.STRUCTURE_BLOCK)
        {
            this.world.setBlockState(blockpos, iblockstate.withProperty(BlockStructure.MODE, this.mode), 2);
        }
    }
}
项目:Backmemed    文件:TileEntityStructure.java   
public void setMode(TileEntityStructure.Mode modeIn)
{
    this.mode = modeIn;
    IBlockState iblockstate = this.world.getBlockState(this.getPos());

    if (iblockstate.getBlock() == Blocks.STRUCTURE_BLOCK)
    {
        this.world.setBlockState(this.getPos(), iblockstate.withProperty(BlockStructure.MODE, modeIn), 2);
    }
}
项目:CustomWorldGen    文件:TileEntityStructure.java   
private void updateBlockState()
{
    if (this.worldObj != null)
    {
        BlockPos blockpos = this.getPos();
        IBlockState iblockstate = this.worldObj.getBlockState(blockpos);

        if (iblockstate.getBlock() == Blocks.STRUCTURE_BLOCK)
        {
            this.worldObj.setBlockState(blockpos, iblockstate.withProperty(BlockStructure.MODE, this.mode), 2);
        }
    }
}
项目:CustomWorldGen    文件:TileEntityStructure.java   
public void setMode(TileEntityStructure.Mode modeIn)
{
    this.mode = modeIn;
    IBlockState iblockstate = this.worldObj.getBlockState(this.getPos());

    if (iblockstate.getBlock() == Blocks.STRUCTURE_BLOCK)
    {
        this.worldObj.setBlockState(this.getPos(), iblockstate.withProperty(BlockStructure.MODE, modeIn), 2);
    }
}
项目:pnc-repressurized    文件:DroneAIBlockInteract.java   
private boolean rightClick(BlockPos pos) {
    EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
    EntityPlayer player = drone.getFakePlayer();
    World world = drone.world();
    ItemStack stack = player.getHeldItemMainhand();

    player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
    player.rotationPitch = faceDir.getFrontOffsetY() * -90;
    player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);

    float hitX = (float)(player.posX - pos.getX());
    float hitY = (float)(player.posY - pos.getY());
    float hitZ = (float)(player.posZ - pos.getZ());

    // this is adapted from PlayerInteractionManager#processRightClickBlock()
    try {
        PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(),  ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
        if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
            return false;
        }

        EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
        if (ret != EnumActionResult.PASS) return false;

        boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
        EnumActionResult result = EnumActionResult.PASS;

        if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            IBlockState iblockstate = world.getBlockState(pos);
            if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
                    result = EnumActionResult.SUCCESS;
                }
        }

        if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
            return false;
        }

        if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
            Block block = ((ItemBlock)stack.getItem()).getBlock();
            if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
                return false;
            }
        }

        if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
                || result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
            ItemStack copyBeforeUse = stack.copy();
            result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
            if (result == EnumActionResult.PASS) {
                ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
                player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
            }
            if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
                net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
            }
        }

        return false;
    } catch (Throwable e) {
        Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
        e.printStackTrace();
        return false;
    }
}
项目:harshencastle    文件:HarshenTemplate.java   
protected HarshenTemplate(ResourceLocation location) {
    String s = location.getResourceDomain();
       String s1 = location.getResourcePath();
       InputStream stream = null;
       boolean flag;
       try
       {
        stream = getClass().getResourceAsStream("/assets/" + HarshenCastle.MODID + "/structures/" + s1 + ".nbt");
           NBTTagCompound compound = CompressedStreamTools.readCompressed(stream);
           if (!compound.hasKey("DataVersion", 99))
           {
            compound.setInteger("DataVersion", 500);
           }
           Template template = new Template();
           DataFixer fixer;
           try
           {
            fixer = Minecraft.getMinecraft().getDataFixer();
           }
           catch (Throwable e) {
            fixer = FMLServerHandler.instance().getDataFixer();
        }
           template.read(fixer.process(FixTypes.STRUCTURE, compound));
           this.blocks.clear();
           NBTTagList nbttaglist = compound.getTagList("size", 3);
           this.size = new BlockPos(nbttaglist.getIntAt(0), nbttaglist.getIntAt(1), nbttaglist.getIntAt(2));
           NBTTagList nbttaglist4 = compound.getTagList("pos", 3);
           if(nbttaglist4.hasNoTags())
            this.pos = BlockPos.ORIGIN;
           else
               this.pos = new BlockPos(nbttaglist4.getIntAt(0), nbttaglist4.getIntAt(1), nbttaglist4.getIntAt(2));
           BasicPalette template$basicpalette = new BasicPalette();
           NBTTagList nbttaglist1 = compound.getTagList("palette", 10);

           for (int i = 0; i < nbttaglist1.tagCount(); ++i)
           {
               template$basicpalette.addMapping(NBTUtil.readBlockState(nbttaglist1.getCompoundTagAt(i)), i);
           }

           NBTTagList nbttaglist3 = compound.getTagList("blocks", 10);
           for (int j = 0; j < nbttaglist3.tagCount(); ++j)
           {
               NBTTagCompound nbttagcompound = nbttaglist3.getCompoundTagAt(j);
               NBTTagList nbttaglist2 = nbttagcompound.getTagList("pos", 3);
               BlockPos blockpos = new BlockPos(nbttaglist2.getIntAt(0), nbttaglist2.getIntAt(1), nbttaglist2.getIntAt(2));
               IBlockState iblockstate = template$basicpalette.stateFor(nbttagcompound.getInteger("state"));
               NBTTagCompound nbttagcompound1;

               if (nbttagcompound.hasKey("nbt"))
               {
                   nbttagcompound1 = nbttagcompound.getCompoundTag("nbt");
               }
               else
               {
                   nbttagcompound1 = null;
               }

               if(!(iblockstate.getBlock() instanceof BlockStructure))
                this.blocks.add(new Template.BlockInfo(blockpos, iblockstate, nbttagcompound1));
           }
       }
       catch (Throwable var10)
       {
       }
       finally
       {
           IOUtils.closeQuietly(stream);
       }
}
项目:Thermionics    文件:ToolHelper.java   
/**
 * Destroys and tries to harvest a block with the currently active tool, except that instead of calling
 * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
 */
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
    if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!

    GameType gameType = player.interactionManager.getGameType();

    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
       if (exp == -1) {
           return false;
       } else {
           IBlockState iblockstate = world.getBlockState(pos);
           if (iblockstate.getBlockHardness(world, pos)<0) return false;
           TileEntity tileentity = world.getTileEntity(pos);
           Block block = iblockstate.getBlock();

           if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
               world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
               return false;
           } else {
               ItemStack stack = player.getHeldItemMainhand();
               if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;

               world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
               boolean removed = false;

               if (gameType==GameType.CREATIVE) {
                   removed = removeBlock(world, pos, player, false);
                   player.connection.sendPacket(new SPacketBlockChange(world, pos));
               } else {
                   ItemStack itemstack1 = player.getHeldItemMainhand();
                   ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                   boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);

                   if (!itemstack1.isEmpty()) {
                   //    itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                    if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
                        ((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
                    }
                   }

                   removed = removeBlock(world, pos, player, canHarvest);
                   if (removed && canHarvest) {
                       iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                   }
               }

               // Drop experience
               if (gameType!=GameType.CREATIVE && removed && exp > 0) {
                   iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
               }
               return removed;
           }
       }
}
项目:Backmemed    文件:PlayerControllerMP.java   
public EnumActionResult processRightClickBlock(EntityPlayerSP player, WorldClient worldIn, BlockPos stack, EnumFacing pos, Vec3d facing, EnumHand vec)
{
    this.syncCurrentPlayItem();
    ItemStack itemstack = player.getHeldItem(vec);
    float f = (float)(facing.xCoord - (double)stack.getX());
    float f1 = (float)(facing.yCoord - (double)stack.getY());
    float f2 = (float)(facing.zCoord - (double)stack.getZ());
    boolean flag = false;

    if (!this.mc.world.getWorldBorder().contains(stack))
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        if (this.currentGameType != GameType.SPECTATOR)
        {
            IBlockState iblockstate = worldIn.getBlockState(stack);

            if ((!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b()) && iblockstate.getBlock().onBlockActivated(worldIn, stack, iblockstate, player, vec, pos, f, f1, f2))
            {
                flag = true;
            }

            if (!flag && itemstack.getItem() instanceof ItemBlock)
            {
                ItemBlock itemblock = (ItemBlock)itemstack.getItem();

                if (!itemblock.canPlaceBlockOnSide(worldIn, stack, pos, player, itemstack))
                {
                    return EnumActionResult.FAIL;
                }
            }
        }

        this.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(stack, pos, vec, f, f1, f2));

        if (!flag && this.currentGameType != GameType.SPECTATOR)
        {
            if (itemstack.func_190926_b())
            {
                return EnumActionResult.PASS;
            }
            else if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
            {
                return EnumActionResult.PASS;
            }
            else
            {
                if (itemstack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
                {
                    Block block = ((ItemBlock)itemstack.getItem()).getBlock();

                    if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
                    {
                        return EnumActionResult.FAIL;
                    }
                }

                if (this.currentGameType.isCreative())
                {
                    int i = itemstack.getMetadata();
                    int j = itemstack.func_190916_E();
                    EnumActionResult enumactionresult = itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
                    itemstack.setItemDamage(i);
                    itemstack.func_190920_e(j);
                    return enumactionresult;
                }
                else
                {
                    return itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
                }
            }
        }
        else
        {
            return EnumActionResult.SUCCESS;
        }
    }
}
项目:Backmemed    文件:PlayerInteractionManager.java   
/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos)
{
    if (this.gameType.isCreative() && !this.thisPlayerMP.getHeldItemMainhand().func_190926_b() && this.thisPlayerMP.getHeldItemMainhand().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
        {
            this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
            return false;
        }
        else
        {
            if (this.gameType.isAdventure())
            {
                if (this.gameType == GameType.SPECTATOR)
                {
                    return false;
                }

                if (!this.thisPlayerMP.isAllowEdit())
                {
                    ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand();

                    if (itemstack.func_190926_b())
                    {
                        return false;
                    }

                    if (!itemstack.canDestroy(block))
                    {
                        return false;
                    }
                }
            }

            this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1 = this.removeBlock(pos);

            if (this.isCreative())
            {
                this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
            }
            else
            {
                ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
                ItemStack itemstack2 = itemstack1.func_190926_b() ? ItemStack.field_190927_a : itemstack1.copy();
                boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate);

                if (!itemstack1.func_190926_b())
                {
                    itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);
                }

                if (flag1 && flag)
                {
                    iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
                }
            }

            return flag1;
        }
    }
}
项目:Backmemed    文件:PlayerInteractionManager.java   
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (this.gameType == GameType.SPECTATOR)
    {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof ILockableContainer)
        {
            Block block1 = worldIn.getBlockState(pos).getBlock();
            ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;

            if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
            {
                ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
            }

            if (ilockablecontainer != null)
            {
                player.displayGUIChest(ilockablecontainer);
                return EnumActionResult.SUCCESS;
            }
        }
        else if (tileentity instanceof IInventory)
        {
            player.displayGUIChest((IInventory)tileentity);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }
    else
    {
        if (!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b())
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);

            if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ))
            {
                return EnumActionResult.SUCCESS;
            }
        }

        if (stack.func_190926_b())
        {
            return EnumActionResult.PASS;
        }
        else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
        {
            return EnumActionResult.PASS;
        }
        else
        {
            if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
            {
                Block block = ((ItemBlock)stack.getItem()).getBlock();

                if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
                {
                    return EnumActionResult.FAIL;
                }
            }

            if (this.isCreative())
            {
                int j = stack.getMetadata();
                int i = stack.func_190916_E();
                EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
                stack.setItemDamage(j);
                stack.func_190920_e(i);
                return enumactionresult;
            }
            else
            {
                return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
            }
        }
    }
}
项目:CustomWorldGen    文件:PlayerControllerMP.java   
public boolean onPlayerDestroyBlock(BlockPos pos)
{
    if (this.currentGameType.isAdventure())
    {
        if (this.currentGameType == GameType.SPECTATOR)
        {
            return false;
        }

        if (!this.mc.thePlayer.isAllowEdit())
        {
            ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();

            if (itemstack == null)
            {
                return false;
            }

            if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
            {
                return false;
            }
        }
    }

    ItemStack stack = mc.thePlayer.getHeldItemMainhand();
    if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
    {
        return false;
    }

    if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        World world = this.mc.theWorld;
        IBlockState iblockstate = world.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.canUseCommandBlock())
        {
            return false;
        }
        else if (iblockstate.getMaterial() == Material.AIR)
        {
            return false;
        }
        else
        {
            world.playEvent(2001, pos, Block.getStateId(iblockstate));

            this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());

            if (!this.currentGameType.isCreative())
            {
                ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);

                    if (itemstack1.stackSize <= 0)
                    {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
                        this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
                    }
                }
            }

            boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);

            if (flag)
            {
                block.onBlockDestroyedByPlayer(world, pos, iblockstate);
            }
            return flag;
        }
    }
}
项目:CustomWorldGen    文件:PlayerInteractionManager.java   
/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos)
{
    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, pos);
    if (exp == -1)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
        {
            this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
            return false;
        }
        else
        {
            ItemStack stack = thisPlayerMP.getHeldItemMainhand();
            if (stack != null && stack.getItem().onBlockStartBreak(stack, pos, thisPlayerMP)) return false;

            this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1 = false;

            if (this.isCreative())
            {
                flag1 = this.removeBlock(pos);
                this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
            }
            else
            {
                ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
                ItemStack itemstack2 = itemstack1 == null ? null : itemstack1.copy();
                boolean flag = iblockstate.getBlock().canHarvestBlock(theWorld, pos, thisPlayerMP);

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);

                    if (itemstack1.stackSize <= 0)
                    {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.thisPlayerMP, itemstack1, EnumHand.MAIN_HAND);
                        this.thisPlayerMP.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
                    }
                }

                flag1 = this.removeBlock(pos, flag);
                if (flag1 && flag)
                {
                    iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
                }
            }

            // Drop experience
            if (!this.isCreative() && flag1 && exp > 0)
            {
                iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp);
            }
            return flag1;
        }
    }
}
项目:ExpandedRailsMod    文件:PlayerControllerMP.java   
public boolean onPlayerDestroyBlock(BlockPos pos)
{
    if (this.currentGameType.isAdventure())
    {
        if (this.currentGameType == GameType.SPECTATOR)
        {
            return false;
        }

        if (!this.mc.thePlayer.isAllowEdit())
        {
            ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();

            if (itemstack == null)
            {
                return false;
            }

            if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
            {
                return false;
            }
        }
    }

    ItemStack stack = mc.thePlayer.getHeldItemMainhand();
    if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
    {
        return false;
    }

    if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        World world = this.mc.theWorld;
        IBlockState iblockstate = world.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.func_189808_dh())
        {
            return false;
        }
        else if (iblockstate.getMaterial() == Material.AIR)
        {
            return false;
        }
        else
        {
            world.playEvent(2001, pos, Block.getStateId(iblockstate));

            this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());

            if (!this.currentGameType.isCreative())
            {
                ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);

                    if (itemstack1.stackSize <= 0)
                    {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
                        this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
                    }
                }
            }

            boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);

            if (flag)
            {
                block.onBlockDestroyedByPlayer(world, pos, iblockstate);
            }
            return flag;
        }
    }
}
项目:YUNoMakeGoodMap    文件:PlatformCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}