Search in sources :

Example 86 with ActionResult

use of net.minecraft.util.ActionResult in project RFToolsDimensions by McJty.

the class DimensionMonitorItem method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        int id = player.getEntityWorld().provider.getDimension();
        RfToolsDimensionManager dimensionManager = RfToolsDimensionManager.getDimensionManager(player.getEntityWorld());
        DimensionInformation dimensionInformation = dimensionManager.getDimensionInformation(id);
        if (dimensionInformation == null) {
            Logging.message(player, "Not an RFTools dimension!");
        } else {
            String name = dimensionInformation.getName();
            DimensionStorage storage = DimensionStorage.getDimensionStorage(player.getEntityWorld());
            int power = storage != null ? storage.getEnergyLevel(id) : 0;
            Logging.message(player, TextFormatting.BLUE + "Name: " + name + " (Id " + id + ")" + TextFormatting.YELLOW + "    Power: " + power + " RF");
            if (player.isSneaking()) {
                Logging.message(player, TextFormatting.RED + "Description: " + dimensionInformation.getDescriptor().getDescriptionString());
                System.out.println("Description:  = " + dimensionInformation.getDescriptor().getDescriptionString());
            }
        }
        return new ActionResult<>(EnumActionResult.SUCCESS, stack);
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : DimensionStorage(mcjty.rftoolsdim.dimensions.DimensionStorage) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack) DimensionInformation(mcjty.rftoolsdim.dimensions.DimensionInformation) RfToolsDimensionManager(mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)

Example 87 with ActionResult

use of net.minecraft.util.ActionResult in project RFToolsDimensions by McJty.

the class KnownDimlet method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    if (world.isRemote) {
        return new ActionResult<>(EnumActionResult.PASS, stack);
    }
    DimletKey key = KnownDimletConfiguration.getDimletKey(stack);
    if (KnownDimletConfiguration.isSeedDimlet(key)) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
        }
        boolean locked = tagCompound.getBoolean("locked");
        if (locked) {
            Logging.message(player, TextFormatting.YELLOW + "This seed dimlet is locked. You cannot modify it!");
            return new ActionResult<>(EnumActionResult.SUCCESS, stack);
        }
        long forcedSeed = tagCompound.getLong("forcedSeed");
        if (player.isSneaking()) {
            if (forcedSeed == 0) {
                Logging.message(player, TextFormatting.YELLOW + "This dimlet has no seed. You cannot lock it!");
                return new ActionResult<>(EnumActionResult.SUCCESS, stack);
            }
            tagCompound.setBoolean("locked", true);
            Logging.message(player, "Dimlet locked!");
        } else {
            long seed = world.getSeed();
            tagCompound.setLong("forcedSeed", seed);
            Logging.message(player, "Seed set to: " + seed);
        }
        stack.setTagCompound(tagCompound);
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) DimletKey(mcjty.rftoolsdim.dimensions.dimlets.DimletKey)

Example 88 with ActionResult

use of net.minecraft.util.ActionResult in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    ItemStack itemStackIn = playerIn.getHeldItem(hand);
    boolean flag = containedBlock == Blocks.AIR;
    RayTraceResult raytraceresult = rayTrace(worldIn, playerIn, flag);
    ActionResult<ItemStack> ret = ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, raytraceresult);
    if (ret != null)
        return ret;
    if (raytraceresult == null)
        return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
    else if (raytraceresult.typeOfHit != RayTraceResult.Type.BLOCK)
        return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
    else {
        BlockPos blockpos = raytraceresult.getBlockPos();
        if (!worldIn.isBlockModifiable(playerIn, blockpos))
            return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
        else if (flag) {
            if (!playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
            else {
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getMaterial();
                if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, fillBucket(itemStackIn, playerIn, SCContent.fWaterBucket));
                } else if (material == Material.LAVA && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, fillBucket(itemStackIn, playerIn, SCContent.fLavaBucket));
                } else
                    return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
            }
        } else {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);
            if (!playerIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemStackIn))
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
            else if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos1)) {
                playerIn.addStat(StatList.getObjectUseStats(this));
                return !playerIn.capabilities.isCreativeMode ? new ActionResult<ItemStack>(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
            } else
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 89 with ActionResult

use of net.minecraft.util.ActionResult in project SilentGems by SilentChaos512.

the class ItemDebug method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    // playerIn.attackEntityFrom(DamageSource.inWall, 1.0f);
    FoodStats food = playerIn.getFoodStats();
    food.setFoodLevel(food.getFoodLevel() - 2);
    food.setFoodSaturationLevel(food.getSaturationLevel() - 0.2f);
    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) FoodStats(net.minecraft.util.FoodStats)

Example 90 with ActionResult

use of net.minecraft.util.ActionResult in project SilentGems by SilentChaos512.

the class ItemSkillOrb method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack offhand = player.getHeldItemOffhand();
    // Orb in main hand, tool/armor in offhand.
    if (hand != EnumHand.MAIN_HAND || StackHelper.isEmpty(offhand) || !(offhand.getItem() instanceof ITool || offhand.getItem() instanceof IArmor)) {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand));
    }
    ItemStack orb = player.getHeldItemMainhand();
    // Check for tool soul.
    ToolSoul soul = SoulManager.getSoul(offhand);
    if (soul == null) {
        if (!world.isRemote) {
            ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "no_soul"));
        }
        return new ActionResult<ItemStack>(EnumActionResult.PASS, orb);
    }
    // Check skill on orb.
    SoulSkill skill = getSkill(orb);
    if (skill == null) {
        if (!world.isRemote) {
            ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "no_skill"));
        }
        return new ActionResult<ItemStack>(EnumActionResult.PASS, orb);
    }
    if (world.isRemote) {
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
    }
    // Try to add or level up the skill.
    if (soul.addOrLevelSkill(skill, offhand, player)) {
        ToolHelper.recalculateStats(offhand);
        StackHelper.shrink(orb, 1);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, orb);
    } else {
        ChatHelper.sendMessage(player, SilentGems.localizationHelper.getItemSubText(Names.SKILL_ORB, "max_level"));
        return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand));
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) SoulSkill(net.silentchaos512.gems.lib.soul.SoulSkill) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Aggregations

ActionResult (net.minecraft.util.ActionResult)148 EnumActionResult (net.minecraft.util.EnumActionResult)147 ItemStack (net.minecraft.item.ItemStack)124 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)39 BlockPos (net.minecraft.util.math.BlockPos)31 RayTraceResult (net.minecraft.util.math.RayTraceResult)25 Nonnull (javax.annotation.Nonnull)15 Vec3d (net.minecraft.util.math.Vec3d)14 IBlockState (net.minecraft.block.state.IBlockState)12 TextComponentString (net.minecraft.util.text.TextComponentString)12 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)8 Entity (net.minecraft.entity.Entity)7 Block (net.minecraft.block.Block)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntity (net.minecraft.tileentity.TileEntity)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)3 RfToolsDimensionManager (mcjty.rftoolsdim.dimensions.RfToolsDimensionManager)3 FluidStack (net.minecraftforge.fluids.FluidStack)3