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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#addChatMessage() . 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: BlockCoordTransporter.java    From ModdingTutorials with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
	ItemStack stack = playerIn.getCurrentEquippedItem();
	if(stack != null)
	{
		if(stack.getItem() instanceof ItemCoordinateCache)
		{
			if(stack.getItem().hasEffect(stack))
			{
				TileEntityCoordTransporter tect = (TileEntityCoordTransporter) worldIn.getTileEntity(pos);
				stack.stackSize--;
				playerIn.addChatMessage(new ChatComponentText("Added cordinate cache to tile entity"));
			}
		}
	}
	return true;
}
 
Example 2
Source File: EventHandlerEntity.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void on(LivingEvent.LivingUpdateEvent event) {
    if (event.entityLiving == null || !(event.entityLiving instanceof EntityPlayer)) return;
    EntityPlayer player = (EntityPlayer) event.entity;
    if ((event.entity.worldObj.provider.dimensionId == ModConfig.dimOuterId) && ((player.ticksExisted & 7) == 0) && ((player.capabilities.isFlying) || (Hover.getHover(player.getEntityId())))) {
        if(player.capabilities.isCreativeMode && MiscUtils.isANotApprovedOrMisunderstoodPersonFromMoreDoor(player)) return;
        player.capabilities.isFlying = false;
        Hover.setHover(player.getEntityId(), false);
        if (!((EntityPlayer) event.entityLiving).worldObj.isRemote) {
            String msg = StatCollector.translateToLocal("tc.break.fly");
            if (player.capabilities.isCreativeMode) {
                msg += " " + StatCollector.translateToLocal("gadomancy.eldritch.noflyCreative");
            }
            player.addChatMessage(new ChatComponentText(EnumChatFormatting.ITALIC + "" + EnumChatFormatting.GRAY + msg));
        }
    }
}
 
Example 3
Source File: BlockCoordTransporter.java    From ModdingTutorials with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
	ItemStack stack = playerIn.getCurrentEquippedItem();
	if(stack != null)
	{
		if(stack.getItem() instanceof ItemCoordinateCache)
		{
			if(stack.getItem().hasEffect(stack))
			{
				TileEntityCoordTransporter tect = (TileEntityCoordTransporter) worldIn.getTileEntity(pos);
				stack.stackSize--;
				playerIn.addChatMessage(new ChatComponentText("Added cordinate cache to tile entity"));
			}
		}
	}
	return true;
}
 
