Search in sources :

Example 46 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Engine by VoltzEngine-Project.

the class BlockBase method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    try {
        boolean activated = false;
        Object tile = getTile(world, x, y, z);
        if (WrenchUtility.isUsableWrench(player, player.inventory.getCurrentItem(), x, y, z)) {
            ListenerIterator it = new ListenerIterator(world, x, y, z, this, "wrench");
            while (it.hasNext()) {
                ITileEventListener next = it.next();
                if (next instanceof IWrenchListener && ((IWrenchListener) next).handlesWrenchRightClick() && ((IWrenchListener) next).onPlayerRightClickWrench(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
            if (activated) {
                WrenchUtility.damageWrench(player, player.inventory.getCurrentItem(), x, y, z);
            }
            if (activated) {
                return true;
            }
        }
        //TODO move to listener to prevent usage of IGuiTile in special cases
        if (tile instanceof IGuiTile && ((IGuiTile) tile).shouldOpenOnRightClick(player)) {
            int id = ((IGuiTile) tile).getDefaultGuiID(player);
            if (id >= 0) {
                Object o = ((IGuiTile) tile).getServerGuiElement(id, player);
                if (o != null) {
                    player.openGui(mod, id, world, x, y, z);
                    return true;
                }
            }
        }
        ListenerIterator it = new ListenerIterator(world, x, y, z, this, "activation");
        while (it.hasNext()) {
            ITileEventListener next = it.next();
            if (next instanceof IActivationListener) {
                if (((IActivationListener) next).onPlayerActivated(player, side, hitX, hitY, hitZ)) {
                    activated = true;
                }
            }
        }
        return activated;
    } catch (Exception e) {
        outputError(world, x, y, z, "while right click block on side " + side, e);
        player.addChatComponentMessage(new ChatComponentText(Colors.RED.code + LanguageUtility.getLocal("blockTile.error.onBlockActivated")));
    }
    return false;
}
Also used : ListenerIterator(com.builtbroken.mc.prefab.tile.listeners.ListenerIterator) IGuiTile(com.builtbroken.mc.api.tile.access.IGuiTile) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 47 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ICBM-Classic by BuiltBrokenModding.

the class CommandICBM method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) {
    try {
        EntityPlayer entityPlayer = (EntityPlayer) sender;
        int dimension = entityPlayer.worldObj.provider.dimensionId;
        if (args == null || args.length == 0 || args[0].equalsIgnoreCase("help")) {
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc help"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc lag <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc remove <All/Missile/Explosion> <radius>"));
            ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc emp <radius>"));
            return;
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("lag")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(entityPlayer.posX - radius, entityPlayer.posY - radius, entityPlayer.posZ - radius, entityPlayer.posX + radius, entityPlayer.posY + radius, entityPlayer.posZ + radius);
                List<Entity> entitiesNearby = entityPlayer.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if (entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if (entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if (entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM lag sources within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 3 && args[0].equalsIgnoreCase("remove")) {
            int radius = parseInt(sender, args[2]);
            boolean all = args[1].equalsIgnoreCase("all");
            boolean missile = args[1].equalsIgnoreCase("missiles");
            boolean explosion = args[1].equalsIgnoreCase("explosion");
            String str = "entities";
            if (missile) {
                str = "missiles";
            }
            if (explosion) {
                str = "explosions";
            }
            if (radius > 0) {
                EntityPlayer player = (EntityPlayer) sender;
                AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(player.posX - radius, player.posY - radius, player.posZ - radius, player.posX + radius, player.posY + radius, player.posZ + radius);
                List<Entity> entitiesNearby = player.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
                for (Entity entity : entitiesNearby) {
                    if ((all || explosion) && entity instanceof EntityFlyingBlock) {
                        ((EntityFlyingBlock) entity).setBlock();
                    } else if ((all || missile) && entity instanceof EntityMissile) {
                        entity.setDead();
                    } else if ((all || explosion) && entity instanceof EntityExplosion) {
                        entity.setDead();
                    }
                }
                ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM " + str + " within " + radius + " radius."));
                return;
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        } else if (args.length >= 2 && args[0].equalsIgnoreCase("emp")) {
            int radius = parseInt(sender, args[1]);
            if (radius > 0) {
                new BlastEMP(entityPlayer.worldObj, null, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, radius).setEffectBlocks().setEffectEntities().doExplode();
                switch(entityPlayer.worldObj.rand.nextInt(20)) {
                    case 0:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Did you pay the power bill?"));
                        return;
                    case 1:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("See them power their toys now!"));
                        return;
                    case 2:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Hey who turned the lights out."));
                        return;
                    case 3:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Ha! I run on steam power!"));
                        return;
                    case 4:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("The power of lighting at my finger tips!"));
                        return;
                    default:
                        ((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Zap!"));
                        return;
                }
            } else {
                throw new WrongUsageException("Radius needs to be higher than zero");
            }
        }
    } catch (Exception e) {
    }
    throw new WrongUsageException(this.getCommandUsage(sender));
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityMissile(icbm.classic.content.entity.EntityMissile) BlastEMP(icbm.classic.content.explosive.blast.BlastEMP) WrongUsageException(net.minecraft.command.WrongUsageException) WrongUsageException(net.minecraft.command.WrongUsageException) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) List(java.util.List) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 48 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ICBM-Classic by BuiltBrokenModding.

the class ItemTracker method onLeftClickEntity.

/**
     * Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
     * return value is true further processing is canceled and the entity is not attacked.
     *
     * @param itemStack The Item being used
     * @param player    The player that is attacking
     * @param entity    The entity being attacked
     * @return True to cancel the rest of the interaction.
     */
@Override
public boolean onLeftClickEntity(ItemStack itemStack, EntityPlayer player, Entity entity) {
    if (!player.worldObj.isRemote) {
        //FlagRegistry.getModFlag().getFlagWorld(player.worldObj).containsValue("ban_Tracker", "true", new Pos(entity));
        boolean flag_ban = false;
        if (!flag_ban) {
            //if (this.getEnergy(itemStack) > ENERGY_PER_TICK)
            //{
            setTrackingEntity(itemStack, entity);
            player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.tracker.nowtrack") + " " + entity.getCommandSenderName()));
            return true;
        //}
        //else
        //{
        //    player.addChatMessage(LanguageUtility.getLocal("message.tracker.nopower"));
        //}
        } else {
            player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.tracker.banned")));
        }
    }
    return false;
}
Also used : ChatComponentText(net.minecraft.util.ChatComponentText)

Example 49 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ICBM-Classic by BuiltBrokenModding.

the class ItemDefuser method onLeftClickEntity.

/**
     * Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
     * return value is true further processing is canceled and the entity is not attacked.
     *
     * @param itemStack The Item being used
     * @param player    The player that is attacking
     * @param entity    The entity being attacked
     * @return True to cancel the rest of the interaction.
     */
@Override
public boolean onLeftClickEntity(ItemStack itemStack, EntityPlayer player, Entity entity) {
    if (this.getEnergy(itemStack) >= ENERGY_COST) {
        if (entity instanceof EntityExplosive) {
            if (!entity.worldObj.isRemote) {
                EntityExplosive entityTNT = (EntityExplosive) entity;
                EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(ICBMClassic.blockExplosive, 1, entityTNT.explosiveID.ordinal()));
                float var13 = 0.05F;
                Random random = new Random();
                entityItem.motionX = ((float) random.nextGaussian() * var13);
                entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
                entityItem.motionZ = ((float) random.nextGaussian() * var13);
                entity.worldObj.spawnEntityInWorld(entityItem);
            }
            entity.setDead();
        } else if (entity instanceof EntityTNTPrimed) {
            if (!entity.worldObj.isRemote) {
                EntityItem entityItem = new EntityItem(entity.worldObj, entity.posX, entity.posY, entity.posZ, new ItemStack(Blocks.tnt));
                float var13 = 0.05F;
                Random random = new Random();
                entityItem.motionX = ((float) random.nextGaussian() * var13);
                entityItem.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
                entityItem.motionZ = ((float) random.nextGaussian() * var13);
                entity.worldObj.spawnEntityInWorld(entityItem);
            }
            entity.setDead();
        } else if (entity instanceof EntityBombCart) {
            ((EntityBombCart) entity).killMinecart(DamageSource.generic);
        }
        this.discharge(itemStack, ENERGY_COST, true);
        return true;
    } else {
        player.addChatMessage(new ChatComponentText(LanguageUtility.getLocal("message.defuser.nopower")));
    }
    return false;
}
Also used : EntityBombCart(icbm.classic.content.entity.EntityBombCart) Random(java.util.Random) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityExplosive(icbm.classic.content.entity.EntityExplosive) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText) EntityItem(net.minecraft.entity.item.EntityItem)

Example 50 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherScreen method receiveRadioWave.

@Override
public void receiveRadioWave(float hz, IRadioWaveSender sender, String messageHeader, Object[] data) {
    //Floor frequency as we do not care about sub ranges
    int frequency = (int) Math.floor(hz);
    //Only tier 3 (2 for tier value) can be remotely fired
    if (getTier() == 2 && frequency == getFrequency() && laucherBase != null) {
        //Laser detonator signal
        if (messageHeader.equals("activateLauncherWithTarget")) {
            Pos pos = (Pos) data[0];
            if (toPos().distance(pos) < this.laucherBase.getRange()) {
                setTarget(pos);
                launch();
                ((FakeRadioSender) sender).player.addChatComponentMessage(new ChatComponentText("Firing missile at " + pos));
            }
        } else //Remote detonator signal
        if (messageHeader.equals("activateLauncher")) {
            ((FakeRadioSender) sender).player.addChatComponentMessage(new ChatComponentText("Firing missile at " + getTarget()));
            launch();
        }
    }
}
Also used : Pos(com.builtbroken.mc.imp.transform.vector.Pos) FakeRadioSender(com.builtbroken.mc.prefab.hz.FakeRadioSender) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

ChatComponentText (net.minecraft.util.ChatComponentText)108 EntityPlayer (net.minecraft.entity.player.EntityPlayer)19 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)9 Entity (net.minecraft.entity.Entity)8 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)7 ArrayList (java.util.ArrayList)7 Block (net.minecraft.block.Block)6 AMVector3 (am2.api.math.AMVector3)4 AccessGroup (com.builtbroken.mc.framework.access.AccessGroup)4 Pos (com.builtbroken.mc.imp.transform.vector.Pos)4 OpenChatGui (logisticspipes.network.packets.gui.OpenChatGui)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ChatStyle (net.minecraft.util.ChatStyle)4 IPowerNode (am2.api.power.IPowerNode)3 IItemActivationListener (com.builtbroken.mc.api.items.listeners.IItemActivationListener)3 IItemEventListener (com.builtbroken.mc.api.items.listeners.IItemEventListener)3 AbstractCommand (com.builtbroken.mc.core.commands.prefab.AbstractCommand)3 ItemListenerIterator (com.builtbroken.mc.prefab.items.listeners.ItemListenerIterator)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3