Java Code Examples for net.minecraft.entity.player.EntityPlayer#sendStatusMessage()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#sendStatusMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private EnumActionResult deleteArea(ItemStack stack, World world, EntityPlayer player, BlockPosEU posStartIn, BlockPosEU posEndIn)
{
    if (posStartIn == null || posEndIn == null)
    {
        return EnumActionResult.PASS;
    }

    if (player.capabilities.isCreativeMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.creativeonly"), true);
        return EnumActionResult.FAIL;
    }

    this.deleteArea(stack, world, player, posStartIn.toBlockPos(), posEndIn.toBlockPos(),
            WandOption.AFFECT_ENTITIES.isEnabled(stack, Mode.DELETE));

    return EnumActionResult.SUCCESS;
}
 
Example 2
Source File: ItemKatana.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
	if(worldIn.isRemote) return;
	if(entityIn instanceof EntityPlayer){
		EntityPlayer player = (EntityPlayer) entityIn;
		ItemStack mainhand =player.getHeldItem(EnumHand.MAIN_HAND);
		ItemStack offhand =player.getHeldItem(EnumHand.OFF_HAND);
		boolean flag1 =!(mainhand.isEmpty())&&!(offhand.isEmpty()),
				flag2 = mainhand.getItem() instanceof ItemKatana && offhand.getItem() instanceof ItemKatana;
		if(flag1&&flag2) {
            player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
            player.dropItem(offhand, false);
            player.sendStatusMessage(new TextComponentTranslation("sakura.katana.wrong_duel", new Object()), false);
		}
	}
}
 
Example 3
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private EnumActionResult replaceBlocks(ItemStack stack, World world, EntityPlayer player, BlockPosEU center)
{
    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnableReplaceMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    BlockInfo biBound = getSelectedFixedBlockType(stack);

    if (biBound == null || biBound.blockState == world.getBlockState(center.toBlockPos()))
    {
        return EnumActionResult.FAIL;
    }

    List<BlockPosStateDist> positions = new ArrayList<BlockPosStateDist>();
    this.getBlockPositions(stack, world, player, positions, center);

    UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
    TaskReplaceBlocks task = new TaskReplaceBlocks(world, wandUUID, positions, Configs.buildersWandReplaceBlocksPerTick);
    PlayerTaskScheduler.getInstance().addTask(player, task, 1);

    return EnumActionResult.SUCCESS;
}
 
Example 4
Source File: ItemShinai.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
	if(worldIn.isRemote) return;
	if(entityIn instanceof EntityPlayer){
		EntityPlayer player = (EntityPlayer) entityIn;
		ItemStack mainhand =player.getHeldItem(EnumHand.MAIN_HAND);
		ItemStack offhand =player.getHeldItem(EnumHand.OFF_HAND);
		boolean flag1 =!(mainhand.isEmpty())&&!(offhand.isEmpty()),
				flag2 = mainhand.getItem() instanceof ItemShinai||offhand.getItem() instanceof ItemShinai;
		if(flag1&&flag2) {
            player.setItemStackToSlot((mainhand.getItem() instanceof ItemShinai)?EntityEquipmentSlot.OFFHAND:EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
            player.dropItem((mainhand.getItem() instanceof ItemShinai)?offhand:mainhand, false);
            player.sendStatusMessage(new TextComponentTranslation("sakura.katana.wrong_duel_shinai", new Object()), false);
		}
	}
}
 
Example 5
Source File: ItemLivingManipulator.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private EnumActionResult captureEntity(ItemStack stack, EntityPlayer player, EntityLivingBase livingBase)
{
    if (livingBase == null || livingBase instanceof EntityPlayer)
    {
        return EnumActionResult.PASS;
    }

    int count = this.getStoredEntityCount(stack);

    if (count < MAX_ENTITIES_PER_CARD)
    {
        return this.storeEntity(stack, livingBase, player);
    }

    player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.memorycard.full"), true);

    return EnumActionResult.FAIL;
}
 