Example 4
Source File: TileEntityHelm.java    From archimedes-ships with MIT License 5 votes vote down vote up
public boolean mountShip(EntityPlayer player)
{
	if (!worldObj.isRemote)
	{
		if (assembleResult != null && assembleResult.isOK())
		{
			assembleResult.checkConsistent(worldObj);
			sendAssembleResult(player, false);
			if (assembleResult.getCode() == AssembleResult.RESULT_INCONSISTENT)
			{
				return false;
			}
			if (assembleResult.getCode() == AssembleResult.RESULT_OK_WITH_WARNINGS)
			{
				IChatComponent c = new ChatComponentText("Ship contains changes");
				player.addChatMessage(c);
			}
			
			EntityShip entity = assembleResult.getEntity(worldObj);
			if (entity != null)
			{
				entity.setInfo(info);
				if (worldObj.spawnEntityInWorld(entity))
				{
					player.mountEntity(entity);
					assembleResult = null;
					//entity.getCapabilities().mountEntity(entityplayer);
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 5
Source File: ItemStoragePhysical.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack i, World w, EntityPlayer p)
{
	if (p.isSneaking())
	{
		if (i.getItemDamage() == 0 || i.getItemDamage() == 1 || i.getItemDamage() == 2 || i.getItemDamage() == 3)
		{
			if (Util.getCellRegistry().getHandlerForCell(i).storedItemCount() == 0)
			{
				if (p.inventory.addItemStackToInventory(new ItemStack(ItemEnum.STORAGECASING.getItemInstance(), 1, 0)))
					return new ItemStack(ItemEnum.STORAGECOMPONENT.getItemInstance(), 1, i.getItemDamage());
			}
		} else if (i.getItemDamage() == 4)
		{
			if (FMLCommonHandler.instance().getEffectiveSide().isServer())
			{
				switch (i.getTagCompound().getInteger("mode"))
				{
				case 0:
					i.getTagCompound().setInteger("mode", 1);
					p.addChatMessage(StatCollector.translateToLocal("tooltip.mode") + ": " + StatCollector.translateToLocal("tooltip.equaltrade1"));
					break;
				case 1:
					i.getTagCompound().setInteger("mode", 2);
					p.addChatMessage(StatCollector.translateToLocal("tooltip.mode") + ": " + StatCollector.translateToLocal("tooltip.equaltrade3"));
					break;
				case 2:
					i.getTagCompound().setInteger("mode", 0);
					p.addChatMessage(StatCollector.translateToLocal("tooltip.mode") + ": " + StatCollector.translateToLocal("tooltip.placement"));
					break;
				}
			}
		}
	}
	return i;

}
 
Example 6
Source File: ItemSubCollar.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
@Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
{
    if (entity.worldObj.isRemote)
    {
        return false;
    }
    if (entity instanceof EntityPlayer)
    {
        EntityPlayer sub = (EntityPlayer)entity;
        IInventory baubles = BaublesApi.getBaubles(sub);
        if(baubles.getStackInSlot(0) == null) {
            if(!itemstack.hasTagCompound()){
                NBTTagCompound tag = new NBTTagCompound();
                itemstack.setTagCompound(tag);
            }
            itemstack.stackTagCompound.setString("owner", player.getDisplayName());
            baubles.setInventorySlotContents(0, itemstack.copy());
            itemstack.stackSize = 0;
            sub.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.placescollar").replace("%s", player.getDisplayName())));
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.youplacecollar").replace("%s", sub.getDisplayName())));
            return true;
        }
        else
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.alreadywearing").replace("%s", sub.getDisplayName())));
    }
    return false;
}
 
Example 7
Source File: ItemFruitTainted.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 5 votes vote down vote up
public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) {
    if(!world.isRemote && player instanceof EntityPlayerMP) {
        Thaumcraft.addStickyWarpToPlayer(player, 1);
        player.addPotionEffect(getEffect(PotionFluxTaint.instance.id, 600, false));
        player.addPotionEffect(getEffect(Potion.hunger.id, 600, false));
        if(world.rand.nextFloat() < 0.4F){
            player.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + StatCollector.translateToLocal("warp.text.15")));
            player.addPotionEffect(getEffect(PotionThaumarhia.instance.id, 600, true));
        }
    }
    return super.onEaten(stack, world, player);
}
 
Example 8
Source File: BW_SimpleWindMeter.java    From bartworks with MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
    if (entityPlayer.worldObj.isRemote || world == null || WorldData.get(world) == null || WorldData.get(world).windSim == null)
        return itemStack;

    float windStrength = (float) WorldData.get(world).windSim.getWindAt(entityPlayer.posY);
    String windS = windStrength < 1f ? StatCollector.translateToLocal("tooltip.windmeter.2.name") : windStrength < 10f ? StatCollector.translateToLocal("tooltip.windmeter.3.name") : windStrength < 20f ? StatCollector.translateToLocal("tooltip.windmeter.4.name") : windStrength < 30f ? StatCollector.translateToLocal("tooltip.windmeter.5.name") : windStrength < 50f ? StatCollector.translateToLocal("tooltip.windmeter.6.name") : StatCollector.translateToLocal("tooltip.windmeter.7.name");
    entityPlayer.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("tooltip.windmeter.8.name") + " " + windS + "."));
    itemStack.damageItem(1, entityPlayer);
    return itemStack;
}
 
Example 9
Source File: ContainerAmadron.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean canInteractWith(EntityPlayer player){
    if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Itemss.amadronTablet) {
        IPressurizable pressurizable = (IPressurizable)Itemss.amadronTablet;
        pressurizable.addAir(player.getCurrentEquippedItem(), -1);
        if(pressurizable.getPressure(player.getCurrentEquippedItem()) > 0) return true;
        else {
            player.addChatMessage(new ChatComponentTranslation("gui.tab.problems.notEnoughPressure"));
        }
    }
    return false;
}
 
Example 10
Source File: PackBase.java    From SimplyJetpacks with MIT License 5 votes vote down vote up
protected void toggleState(boolean on, ItemStack stack, String type, String tag, EntityPlayer player, boolean showInChat) {
    stack.stackTagCompound.setBoolean(tag, !on);
    
    if (player != null && showInChat) {
        String color = on ? StringHelper.LIGHT_RED : StringHelper.BRIGHT_GREEN;
        type = type != null && !type.equals("") ? "chat." + this.name + "." + type + ".on" : "chat." + this.name + ".on";
        String msg = SJStringHelper.localize(type) + " " + color + SJStringHelper.localize("chat." + (on ? "disabled" : "enabled"));
        player.addChatMessage(new ChatComponentText(msg));
    }
}
 
