Search in sources :

Example 76 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class RailUtility method placeOnRail.

/**
     * <h2>rail placement from item</h2>
     * basic functionality to place a train or rollingstock on the rails on item use.
     */
public static boolean placeOnRail(GenericRailTransport entity, EntityPlayer playerEntity, World worldObj, int posX, int posY, int posZ) {
    //be sure there is a rail at the location
    if (RailUtility.isRailBlockAt(worldObj, posX, posY, posZ) && !worldObj.isRemote) {
        //define the direction
        int playerMeta = MathHelper.floor_double((playerEntity.rotationYaw / 90.0F) + 2.5D) & 3;
        //check rail axis
        if (((BlockRailBase) worldObj.getBlock(posX, posY, posZ)).getBasicRailMetadata(worldObj, null, posX, posY, posZ) == 1) {
            //check player direction
            if (playerMeta == 3) {
                //check if the transport can be placed in the area
                if (!RailUtility.isRailBlockAt(worldObj, posX + MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D), posY, posZ) && !RailUtility.isRailBlockAt(worldObj, posX + MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D), posY, posZ)) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 0;
                //spawn the entity
                worldObj.spawnEntityInWorld(entity);
                return true;
            } else //same as above, but reverse direction.
            if (playerMeta == 1) {
                if (!RailUtility.isRailBlockAt(worldObj, posX - MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D), posY, posZ) && !RailUtility.isRailBlockAt(worldObj, posX - MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D), posY, posZ)) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 180;
                worldObj.spawnEntityInWorld(entity);
                return true;
            }
        } else //same as above but a different axis.
        if (((BlockRailBase) worldObj.getBlock(posX, posY, posZ)).getBasicRailMetadata(worldObj, null, posX, posY, posZ) == 0) {
            if (playerMeta == 0) {
                if (!RailUtility.isRailBlockAt(worldObj, posX, posY, posZ + MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D)) && !RailUtility.isRailBlockAt(worldObj, posX, posY, posZ + MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D))) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 90;
                worldObj.spawnEntityInWorld(entity);
                return true;
            } else if (playerMeta == 2) {
                if (!RailUtility.isRailBlockAt(worldObj, posX, posY, posZ - MathHelper.floor_double(entity.getRenderBogieOffsets().get(entity.getRenderBogieOffsets().size() - 1) + 1.0D)) && !RailUtility.isRailBlockAt(worldObj, posX, posY, posZ - MathHelper.floor_double(entity.getRenderBogieOffsets().get(0) - 1.0D))) {
                    playerEntity.addChatMessage(new ChatComponentText("Place on a straight piece of track that is of sufficient length"));
                    return false;
                }
                entity.rotationYaw = 270;
                worldObj.spawnEntityInWorld(entity);
                return true;
            }
        }
    }
    return false;
}
Also used : ChatComponentText(net.minecraft.util.ChatComponentText) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 77 with ChatComponentText

use of net.minecraft.util.ChatComponentText in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class EventManager method entityJoinWorldEvent.

/**
     * <h2>join world</h2>
     * This event is called when a player joins the world, we use this to display the alpha notice, and check for new mod versions, this is only displayed on the client side, but can be used for server..
     */
@SubscribeEvent
@SuppressWarnings("unused")
public void entityJoinWorldEvent(EntityJoinWorldEvent event) {
    if (event.entity instanceof EntityPlayer && event.entity.worldObj.isRemote) {
        //add alpha notice
        ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText("You are currently playing an alpha release of Trains In Motion."));
        ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText("For official releases, check out https://github.com/EternalBlueFlame/Trains-In-Motion/"));
        ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText("Keep in mind that everything in this mod is subject to change, and report any bugs you find."));
        ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText("Good luck and thanks for the assistance. - Eternal Blue Flame."));
        //use an HTTP request and parse to check for new versions of the mod from github.
        try {
            //make an HTTP connection to the version text file, and set the type as get.
            HttpURLConnection conn = (HttpURLConnection) new URL("https://raw.githubusercontent.com/USER/PROJECT/BRANCH/version.txt").openConnection();
            conn.setRequestMethod("GET");
            //use the HTTP connection as an input stream to actually get the file, then put it into a buffered reader.
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            //read the first line of the text document, if it's not the same as the current running version, notify there is an update, then display the second line, which is intended for a download URL.
            if (!TrainsInMotion.MOD_VERSION.equals(rd.readLine())) {
                ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText("A new version of Trains In Motion is available, check it out at:"));
                ((EntityPlayer) event.entity).addChatMessage(new ChatComponentText(rd.readLine()));
            }
        } catch (Exception e) {
        //couldn't check for new version, most likely because there's no internet, so just do nothing.
        }
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ChatComponentText(net.minecraft.util.ChatComponentText) URL(java.net.URL) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 78 with ChatComponentText

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