Example 6
Source File: ElectricStats.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    IElectricItem electricItem = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
    if(electricItem != null && electricItem.canProvideChargeExternally() && player.isSneaking()) {
        if(!world.isRemote) {
            boolean isInDischargeMode = isInDishargeMode(itemStack);
            String locale = "metaitem.electric.discharge_mode." + (isInDischargeMode ? "disabled" : "enabled");
            player.sendStatusMessage(new TextComponentTranslation(locale), true);
            setInDischargeMode(itemStack, !isInDischargeMode);
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
 
Example 7
Source File: ScannerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack onItemUseFinish(ItemStack stack, EntityPlayer player) {
    if (!player.world.isRemote) {
        Pair<BlockPos, IBlockState> hitBlock = getHitBlock(player);
        if (hitBlock != null && checkCanUseScanner(stack, player, false).getLeft() == null) {
            ITextComponent component = new TextComponentTranslation("behavior.scanner.analyzing_complete");
            component.getStyle().setColor(TextFormatting.GOLD);
            player.sendStatusMessage(component, true);
            IScannableBlock magnifiableBlock = ((IScannableBlock) hitBlock.getRight().getBlock());
            List<ITextComponent> text = magnifiableBlock.getMagnifyResults(player.world, hitBlock.getLeft(), hitBlock.getRight(), player);
            text.forEach(player::sendMessage);
        }
    }
    return stack;
}
 
Example 8
Source File: ModeSwitchBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    if(player.isSneaking()) {
        T currentMode = getModeFromItemStack(itemStack);
        int currentModeIndex = ArrayUtils.indexOf(enumConstants, currentMode);
        T nextMode = enumConstants[(currentModeIndex + 1) % enumConstants.length];
        setModeForItemStack(itemStack, nextMode);
        ITextComponent newModeComponent = new TextComponentTranslation(nextMode.getUnlocalizedName());
        ITextComponent textComponent = new TextComponentTranslation("metaitem.behavior.mode_switch.mode_switched", newModeComponent);
        player.sendStatusMessage(textComponent, true);
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
 
Example 9
Source File: ItemWand.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
public void toggleMode(EntityPlayer player, ItemStack stack) {
    WandMode mode = getMode(stack);
    if (mode == WandMode.SPHERE) {
        mode = WandMode.LEVITATE;
    } else {
        mode = WandMode.SPHERE;
    }
    player.sendStatusMessage(new TextComponentString(TextFormatting.GREEN + "Switched to " + mode.name()), false);
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
    }
    stack.getTagCompound().setInteger("mode", mode.ordinal());
}
 
Example 10
Source File: BlockStorage.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (world.isRemote == false && player.capabilities.isCreativeMode == false)
    {
        switch (state.getValue(TYPE))
        {
            case MEMORY_CHEST_0:
            case MEMORY_CHEST_1:
            case MEMORY_CHEST_2:
                TileEntityMemoryChest te = getTileEntitySafely(world, pos, TileEntityMemoryChest.class);

                if (te != null && te.isUseableByPlayer(player) == false)
                {
                    TextComponentTranslation msg = new TextComponentTranslation(
                            "enderutilities.chat.message.private.owned.by", te.getOwnerName());
                    player.sendStatusMessage(msg, true);
                    return false;
                }
                break;

            default:
        }
    }

    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
Example 11
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private EnumActionResult replaceBlocks3D(ItemStack stack, World world, EntityPlayer player)
{
    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnableReplace3DMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    BlockPosEU pos1 = this.getPosition(stack, true);
    BlockPosEU pos2 = this.getPosition(stack, false);

    if (pos1 == null || pos2 == null)
    {
        return EnumActionResult.FAIL;
    }

    BlockInfo blockInfoTarget = getSelectedFixedBlockType(stack, true);
    BlockInfo blockInfoReplacement = getSelectedFixedBlockType(stack, false);

    if (blockInfoTarget != null && blockInfoReplacement != null)
    {
        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskReplaceBlocks3D task = new TaskReplaceBlocks3D(world, wandUUID, pos1, pos2, blockInfoTarget.blockState, blockInfoReplacement, 5);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);

        return EnumActionResult.SUCCESS;
    }

    return EnumActionResult.FAIL;
}
 
Example 12
Source File: ItemPortalScaler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean usePortalWithPortalScaler(ItemStack stack, World world, EntityPlayer player)
{
    int dimSrc = player.getEntityWorld().provider.getDimension();

    if ((dimSrc != 0 && dimSrc != -1) || this.itemHasScaleFactor(stack) == false)
    {
        return false;
    }

    int dimDst = dimSrc == 0 ? -1 : 0;
    Vec3d normalDest = this.getNormalDestinationPosition(player, dimDst);
    Vec3d posDest = this.getDestinationPosition(stack, player, dimDst);
    int cost = this.getTeleportCostEstimate(player, posDest, dimDst);
    //System.out.printf("cost estimate: %d normal: %s new: %s\n", cost, normalDest, posDest);

    if (UtilItemModular.useEnderCharge(stack, cost, true))
    {
        TeleportEntityNetherPortal tp = new TeleportEntityNetherPortal();
        Entity entity = tp.travelToDimension(player, dimDst, new BlockPos(posDest), 32, false);

        if (entity != null)
        {
            cost = this.getTeleportCost(normalDest, entity.getPositionVector());
            UtilItemModular.useEnderCharge(stack, cost, false);
            return true;
        }
    }
    else
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.notenoughendercharge"), true);
    }

    return false;
}
 