Example 11
Source File: BlockMultiblockGlass.java    From BigReactors with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
	if(player.isSneaking()) {
		return false;
	}

	// If the player's hands are empty and they rightclick on a multiblock, they get a 
	// multiblock-debugging message if the machine is not assembled.
	if(!world.isRemote && player.getCurrentEquippedItem() == null) {
		TileEntity te = world.getTileEntity(x, y, z);
		if(te instanceof IMultiblockPart) {
			MultiblockControllerBase controller = ((IMultiblockPart)te).getMultiblockController();

			if(controller == null) {
				player.addChatMessage(new ChatComponentText(String.format("SERIOUS ERROR - server part @ %d, %d, %d has no controller!", x, y, z))); //TODO Localize
			}
			else {
				Exception e = controller.getLastValidationException();
				if(e != null) {
					player.addChatMessage(new ChatComponentText(e.getMessage()));
					return true;
				}
			}
		}
	}
	
	return false;
}
 
Example 12
Source File: TileMotor.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean debug(World world, int x, int y, int z, ForgeDirection face, EntityPlayer player) {

    if (!world.isRemote)
        return true;

    player.addChatMessage(new ChatComponentText("Power: " + getEnergyBuffer() + "/" + getEnergyBufferSize()));
    player.addChatMessage(new ChatComponentText("Face: " + getFace().name().toLowerCase()));
    getMovement().debug(world, x, y, z, face, player);

    return true;
}
 