the class AMPacketProcessorClient method handleNBTDump.

private void handleNBTDump(EntityPlayer player) {
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack == null || !stack.hasTagCompound())
        return;
    NBTTagCompound compound = stack.writeToNBT(new NBTTagCompound());
    String fileName = "NBTDump_" + System.currentTimeMillis() + ".dat";
    File file = new File(fileName);
    try {
        CompressedStreamTools.write(compound, file);
    } catch (IOException e) {
        e.printStackTrace();
        player.addChatMessage(new ChatComponentText("An error occurred while attempting to write the NBT, check the console for more information."));
        return;
    }
    player.addChatMessage(new ChatComponentText("NBT Saved to " + file.getAbsolutePath()));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) File(java.io.File) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 79 with ChatComponentText

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

the class Recall method handleRitualReagents.

private boolean handleRitualReagents(ItemStack[] ritualRunes, World world, int x, int y, int z, EntityLivingBase caster, Entity target) {
    boolean hasVinteumDust = false;
    for (ItemStack stack : ritualRunes) {
        if (stack.getItem() == ItemsCommonProxy.itemOre && stack.getItemDamage() == ItemsCommonProxy.itemOre.META_VINTEUMDUST) {
            hasVinteumDust = true;
            break;
        }
    }
    if (!hasVinteumDust && ritualRunes.length == 3) {
        long key = KeystoneUtilities.instance.getKeyFromRunes(ritualRunes);
        AMVector3 vector = AMCore.proxy.blocks.getNextKeystonePortalLocation(world, x, y, z, false, key);
        if (vector == null || vector.equals(new AMVector3(x, y, z))) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.noMatchingGate")));
            return false;
        } else {
            RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
            RitualShapeHelper.instance.consumeRitualShape(this, world, x, y, z);
            ((EntityLivingBase) target).setPositionAndUpdate(vector.x, vector.y - target.height, vector.z);
            return true;
        }
    } else if (hasVinteumDust) {
        ArrayList<ItemStack> copy = new ArrayList<ItemStack>();
        for (ItemStack stack : ritualRunes) {
            if (stack.getItem() == ItemsCommonProxy.rune && stack.getItemDamage() <= 16) {
                copy.add(stack);
            }
        }
        ItemStack[] newRunes = copy.toArray(new ItemStack[copy.size()]);
        long key = KeystoneUtilities.instance.getKeyFromRunes(newRunes);
        EntityPlayer player = EntityUtilities.getPlayerForCombo(world, (int) key);
        if (player == null) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.noMatchingPlayer"));
            return false;
        } else if (player == caster) {
            if (caster instanceof EntityPlayer && !world.isRemote)
                ((EntityPlayer) caster).addChatMessage(new ChatComponentText("am2.tooltip.cantSummonSelf"));
            return false;
        } else {
            RitualShapeHelper.instance.consumeRitualReagents(this, world, x, y, z);
            if (target.worldObj.provider.dimensionId != caster.worldObj.provider.dimensionId) {
                DimensionUtilities.doDimensionTransfer(player, caster.worldObj.provider.dimensionId);
            }
            ((EntityLivingBase) target).setPositionAndUpdate(x, y, z);
            return true;
        }
    }
    return false;
}
Also used : AMVector3(am2.api.math.AMVector3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 80 with ChatComponentText

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

the class TileEntityCrystalMarker method linkToHabitat.

public void linkToHabitat(AMVector3 habLocation, EntityPlayer player) {
    TileEntity te = worldObj.getTileEntity((int) habLocation.x, (int) habLocation.y, (int) habLocation.z);
    if (te instanceof TileEntityFlickerHabitat) {
        AMVector3 myLocation = new AMVector3(this.xCoord, this.yCoord, this.zCoord);
        boolean setElementalAttuner = false;
        if (myLocation.distanceSqTo(habLocation) <= SEARCH_RADIUS) {
            if (BlockCrystalMarker.isInputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationIn(myLocation);
                setElementalAttuner = true;
            }
            if (BlockCrystalMarker.isOutputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationOut(myLocation);
                setElementalAttuner = true;
            }
            if (setElementalAttuner)
                this.setElementalAttuner(habLocation);
        } else {
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.habitatToFar")));
        }
    }
}
Also used : S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) 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