Search in sources :

Example 81 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.

the class ItemCrystalWrench method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (!stack.hasTagCompound())
        stack.setTagCompound(new NBTTagCompound());
    int cMode = getMode(stack);
    if (te != null && !(te instanceof IPowerNode || te instanceof TileEntityParticleEmitter) && cMode == MODE_DISCONNECT) {
        player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.wrongWrenchMode")));
        return false;
    }
    if (te != null && te instanceof IPowerNode) {
        if (cMode == MODE_DISCONNECT) {
            doDisconnect((IPowerNode) te, world, x + hitX, y + hitY, z + hitZ, player);
            return false;
        }
        if (stack.stackTagCompound.hasKey(KEY_PAIRLOC)) {
            doPairNodes(world, x, y, z, stack, player, hitX, hitY, hitZ, te);
        } else {
            storePairLocation(world, te, stack, player, x + hitX, y + hitY, z + hitZ);
        }
    } else if (te != null && te instanceof TileEntityCrystalMarker && stack.stackTagCompound != null && stack.stackTagCompound.hasKey(HAB_PAIRLOC)) {
        handleCMPair(stack, world, player, te, x + hitX, y + hitY, z + hitZ);
    } else if (player.isSneaking()) {
        handleModeChanges(stack);
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityParticleEmitter(am2.blocks.tileentities.TileEntityParticleEmitter) ChatComponentText(net.minecraft.util.ChatComponentText) IPowerNode(am2.api.power.IPowerNode)

Example 82 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.

the class ItemCrystalWrench method doPairNodes.

private void doPairNodes(World world, int x, int y, int z, ItemStack stack, EntityPlayer player, double hitX, double hitY, double hitZ, TileEntity te) {
    AMVector3 source = AMVector3.readFromNBT(stack.stackTagCompound.getCompoundTag(KEY_PAIRLOC));
    TileEntity sourceTE = world.getTileEntity((int) source.x, (int) source.y, (int) source.z);
    if (sourceTE != null && sourceTE instanceof IPowerNode && !world.isRemote) {
        player.addChatMessage(new ChatComponentText(PowerNodeRegistry.For(world).tryPairNodes((IPowerNode) sourceTE, (IPowerNode) te)));
    } else if (world.isRemote) {
        spawnLinkParticles(world, x + hitX, y + hitY, z + hitZ);
    }
    if (!stack.stackTagCompound.hasKey(KEEP_BINDING))
        stack.stackTagCompound.removeTag(KEY_PAIRLOC);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChatComponentText(net.minecraft.util.ChatComponentText) IPowerNode(am2.api.power.IPowerNode)

Example 83 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.

the class ItemCandle method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    if (!stack.hasTagCompound() || !stack.stackTagCompound.hasKey("search_block")) {
        Block block = world.getBlock(x, y, z);
        if (player.isSneaking() && block != null && block.getBlockHardness(world, x, y, z) > 0f && world.getTileEntity(x, y, z) == null) {
            if (!world.isRemote) {
                setSearchBlock(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z), stack);
                world.setBlockToAir(x, y, z);
            } else {
                AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(world, "radiant", x + 0.5, y + 0.5, z + 0.5);
                if (particle != null) {
                    particle.AddParticleController(new ParticleHoldPosition(particle, 20, 1, false));
                    particle.setRGBColorF(0, 0.5f, 1);
                }
            }
            return true;
        }
    }
    if (!world.isRemote) {
        if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("search_block")) {
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.candlecantplace")));
            return false;
        }
        switch(side) {
            case 0:
                y--;
                break;
            case 1:
                y++;
                break;
            case 2:
                z--;
                break;
            case 3:
                z++;
                break;
            case 4:
                x--;
                break;
            case 5:
                x++;
                break;
        }
        Block block = world.getBlock(x, y, z);
        if (block == null || block.isReplaceable(world, x, y, z)) {
            int newMeta = (int) Math.ceil(stack.getItemDamage() / 1200);
            world.setBlock(x, y, z, BlocksCommonProxy.candle, newMeta, 2);
            if (!player.capabilities.isCreativeMode)
                player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
        }
        return true;
    }
    return false;
}
Also used : AMParticle(am2.particles.AMParticle) ParticleHoldPosition(am2.particles.ParticleHoldPosition) Block(net.minecraft.block.Block) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 84 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.