Example 13
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setPerTemplateAreaCorner(BlockPosEU pos, Mode mode, boolean isStart, ItemStack stack, EntityPlayer player)
{
    BlockPosEU oldPos = this.getPerTemplateAreaCorner(stack, mode, isStart);

    if (oldPos != null && oldPos.equals(pos))
    {
        this.removeCornerPositionTag(stack, mode, isStart);
        return;
    }

    if (PositionUtils.isPositionValid(pos))
    {
        if (isStart)
        {
            BlockPosEU endPos = this.getTransformedEndPosition(stack, mode, pos);

            if (endPos != null && PositionUtils.isPositionValid(endPos) == false)
            {
                player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.positionoutsideworld"), true);
                return;
            }
        }

        pos.writeToTag(this.getCornerPositionTag(stack, mode, isStart));
    }
    else
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.positionoutsideworld"), true);
    }
}
 
Example 14
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult stackArea(ItemStack stack, World world, EntityPlayer player, BlockPosEU pos1EU, BlockPosEU pos2EU)
{
    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnableStackMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    if (pos1EU == null || pos2EU == null)
    {
        return EnumActionResult.FAIL;
    }

    int dim = world.provider.getDimension();
    BlockPos pos1 = pos1EU.toBlockPos();
    BlockPos pos2 = pos2EU.toBlockPos();
    BlockPos endPosRelative = pos2.subtract(pos1);
    Area3D area = Area3D.getAreaFromNBT(this.getAreaTag(stack));

    if (pos1EU.getDimension() != dim || pos2EU.getDimension() != dim ||
        this.isStackedAreaWithinLimits(pos1, pos2, endPosRelative, area, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolargeortoofar"), true);
        return EnumActionResult.FAIL;
    }

    boolean takeEntities = player.capabilities.isCreativeMode && WandOption.AFFECT_ENTITIES.isEnabled(stack);
    PlacementSettings placement = new PlacementSettings();
    placement.setIgnoreEntities(takeEntities == false);
    ReplaceMode replaceMode = WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.STACK) ? ReplaceMode.WITH_NON_AIR : ReplaceMode.NOTHING;
    TemplateEnderUtilities template = new TemplateEnderUtilities(placement, replaceMode);
    template.takeBlocksFromWorld(world, pos1, pos2.subtract(pos1), takeEntities, false);

    if (player.capabilities.isCreativeMode)
    {
        this.stackAreaImmediate(world, pos1, endPosRelative, area, template);
    }
    else
    {
        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskStackArea task = new TaskStackArea(world, wandUUID, pos1, endPosRelative, template, area, Configs.buildersWandBlocksPerTick);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);
    }

    return EnumActionResult.SUCCESS;
}
 