Example 13
Source File: BlockMEDropper.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() instanceof IAEWrench)
	{
		return false;
	}
	if (!world.isRemote)
	{
		if (!player.isSneaking())
		{
			if (!((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getLocked())
			{
				if (player.inventory.getCurrentItem() != null)
				{
					((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).setItem(player.inventory.getCurrentItem().copy());
					player.addChatMessage(StatCollector.translateToLocal("tooltip.dropset") + " " + player.inventory.getCurrentItem().getDisplayName());
				}
			} else
			{
				ItemStack item = ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getItem();
				player.addChatMessage(StatCollector.translateToLocal("tooltip.item") + ": " + item != null ? item.getDisplayName() : StatCollector.translateToLocal("tooltip.empty1"));
			}
		} else
		{
			((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).setLocked(!((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getLocked());
			if (((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getLocked())
			{
				player.addChatMessage(StatCollector.translateToLocal("tooltip.dropperlocked") + "!");
			} else
			{
				player.addChatMessage(StatCollector.translateToLocal("tooltip.dropperunlocked") + "!");
			}
		}
	}
	return true;
}
 
Example 14
Source File: config.java    From wailanbt with MIT License 4 votes vote down vote up
public static void loadConfig(EntityPlayer player) {
        configJson = new JsonObject();
        NBTHandler.manager = new ScriptEngineManager(null);
        NBTHandler.engine = NBTHandler.manager.getEngineByName("javascript");
        NBTHandler.scriptSet = new HashSet<String>();
//        try {
//            NBTHandler.engine.eval("var names={}");
//        } catch (ScriptException e) {
//            e.printStackTrace();
//        }
//        for (Object item : Item.itemRegistry) {
//            String ID = String.valueOf(Item.itemRegistry.getIDForObject(item));
//            String name = StatCollector.translateToLocal(((Item)item).getUnlocalizedName()+".name").trim();
//            try {
//                NBTHandler.engine.eval("names['"+ID+"']='"+name+"'");
//            } catch (ScriptException e) {
//                e.printStackTrace();
//            }
//        }
        File[] configFiles = configDir.listFiles(new FilenameFilter(){
            public boolean accept(File dir, String name) {
                return name.endsWith(".json");
            }
        });
        if (!(configFiles == null)) {
            for (File configFile : configFiles) {
                if (configFile.isFile()) {
                    try {
                        InputStream inputStream = new FileInputStream(configFile);
                        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                        JsonParser parser = new JsonParser();
                        JsonElement jsonElementCurrent = parser.parse(inputStreamReader);
                        if (jsonElementCurrent.isJsonObject()) {
                            JsonObject jsonObjectCurrent = jsonElementCurrent.getAsJsonObject();
                            mergeJson(jsonObjectCurrent);
                        } else {
                            LogHelper.error("Parse " + configFile.getName() + " failed");
                            player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("wailanbt.info.JsonContentError"),configFile.getName())));
                        }
                    } catch (Exception e) {
                        //e.printStackTrace();
                        LogHelper.error("Error parsing file '" + configFile.getName() + "'. Possible error: " + e.getCause().getMessage());
                        player.addChatComponentMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("wailanbt.info.ParsingError"),configFile.getName())));
                    }
                }
            }
        }
        LogHelper.info("Config Loaded");
        System.out.println(configJson);
        player.addChatMessage(new ChatComponentTranslation("wailanbt.info.ConfigLoaded"));
    }
 
Example 15
Source File: PacketAmadronTradeRemoved.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleClientSide(PacketAmadronTradeRemoved message, EntityPlayer player){
    if(AmadronOfferSettings.notifyOfTradeRemoval) player.addChatMessage(new ChatComponentText(I18n.format("message.amadron.playerRemovedTrade", message.getOffer().getVendor(), WidgetAmadronOffer.getStringForObject(message.getOffer().getInput()), WidgetAmadronOffer.getStringForObject(message.getOffer().getOutput()))));
}
 
Example 16
Source File: PacketAmadronTradeNotifyDeal.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleClientSide(PacketAmadronTradeNotifyDeal message, EntityPlayer player){
    if(AmadronOfferSettings.notifyOfDealMade) player.addChatMessage(new ChatComponentText(I18n.format("message.amadron.playerBought", message.buyingPlayer, WidgetAmadronOffer.getStringForObject(message.getOffer().getOutput(), message.offerAmount), WidgetAmadronOffer.getStringForObject(message.getOffer().getInput(), message.offerAmount))));
}
 
Example 17
Source File: PacketAmadronTradeAdd.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleClientSide(PacketAmadronTradeAdd message, EntityPlayer player){
    if(AmadronOfferSettings.notifyOfTradeAddition) player.addChatMessage(new ChatComponentText(I18n.format("message.amadron.playerAddedTrade", message.getOffer().getVendor(), WidgetAmadronOffer.getStringForObject(message.getOffer().getOutput()), WidgetAmadronOffer.getStringForObject(message.getOffer().getInput()))));
}
 
Example 18
Source File: ItemSecureStoragePhysicalEncrypted.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@ForgeSubscribe
@Override
public ItemStack onItemRightClick(ItemStack stack, World w, EntityPlayer p)
{
	ItemStack itemStackEncrypted = p.inventory.getCurrentItem();
	ItemStack itemStackDecrypted = new ItemStack(ItemEnum.STORAGEPHYSICALDECRYPTED.getItemInstance(), 1);

	if (!itemStackEncrypted.hasTagCompound())
	{
		itemStackEncrypted.setTagCompound(new NBTTagCompound());
	}

	// copy over content
	NBTTagCompound tagEncrypted = itemStackEncrypted.getTagCompound();

	// remove owner
	String user = tagEncrypted.getString("owner");

	if (p.isSneaking())
	{
		if (p.username.equals(user))
		{
			tagEncrypted.removeTag("owner");
			itemStackDecrypted.setTagCompound((tagEncrypted));

			p.inventory.setInventorySlotContents(p.inventory.currentItem, itemStackDecrypted);

			if (!w.isRemote)
			{
				p.addChatMessage(StatCollector.translateToLocal("tooltip.accessgranted"));
			}
		} else
		{
			if (!w.isRemote)
			{
				p.addChatMessage(StatCollector.translateToLocal("tooltip.notyours"));
			}
		}
	}
	return stack;
}
 
Example 19
Source File: PacketCommandGetGlobalVariableOutput.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void handleClientSide(PacketCommandGetGlobalVariableOutput message, EntityPlayer player){
    player.addChatMessage(new ChatComponentText(I18n.format("command.getGlobalVariable.output", message.varName, message.pos.chunkPosX, message.pos.chunkPosY, message.pos.chunkPosZ, message.stack != null ? message.stack.getDisplayName() : "-")));
}
 
Example 20
Source File: MovementSlide.java    From Framez with GNU General Public License v3.0 3 votes vote down vote up
@Override
public boolean debug(World world, int x, int y, int z, ForgeDirection face, EntityPlayer player) {

    player.addChatMessage(new ChatComponentText("Movement direction: " + direction.name().toLowerCase()));

    return true;
}