the class AMEventHandler method onPlayerPickupItem.

@SubscribeEvent
public void onPlayerPickupItem(EntityItemPickupEvent event) {
    if (event.entityPlayer == null)
        return;
    if (!event.entityPlayer.worldObj.isRemote && ExtendedProperties.For(event.entityPlayer).getMagicLevel() <= 0 && event.item.getEntityItem().getItem() == ItemsCommonProxy.arcaneCompendium) {
        event.entityPlayer.addChatMessage(new ChatComponentText("You have unlocked the secrets of the arcane!"));
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "shapes", true);
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "components", true);
        AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "modifiers", true);
        ExtendedProperties.For(event.entityPlayer).setMagicLevelWithMana(1);
        ExtendedProperties.For(event.entityPlayer).forceSync();
        return;
    }
    if (event.item.getEntityItem().getItem() == ItemsCommonProxy.spell) {
        if (event.entityPlayer.worldObj.isRemote) {
            AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, "spell_book", false);
        }
    } else {
        Item item = event.item.getEntityItem().getItem();
        int meta = event.item.getEntityItem().getItemDamage();
        if (event.entityPlayer.worldObj.isRemote && item.getUnlocalizedName() != null && (AMCore.proxy.items.getArsMagicaItems().contains(item)) || (item instanceof ItemBlock && AMCore.proxy.blocks.getArsMagicaBlocks().contains(((ItemBlock) item).field_150939_a))) {
            AMNetHandler.INSTANCE.sendCompendiumUnlockPacket((EntityPlayerMP) event.entityPlayer, item.getUnlocalizedName().replace("item.", "").replace("arsmagica2:", "").replace("tile.", "") + ((meta > -1) ? "@" + meta : ""), false);
        }
    }
}
Also used : Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) ItemBlock(net.minecraft.item.ItemBlock) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 85 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project ArsMagica2 by Mithion.

the class Appropriation method restore.

private void restore(EntityPlayer player, World world, ItemStack stack, int x, int y, int z, double hitX, double hitY, double hitZ) {
    if (stack.stackTagCompound.hasKey(storageKey)) {
        NBTTagCompound storageCompound = stack.stackTagCompound.getCompoundTag(storageKey);
        if (storageCompound != null) {
            String type = storageCompound.getString(storageType);
            if (type.equals("ent")) {
                String clazz = storageCompound.getString("class");
                NBTTagCompound entData = storageCompound.getCompoundTag("targetNBT");
                try {
                    Entity ent = (Entity) Class.forName(clazz).getConstructor(World.class).newInstance(world);
                    ent.readFromNBT(entData);
                    ent.setPosition(hitX, hitY, hitZ);
                    world.spawnEntityInWorld(ent);
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            } else if (type.equals("block")) {
                //String blockName = storageCompound.getString("blockName");
                int blockID = storageCompound.getInteger("blockID");
                int meta = storageCompound.getInteger("meta");
                //Block block = Block.getBlockFromName(blockName);
                Block block = Block.getBlockById(blockID);
                if (block != null) {
                    world.setBlock(x, y, z, block, meta, 2);
                } else {
                    if (!player.worldObj.isRemote)
                        player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.approError")));
                    stack.stackTagCompound.removeTag(storageKey);
                    return;
                }
                if (storageCompound.hasKey("tileEntity")) {
                    TileEntity te = world.getTileEntity(x, y, z);
                    if (te != null) {
                        te.readFromNBT(storageCompound.getCompoundTag("tileEntity"));
                        te.xCoord = x;
                        te.yCoord = y;
                        te.zCoord = z;
                        te.setWorldObj(world);
                    }
                }
            }
        }
        stack.stackTagCompound.removeTag(storageKey);
        setOriginalSpellStackData(player, stack);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) 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