Example 15
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult pasteAreaIntoWorld(ItemStack stack, World world, EntityPlayer player, BlockPosEU posStartIn)
{
    if (posStartIn == null)
    {
        return EnumActionResult.FAIL;
    }

    if (player.capabilities.isCreativeMode == false && Configs.buildersWandEnablePasteMode == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.featuredisabledinsurvivalmode"), true);
        return EnumActionResult.FAIL;
    }

    if (posStartIn.isWithinDistance(player, 160) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoofar"), true);
        return EnumActionResult.FAIL;
    }

    TemplateMetadata templateMeta = this.getTemplateMetadata(stack, player);

    if (this.isAreaWithinSizeLimit(templateMeta.getRelativeEndPosition(), stack, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolarge", this.getMaxAreaDimension(stack, player)), true);
        return EnumActionResult.FAIL;
    }

    PlacementSettings placement = this.getPasteModePlacement(stack, player);
    TemplateEnderUtilities template = this.getTemplate(world, player, stack, placement);

    if (player.capabilities.isCreativeMode)
    {
        template.setReplaceMode(WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.PASTE) ? ReplaceMode.EVERYTHING : ReplaceMode.NOTHING);
        template.addBlocksToWorld(world, posStartIn.toBlockPos());
    }
    else
    {
        template.setReplaceMode(WandOption.REPLACE_EXISTING.isEnabled(stack, Mode.PASTE) ? ReplaceMode.WITH_NON_AIR : ReplaceMode.NOTHING);

        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskTemplatePlaceBlocks task = new TaskTemplatePlaceBlocks(template, posStartIn.toBlockPos(), world.provider.getDimension(),
                player.getUniqueID(), wandUUID, Configs.buildersWandBlocksPerTick);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);
    }

    return EnumActionResult.SUCCESS;
}
 
Example 16
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult useWand(ItemStack stack, World world, EntityPlayer player, BlockPosEU posTarget)
{
    if (world.provider.getDimension() != posTarget.getDimension())
    {
        return EnumActionResult.FAIL;
    }

    if (player.capabilities.isCreativeMode == false && UtilItemModular.useEnderCharge(stack, ENDER_CHARGE_COST, true) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.notenoughendercharge"), true);
        return EnumActionResult.FAIL;
    }

    List<BlockPosStateDist> positions = new ArrayList<BlockPosStateDist>();
    BlockPosEU posStart = this.getPosition(stack, POS_START);
    BlockPosEU posEnd = this.getPosition(stack, POS_END);

    Mode mode = Mode.getMode(stack);

    if (mode == Mode.CUBE)
    {
        this.getBlockPositionsCube(stack, world, positions, posStart, posEnd);
    }
    else if (mode == Mode.WALLS)
    {
        this.getBlockPositionsWalls(stack, world, positions, posStart, posEnd);
    }
    else if (mode == Mode.COPY)
    {
        return this.copyAreaToTemplate(stack, world, player, posStart, posEnd);
    }
    else if (mode == Mode.PASTE)
    {
        return this.pasteAreaIntoWorld(stack, world, player, posStart);
    }
    else if (mode == Mode.DELETE)
    {
        return this.deleteArea(stack, world, player, posStart, posEnd);
    }
    else if (mode == Mode.MOVE_DST)
    {
        return this.moveArea(stack, world, player, posStart, posEnd);
    }
    else if (mode == Mode.MOVE_SRC)
    {
        return EnumActionResult.PASS;
    }
    else if (mode == Mode.REPLACE)
    {
        return this.replaceBlocks(stack, world, player, posStart != null ? posStart : posTarget);
    }
    else if (mode == Mode.REPLACE_3D)
    {
        return this.replaceBlocks3D(stack, world, player);
    }
    else if (mode == Mode.STACK)
    {
        return this.stackArea(stack, world, player, posStart, posEnd);
    }
    else
    {
        this.getBlockPositions(stack, world, player, positions, posStart != null ? posStart : posTarget);
    }

    // Small enough area, build it all in one go without the task
    if (positions.size() <= 60)
    {
        for (int i = 0; i < positions.size(); i++)
        {
            this.placeBlockToPosition(stack, world, player, positions.get(i));
        }

        // Offset the start position by one after a build operation completes, but not for Walls and Cube modes
        BlockPosEU pos = this.getPosition(stack, POS_START);

        if (pos != null && mode != Mode.WALLS && mode != Mode.CUBE &&
            mode != Mode.REPLACE && WandOption.MOVE_POSITION.isEnabled(stack, mode))
        {
            this.setPosition(pos.offset(pos.getFacing()), POS_START, stack, player);
        }
    }
    else
    {
        UUID wandUUID = NBTUtils.getUUIDFromItemStack(stack, WRAPPER_TAG_NAME, true);
        TaskBuildersWand task = new TaskBuildersWand(world, wandUUID, positions, Configs.buildersWandBlocksPerTick);
        PlayerTaskScheduler.getInstance().addTask(player, task, 1);
    }

    return EnumActionResult.SUCCESS;
}
 
Example 17
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPosition(BlockPosEU pos, boolean isStart, ItemStack stack, EntityPlayer player)
{
    Mode mode = Mode.getMode(stack);

    if (PositionUtils.isPositionValid(pos) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.positionoutsideworld"), true);
        return;
    }

    if ((isStart == false && (mode == Mode.PASTE || mode == Mode.MOVE_DST || mode == Mode.REPLACE)) ||
        (mode == Mode.REPLACE && WandOption.REPLACE_MODE_IS_AREA.isEnabled(stack, mode) == false))
    {
        return;
    }

    if (mode.isAreaMode())
    {
        this.setPerTemplateAreaCorner(pos, mode, isStart, stack, player);
        this.setMirror(stack, mode, Mirror.NONE);

        // Update the base rotation to the current area when changing corners
        BlockPosEU posStart = this.getPerTemplateAreaCorner(stack, mode, true);
        BlockPosEU posEnd = this.getPerTemplateAreaCorner(stack, mode, false);

        if (posStart != null && posEnd != null)
        {
            this.setAreaFacing(stack, mode, PositionUtils.getFacingFromPositions(posStart, posEnd));
        }

        return;
    }

    NBTTagCompound tag = this.getModeTag(stack, mode);

    String tagName = isStart ? "Pos1" : "Pos2";

    if (tag.hasKey(tagName, Constants.NBT.TAG_COMPOUND))
    {
        BlockPosEU oldPos = BlockPosEU.readFromTag(tag.getCompoundTag(tagName));

        if (oldPos != null && oldPos.equals(pos))
        {
            tag.removeTag(tagName);
        }
        else
        {
            tag.setTag(tagName, pos.writeToTag(new NBTTagCompound()));
        }
    }
    else
    {
        tag.setTag(tagName, pos.writeToTag(new NBTTagCompound()));
    }
}
 
Example 18
Source File: ItemFairyBell.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
	if (playerIn.world.isRemote || playerIn.isSneaking())
		return super.itemInteractionForEntity(stack, playerIn, target, hand);

	if (target instanceof EntityFairy) {

		EntityFairy targetFairy = (EntityFairy) target;
		FairyData targetData = targetFairy.getDataFairy();

		if (targetData == null) return super.itemInteractionForEntity(stack, playerIn, target, hand);

		if (targetData.isDepressed) {
			IMiscCapability cap = MiscCapabilityProvider.getCap(playerIn);
			if (cap != null) {
				UUID selected = cap.getSelectedFairyUUID();

				if (selected != null && selected.equals(targetFairy.getUniqueID())) {
					cap.setSelectedFairy(null);
					playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 0.25f);

					playerIn.sendStatusMessage(new TextComponentTranslation("item.wizardry:fairy_bell.status.deselected"), true);

				} else if (selected != null && !selected.equals(targetFairy.getUniqueID())) {

					List<Entity> list = playerIn.world.loadedEntityList;
					for (Entity entity : list) {
						if (entity instanceof EntityFairy && entity.getUniqueID().equals(selected)) {
							if (entity.isDead) continue;

							((EntityFairy) entity).setChainedFairy(targetFairy.getUniqueID());
							targetFairy.setChainedFairy(selected);

							playerIn.sendStatusMessage(new TextComponentTranslation("item.wizardry:fairy_bell.status.linked_to_fairy"), true);

							break;
						}
					}

				} else {
					cap.setSelectedFairy(targetFairy.getUniqueID());

					boolean movingMode = NBTHelper.getBoolean(stack, "moving_mode", true);

					if (!movingMode) {
						playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 0.75f);
					} else {
						playerIn.world.playSound(null, playerIn.getPosition(), ModSounds.TINY_BELL, SoundCategory.NEUTRAL, 1, 1.25f);
					}

					playerIn.sendStatusMessage(new TextComponentTranslation(movingMode ? "item.wizardry:fairy_bell.status.fairy_moving" : "item.wizardry:fairy_bell.status.fairy_aiming"), true);

				}
				cap.dataChanged(playerIn);
			}
		}
	}

	return super.itemInteractionForEntity(stack, playerIn, target, hand);
}
 
Example 19
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void deleteArea(ItemStack stack, World world, EntityPlayer player, BlockPos posStart, BlockPos posEnd, boolean removeEntities)
{
    if (posStart == null || posEnd == null)
    {
        return;
    }

    if (player.getDistanceSq(posStart) > 160 * 160)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoofar"), true);
        return;
    }

    if (this.isAreaWithinSizeLimit(posStart.subtract(posEnd), stack, player) == false)
    {
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.areatoolarge"), true);
        return;
    }

    // Set all blocks to air
    for (BlockPos.MutableBlockPos posMutable : BlockPos.getAllInBoxMutable(posStart, posEnd))
    {
        if (world.isAirBlock(posMutable) == false)
        {
            BlockUtils.setBlockToAirWithoutSpillingContents(world, posMutable, 2);
        }
    }

    // Remove pending block updates from within the area
    BlockPos posMin = PositionUtils.getMinCorner(posStart, posEnd);
    BlockPos posMax = PositionUtils.getMaxCorner(posStart, posEnd).add(1, 1, 1);
    StructureBoundingBox sbb = StructureBoundingBox.createProper(posMin.getX(), posMin.getY(), posMin.getZ(), posMax.getX(), posMax.getY(), posMax.getZ());
    world.getPendingBlockUpdates(sbb, true); // The boolean parameter indicates whether the entries will be removed

    // Remove all entities within the area
    int count = 0;

    if (removeEntities)
    {
        int x1 = Math.min(posStart.getX(), posEnd.getX());
        int y1 = Math.min(posStart.getY(), posEnd.getY());
        int z1 = Math.min(posStart.getZ(), posEnd.getZ());
        int x2 = Math.max(posStart.getX(), posEnd.getX());
        int y2 = Math.max(posStart.getY(), posEnd.getY());
        int z2 = Math.max(posStart.getZ(), posEnd.getZ());

        AxisAlignedBB bb = new AxisAlignedBB(x1, y1, z1, x2 + 1, y2 + 1, z2 + 1);
        List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, bb);

        for (Entity entity : entities)
        {
            if ((entity instanceof EntityPlayer) == false || entity instanceof FakePlayer)
            {
                entity.setDead();
                count++;
            }
        }

        if (count > 0)
        {
            player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.killedentitieswithcount", count), true);
        }
    }
}
 
Example 20
Source File: UtilItemModular.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns the inventory that the selected Link Crystal in the given modular item is currently bound to,
 * or null in case of errors.
 */
@Nullable
public static IItemHandler getBoundInventory(ItemStack modularStack, EntityPlayer player, int chunkLoadDuration)
{
    if (modularStack.isEmpty() || (modularStack.getItem() instanceof IModular) == false)
    {
        return null;
    }

    IModular iModular = (IModular) modularStack.getItem();
    TargetData target = TargetData.getTargetFromSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL);

    if (target == null ||
        iModular.getSelectedModuleTier(modularStack, ModuleType.TYPE_LINKCRYSTAL) != ItemLinkCrystal.TYPE_BLOCK ||
        OwnerData.canAccessSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
    {
        return null;
    }

    // Bound to a vanilla Ender Chest
    if ("minecraft:ender_chest".equals(target.blockName))
    {
        return new InvWrapper(player.getInventoryEnderChest());
    }

    World targetWorld = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(target.dimension);

    if (targetWorld == null)
    {
        return null;
    }

    if (chunkLoadDuration > 0)
    {
        // Chunk load the target
        ChunkLoading.getInstance().loadChunkForcedWithPlayerTicket(player, target.dimension,
                target.pos.getX() >> 4, target.pos.getZ() >> 4, chunkLoadDuration);
    }

    TileEntity te = targetWorld.getTileEntity(target.pos);

    // Block has changed since binding, or does not have IItemHandler capability
    if (te == null || te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, target.facing) == false ||
        target.isTargetBlockUnchanged() == false)
    {
        // Remove the bind
        TargetData.removeTargetTagFromSelectedModule(modularStack, ModuleType.TYPE_LINKCRYSTAL);
        player.sendStatusMessage(new TextComponentTranslation("enderutilities.chat.message.bound.block.changed"), true);
        return null;
    }

    return te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, target.facing);
}